1 | import { createComponent } from "reakit-system/createComponent";
|
2 | import { createHook } from "reakit-system/createHook";
|
3 | import { useWarning } from "reakit-warning";
|
4 | import { useCreateElement } from "reakit-system/useCreateElement";
|
5 | import {
|
6 | PopoverOptions,
|
7 | PopoverHTMLProps,
|
8 | usePopover,
|
9 | } from "../Popover/Popover";
|
10 | import { COMBOBOX_POPOVER_KEYS } from "./__keys";
|
11 | import {
|
12 | unstable_ComboboxListOptions as ComboboxListOptions,
|
13 | unstable_ComboboxListHTMLProps as ComboboxListHTMLProps,
|
14 | unstable_useComboboxList as useComboboxList,
|
15 | } from "./ComboboxList";
|
16 | import { ComboboxPopoverStateReturn } from "./__utils/ComboboxPopoverState";
|
17 |
|
18 | export const unstable_useComboboxPopover = createHook<
|
19 | unstable_ComboboxPopoverOptions,
|
20 | unstable_ComboboxPopoverHTMLProps
|
21 | >({
|
22 | name: "ComboboxPopover",
|
23 | compose: [useComboboxList, usePopover],
|
24 | keys: COMBOBOX_POPOVER_KEYS,
|
25 |
|
26 | useOptions(options) {
|
27 | return {
|
28 | ...options,
|
29 | unstable_disclosureRef: options.unstable_referenceRef,
|
30 | unstable_autoFocusOnShow: false,
|
31 | unstable_autoFocusOnHide: false,
|
32 | };
|
33 | },
|
34 |
|
35 | useComposeProps(options, { tabIndex, ...htmlProps }) {
|
36 | htmlProps = useComboboxList(options, htmlProps, true);
|
37 | htmlProps = usePopover(options, htmlProps, true);
|
38 | return {
|
39 | ...htmlProps,
|
40 | tabIndex: tabIndex ?? undefined,
|
41 | };
|
42 | },
|
43 | });
|
44 |
|
45 | export const unstable_ComboboxPopover = createComponent({
|
46 | as: "div",
|
47 | useHook: unstable_useComboboxPopover,
|
48 | useCreateElement: (type, props, children) => {
|
49 | useWarning(
|
50 | !props["aria-label"] && !props["aria-labelledby"],
|
51 | "You should provide either `aria-label` or `aria-labelledby` props.",
|
52 | "See https://reakit.io/docs/combobox"
|
53 | );
|
54 | return useCreateElement(type, props, children);
|
55 | },
|
56 | });
|
57 |
|
58 | export type unstable_ComboboxPopoverOptions = ComboboxListOptions &
|
59 | Omit<
|
60 | PopoverOptions,
|
61 | | "unstable_disclosureRef"
|
62 | | "unstable_autoFocusOnHide"
|
63 | | "unstable_autoFocusOnShow"
|
64 | > &
|
65 | Pick<Partial<ComboboxPopoverStateReturn>, "unstable_referenceRef">;
|
66 |
|
67 | export type unstable_ComboboxPopoverHTMLProps = PopoverHTMLProps &
|
68 | ComboboxListHTMLProps;
|
69 |
|
70 | export type unstable_ComboboxPopoverProps = unstable_ComboboxPopoverOptions &
|
71 | unstable_ComboboxPopoverHTMLProps;
|