@basic-ui/core 0.0.50 → 0.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/build/cjs/index.js +106 -92
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Accordion/Accordion.d.ts +9 -9
- package/build/esm/Accordion/Accordion.js.map +1 -1
- package/build/esm/Accordion/AccordionBody.d.ts +6 -6
- package/build/esm/Accordion/AccordionBody.js.map +1 -1
- package/build/esm/Accordion/AccordionHeader.d.ts +7 -7
- package/build/esm/Accordion/AccordionHeader.js.map +1 -1
- package/build/esm/Accordion/AccordionItem.d.ts +9 -9
- package/build/esm/Accordion/AccordionItem.js.map +1 -1
- package/build/esm/Accordion/context.d.ts +19 -19
- package/build/esm/Accordion/context.js.map +1 -1
- package/build/esm/Accordion/index.d.ts +4 -4
- package/build/esm/Accordion/index.js.map +1 -1
- package/build/esm/Accordion/scopeQuery.d.ts +2 -2
- package/build/esm/Accordion/scopeQuery.js.map +1 -1
- package/build/esm/CheckBox/CheckBox.d.ts +7 -7
- package/build/esm/CheckBox/CheckBox.js.map +1 -1
- package/build/esm/CheckBox/index.d.ts +1 -1
- package/build/esm/CheckBox/index.js.map +1 -1
- package/build/esm/ComboBox/Combobox.d.ts +18 -18
- package/build/esm/ComboBox/Combobox.js.map +1 -1
- package/build/esm/ComboBox/ComboboxButton.d.ts +9 -9
- package/build/esm/ComboBox/ComboboxButton.js.map +1 -1
- package/build/esm/ComboBox/ComboboxInput.d.ts +17 -17
- package/build/esm/ComboBox/ComboboxInput.js.map +1 -1
- package/build/esm/ComboBox/ComboboxLabel.d.ts +7 -7
- package/build/esm/ComboBox/ComboboxLabel.js.map +1 -1
- package/build/esm/ComboBox/ComboboxList.d.ts +8 -8
- package/build/esm/ComboBox/ComboboxList.js.map +1 -1
- package/build/esm/ComboBox/ComboboxOption.d.ts +11 -11
- package/build/esm/ComboBox/ComboboxOption.js.map +1 -1
- package/build/esm/ComboBox/ComboboxPopover.d.ts +9 -9
- package/build/esm/ComboBox/ComboboxPopover.js.map +1 -1
- package/build/esm/ComboBox/cities.d.ts +5 -5
- package/build/esm/ComboBox/cities.js.map +1 -1
- package/build/esm/ComboBox/context.d.ts +30 -30
- package/build/esm/ComboBox/context.js.map +1 -1
- package/build/esm/ComboBox/hooks.d.ts +37 -37
- package/build/esm/ComboBox/hooks.js.map +1 -1
- package/build/esm/ComboBox/index.d.ts +8 -8
- package/build/esm/ComboBox/index.js.map +1 -1
- package/build/esm/ComboBox/makeHash.d.ts +1 -1
- package/build/esm/ComboBox/makeHash.js.map +1 -1
- package/build/esm/ComboBox/scopeQuery.d.ts +1 -1
- package/build/esm/ComboBox/scopeQuery.js.map +1 -1
- package/build/esm/FocusLock/FocusLock.d.ts +9 -9
- package/build/esm/FocusLock/FocusLock.js.map +1 -1
- package/build/esm/FocusLock/index.d.ts +1 -1
- package/build/esm/FocusLock/index.js.map +1 -1
- package/build/esm/FocusLock/tabUtils.d.ts +3 -3
- package/build/esm/FocusLock/tabUtils.js.map +1 -1
- package/build/esm/FocusLock/useFocusLock.d.ts +7 -7
- package/build/esm/FocusLock/useFocusLock.js.map +1 -1
- package/build/esm/List/List.d.ts +7 -7
- package/build/esm/List/List.js.map +1 -1
- package/build/esm/List/ListItem.d.ts +7 -7
- package/build/esm/List/ListItem.js.map +1 -1
- package/build/esm/List/context.d.ts +4 -4
- package/build/esm/List/context.js.map +1 -1
- package/build/esm/List/index.d.ts +2 -2
- package/build/esm/List/index.js.map +1 -1
- package/build/esm/Menu/ContextMenuTrigger.d.ts +11 -11
- package/build/esm/Menu/ContextMenuTrigger.js.map +1 -1
- package/build/esm/Menu/Menu.d.ts +10 -10
- package/build/esm/Menu/Menu.js.map +1 -1
- package/build/esm/Menu/MenuButton.d.ts +11 -11
- package/build/esm/Menu/MenuButton.js.map +1 -1
- package/build/esm/Menu/MenuItem.d.ts +8 -8
- package/build/esm/Menu/MenuItem.js +1 -0
- package/build/esm/Menu/MenuItem.js.map +1 -1
- package/build/esm/Menu/MenuList.d.ts +7 -7
- package/build/esm/Menu/MenuList.js +17 -4
- package/build/esm/Menu/MenuList.js.map +1 -1
- package/build/esm/Menu/MenuPopover.d.ts +8 -8
- package/build/esm/Menu/MenuPopover.js.map +1 -1
- package/build/esm/Menu/context.d.ts +25 -25
- package/build/esm/Menu/context.js.map +1 -1
- package/build/esm/Menu/fixtures/countryList.d.ts +1 -1
- package/build/esm/Menu/fixtures/countryList.js.map +1 -1
- package/build/esm/Menu/index.d.ts +6 -6
- package/build/esm/Menu/index.js.map +1 -1
- package/build/esm/Menu/scope.d.ts +1 -1
- package/build/esm/Menu/scope.js.map +1 -1
- package/build/esm/Modal/Modal.d.ts +9 -9
- package/build/esm/Modal/Modal.js.map +1 -1
- package/build/esm/Modal/ModalBackdrop.d.ts +10 -10
- package/build/esm/Modal/ModalBackdrop.js.map +1 -1
- package/build/esm/Modal/index.d.ts +2 -2
- package/build/esm/Modal/index.js.map +1 -1
- package/build/esm/Popper/Popper.d.ts +35 -35
- package/build/esm/Popper/Popper.js.map +1 -1
- package/build/esm/Popper/PopperArrow.d.ts +6 -6
- package/build/esm/Popper/PopperArrow.js.map +1 -1
- package/build/esm/Popper/context.d.ts +6 -6
- package/build/esm/Popper/context.js.map +1 -1
- package/build/esm/Popper/index.d.ts +3 -3
- package/build/esm/Popper/index.js.map +1 -1
- package/build/esm/Portal/Portal.d.ts +6 -6
- package/build/esm/Portal/Portal.js.map +1 -1
- package/build/esm/Portal/index.d.ts +1 -1
- package/build/esm/Portal/index.js.map +1 -1
- package/build/esm/RadioButton/RadioButton.d.ts +10 -10
- package/build/esm/RadioButton/RadioButton.js.map +1 -1
- package/build/esm/RadioButton/RadioGroup.d.ts +12 -12
- package/build/esm/RadioButton/RadioGroup.js.map +1 -1
- package/build/esm/RadioButton/context.d.ts +9 -9
- package/build/esm/RadioButton/context.js.map +1 -1
- package/build/esm/RadioButton/index.d.ts +2 -2
- package/build/esm/RadioButton/index.js.map +1 -1
- package/build/esm/SkipNav/SkipNav.d.ts +7 -7
- package/build/esm/SkipNav/SkipNav.js.map +1 -1
- package/build/esm/SkipNav/index.d.ts +1 -1
- package/build/esm/SkipNav/index.js.map +1 -1
- package/build/esm/Slider/Slider.d.ts +197 -197
- package/build/esm/Slider/Slider.js +82 -82
- package/build/esm/Slider/Slider.js.map +1 -1
- package/build/esm/Slider/index.d.ts +1 -1
- package/build/esm/Slider/index.js.map +1 -1
- package/build/esm/Spinner/Spinner.d.ts +12 -12
- package/build/esm/Spinner/Spinner.js.map +1 -1
- package/build/esm/Spinner/SpinnerButton.d.ts +8 -8
- package/build/esm/Spinner/SpinnerButton.js.map +1 -1
- package/build/esm/Spinner/context.d.ts +12 -12
- package/build/esm/Spinner/context.js.map +1 -1
- package/build/esm/Spinner/index.d.ts +2 -2
- package/build/esm/Spinner/index.js.map +1 -1
- package/build/esm/Tabs/Tab.d.ts +7 -7
- package/build/esm/Tabs/Tab.js.map +1 -1
- package/build/esm/Tabs/TabList.d.ts +9 -9
- package/build/esm/Tabs/TabList.js.map +1 -1
- package/build/esm/Tabs/TabPanel.d.ts +8 -8
- package/build/esm/Tabs/TabPanel.js.map +1 -1
- package/build/esm/Tabs/TabPanels.d.ts +8 -8
- package/build/esm/Tabs/TabPanels.js.map +1 -1
- package/build/esm/Tabs/Tabs.d.ts +10 -10
- package/build/esm/Tabs/Tabs.js.map +1 -1
- package/build/esm/Tabs/context.d.ts +17 -17
- package/build/esm/Tabs/context.js.map +1 -1
- package/build/esm/Tabs/index.d.ts +5 -5
- package/build/esm/Tabs/index.js.map +1 -1
- package/build/esm/Tabs/scopeQuery.d.ts +1 -1
- package/build/esm/Tabs/scopeQuery.js.map +1 -1
- package/build/esm/Tooltip/Tooltip.d.ts +10 -10
- package/build/esm/Tooltip/Tooltip.js.map +1 -1
- package/build/esm/Tooltip/index.d.ts +1 -1
- package/build/esm/Tooltip/index.js.map +1 -1
- package/build/esm/Tooltip/stateMachine.d.ts +28 -28
- package/build/esm/Tooltip/stateMachine.js.map +1 -1
- package/build/esm/Tooltip/useTooltip.d.ts +10 -10
- package/build/esm/Tooltip/useTooltip.js.map +1 -1
- package/build/esm/hooks/index.d.ts +13 -13
- package/build/esm/hooks/index.js.map +1 -1
- package/build/esm/hooks/useAutoFocus.d.ts +2 -2
- package/build/esm/hooks/useAutoFocus.js.map +1 -1
- package/build/esm/hooks/useChildrenCounter.d.ts +7 -7
- package/build/esm/hooks/useChildrenCounter.js.map +1 -1
- package/build/esm/hooks/useControlledState.d.ts +3 -3
- package/build/esm/hooks/useControlledState.js +1 -1
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/esm/hooks/useFocusReturn.d.ts +2 -2
- package/build/esm/hooks/useFocusReturn.js.map +1 -1
- package/build/esm/hooks/useFocusState.d.ts +11 -11
- package/build/esm/hooks/useFocusState.js.map +1 -1
- package/build/esm/hooks/useGestureHandlers.d.ts +52 -52
- package/build/esm/hooks/useGestureHandlers.js.map +1 -1
- package/build/esm/hooks/useMeasure.d.ts +7 -7
- package/build/esm/hooks/useMeasure.js.map +1 -1
- package/build/esm/hooks/useOnClickOutside.d.ts +2 -2
- package/build/esm/hooks/useOnClickOutside.js.map +1 -1
- package/build/esm/hooks/useOnKeyDown.d.ts +1 -1
- package/build/esm/hooks/useOnKeyDown.js.map +1 -1
- package/build/esm/hooks/useReducerMachine.d.ts +24 -24
- package/build/esm/hooks/useReducerMachine.js.map +1 -1
- package/build/esm/hooks/useRemoveBodyScroll.d.ts +2 -2
- package/build/esm/hooks/useRemoveBodyScroll.js.map +1 -1
- package/build/esm/hooks/useScope.d.ts +11 -11
- package/build/esm/hooks/useScope.js.map +1 -1
- package/build/esm/hooks/useThrottle.d.ts +1 -1
- package/build/esm/hooks/useThrottle.js.map +1 -1
- package/build/esm/index.d.ts +15 -15
- package/build/esm/index.js.map +1 -1
- package/build/esm/utils/assign-ref.d.ts +3 -3
- package/build/esm/utils/assign-ref.js.map +1 -1
- package/build/esm/utils/can-use-dom.d.ts +1 -1
- package/build/esm/utils/can-use-dom.js.map +1 -1
- package/build/esm/utils/clamp.d.ts +1 -1
- package/build/esm/utils/clamp.js.map +1 -1
- package/build/esm/utils/context.d.ts +7 -7
- package/build/esm/utils/context.js.map +1 -1
- package/build/esm/utils/create-subscription.d.ts +4 -4
- package/build/esm/utils/create-subscription.js.map +1 -1
- package/build/esm/utils/get-circular-index.d.ts +1 -1
- package/build/esm/utils/get-circular-index.js.map +1 -1
- package/build/esm/utils/index.d.ts +10 -10
- package/build/esm/utils/index.js.map +1 -1
- package/build/esm/utils/is-right-click.d.ts +6 -6
- package/build/esm/utils/is-right-click.js +4 -4
- package/build/esm/utils/is-right-click.js.map +1 -1
- package/build/esm/utils/owner-document.d.ts +7 -7
- package/build/esm/utils/owner-document.js +5 -5
- package/build/esm/utils/owner-document.js.map +1 -1
- package/build/esm/utils/polymorphic.d.ts +39 -39
- package/build/esm/utils/polymorphic.js.map +1 -1
- package/build/esm/utils/rubber-band-clamp.d.ts +2 -2
- package/build/esm/utils/rubber-band-clamp.js.map +1 -1
- package/build/esm/utils/use-stable-callback.d.ts +16 -16
- package/build/esm/utils/use-stable-callback.js +16 -16
- package/build/esm/utils/use-stable-callback.js.map +1 -1
- package/build/esm/utils/wrap-event.d.ts +3 -3
- package/build/esm/utils/wrap-event.js.map +1 -1
- package/build/tsconfig-build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/Accordion/Accordion.story.tsx +74 -74
- package/src/Accordion/Accordion.tsx +59 -59
- package/src/Accordion/AccordionBody.tsx +52 -52
- package/src/Accordion/AccordionHeader.tsx +167 -167
- package/src/Accordion/AccordionItem.tsx +50 -50
- package/src/Accordion/context.ts +37 -37
- package/src/Accordion/index.ts +4 -4
- package/src/Accordion/scopeQuery.ts +7 -7
- package/src/Accordion/styles.css +21 -21
- package/src/CheckBox/CheckBox.tsx +41 -41
- package/src/CheckBox/index.ts +1 -1
- package/src/ComboBox/ComboBox.story.tsx +120 -120
- package/src/ComboBox/Combobox.tsx +148 -148
- package/src/ComboBox/ComboboxButton.tsx +61 -61
- package/src/ComboBox/ComboboxInput.tsx +187 -187
- package/src/ComboBox/ComboboxLabel.tsx +33 -33
- package/src/ComboBox/ComboboxList.tsx +47 -47
- package/src/ComboBox/ComboboxOption.tsx +111 -111
- package/src/ComboBox/ComboboxPopover.tsx +64 -64
- package/src/ComboBox/cities.ts +23194 -23194
- package/src/ComboBox/context.ts +35 -35
- package/src/ComboBox/hooks.tsx +451 -451
- package/src/ComboBox/index.ts +8 -8
- package/src/ComboBox/makeHash.ts +19 -19
- package/src/ComboBox/scopeQuery.ts +6 -6
- package/src/ComboBox/styles.css +32 -32
- package/src/FocusLock/FocusLock.tsx +66 -66
- package/src/FocusLock/index.ts +1 -1
- package/src/FocusLock/tabUtils.ts +40 -40
- package/src/FocusLock/useFocusLock.ts +56 -56
- package/src/List/List.story.tsx +18 -18
- package/src/List/List.tsx +17 -17
- package/src/List/ListItem.tsx +23 -23
- package/src/List/context.ts +19 -19
- package/src/List/index.ts +2 -2
- package/src/Menu/ContextMenu.story.tsx +73 -73
- package/src/Menu/ContextMenuTrigger.tsx +76 -76
- package/src/Menu/Menu.story.tsx +160 -160
- package/src/Menu/Menu.tsx +83 -83
- package/src/Menu/MenuButton.tsx +83 -83
- package/src/Menu/MenuComplex.story.tsx +58 -58
- package/src/Menu/MenuItem.tsx +88 -87
- package/src/Menu/MenuList.tsx +254 -243
- package/src/Menu/MenuPopover.tsx +35 -35
- package/src/Menu/context.ts +44 -44
- package/src/Menu/fixtures/countryList.ts +198 -198
- package/src/Menu/index.ts +6 -6
- package/src/Menu/scope.ts +7 -7
- package/src/Menu/styles.css +42 -42
- package/src/Modal/Modal.story.tsx +258 -258
- package/src/Modal/Modal.tsx +48 -48
- package/src/Modal/ModalBackdrop.tsx +78 -78
- package/src/Modal/NavDrawer.story.tsx +158 -158
- package/src/Modal/index.ts +2 -2
- package/src/Modal/styles.css +46 -46
- package/src/Popper/Popper.story.tsx +263 -263
- package/src/Popper/Popper.tsx +154 -154
- package/src/Popper/PopperArrow.tsx +35 -35
- package/src/Popper/context.ts +10 -10
- package/src/Popper/index.ts +3 -3
- package/src/Popper/styles.css +60 -60
- package/src/Portal/Portal.tsx +20 -20
- package/src/Portal/index.ts +1 -1
- package/src/RadioButton/RadioButton.story.tsx +77 -77
- package/src/RadioButton/RadioButton.tsx +55 -55
- package/src/RadioButton/RadioGroup.tsx +60 -60
- package/src/RadioButton/context.ts +17 -17
- package/src/RadioButton/index.ts +2 -2
- package/src/SkipNav/SkipNav.tsx +16 -16
- package/src/SkipNav/index.tsx +1 -1
- package/src/Slider/Slider.story.tsx +45 -45
- package/src/Slider/Slider.tsx +1120 -1120
- package/src/Slider/index.ts +1 -1
- package/src/Slider/styles.css +131 -131
- package/src/Spinner/Spinner.story.tsx +31 -31
- package/src/Spinner/Spinner.tsx +117 -117
- package/src/Spinner/SpinnerButton.tsx +54 -54
- package/src/Spinner/context.ts +20 -20
- package/src/Spinner/index.ts +2 -2
- package/src/Spinner/styles.css +23 -23
- package/src/Tabs/Tab.story.tsx +80 -80
- package/src/Tabs/Tab.tsx +136 -136
- package/src/Tabs/TabList.tsx +71 -71
- package/src/Tabs/TabPanel.tsx +53 -53
- package/src/Tabs/TabPanels.tsx +30 -30
- package/src/Tabs/Tabs.tsx +46 -46
- package/src/Tabs/context.ts +30 -30
- package/src/Tabs/index.tsx +5 -5
- package/src/Tabs/scopeQuery.ts +6 -6
- package/src/Tooltip/Tooltip.story.tsx +61 -61
- package/src/Tooltip/Tooltip.tsx +50 -50
- package/src/Tooltip/index.ts +1 -1
- package/src/Tooltip/stateMachine.ts +192 -192
- package/src/Tooltip/styles.css +17 -17
- package/src/Tooltip/useTooltip.ts +136 -136
- package/src/hooks/index.ts +13 -13
- package/src/hooks/useAutoFocus.ts +22 -22
- package/src/hooks/useChildrenCounter.ts +51 -51
- package/src/hooks/useControlledState.ts +3 -3
- package/src/hooks/useFocusReturn.ts +43 -43
- package/src/hooks/useFocusState.ts +30 -30
- package/src/hooks/useGestureHandlers.ts +286 -286
- package/src/hooks/useMeasure.ts +33 -33
- package/src/hooks/useOnClickOutside.ts +32 -32
- package/src/hooks/useOnKeyDown.ts +19 -19
- package/src/hooks/useReducerMachine.ts +60 -60
- package/src/hooks/useRemoveBodyScroll.ts +39 -39
- package/src/hooks/useScope.ts +52 -52
- package/src/hooks/useThrottle.ts +19 -19
- package/src/index.ts +20 -20
- package/src/utils/assign-ref.ts +27 -27
- package/src/utils/can-use-dom.ts +7 -7
- package/src/utils/clamp.ts +3 -3
- package/src/utils/context.tsx +48 -48
- package/src/utils/create-subscription.ts +16 -16
- package/src/utils/get-circular-index.ts +7 -7
- package/src/utils/index.ts +10 -10
- package/src/utils/is-right-click.ts +14 -14
- package/src/utils/owner-document.ts +13 -13
- package/src/utils/polymorphic.ts +78 -78
- package/src/utils/rubber-band-clamp.ts +25 -25
- package/src/utils/use-stable-callback.ts +58 -58
- package/src/utils/wrap-event.ts +22 -22
|
@@ -1,187 +1,187 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ChangeEvent,
|
|
3
|
-
ChangeEventHandler,
|
|
4
|
-
ElementType,
|
|
5
|
-
FocusEventHandler,
|
|
6
|
-
InputHTMLAttributes,
|
|
7
|
-
KeyboardEventHandler,
|
|
8
|
-
MouseEventHandler,
|
|
9
|
-
} from 'react';
|
|
10
|
-
import { forwardRef, useEffect, useRef } from 'react';
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
useBlur,
|
|
14
|
-
CLEAR,
|
|
15
|
-
CHANGE,
|
|
16
|
-
useKeyDown,
|
|
17
|
-
SELECT_WITH_CLICK,
|
|
18
|
-
FOCUS,
|
|
19
|
-
NAVIGATING,
|
|
20
|
-
INIT,
|
|
21
|
-
useFocusManagement,
|
|
22
|
-
} from './hooks';
|
|
23
|
-
import { assignMultipleRefs, wrapEvent } from '../utils';
|
|
24
|
-
import { useComboBoxContext } from './context';
|
|
25
|
-
|
|
26
|
-
export interface ComboboxInputProps
|
|
27
|
-
extends InputHTMLAttributes<HTMLInputElement> {
|
|
28
|
-
// clear on ESC
|
|
29
|
-
clearOnEscape?: boolean;
|
|
30
|
-
// highlights all the text in the box on click when true
|
|
31
|
-
selectOnClick?: boolean;
|
|
32
|
-
// updates the value in the input when navigating w/ the keyboard
|
|
33
|
-
autocomplete?: boolean;
|
|
34
|
-
// initial value for uncontrolled mode
|
|
35
|
-
defaultValue?: string;
|
|
36
|
-
// value for controlled mode
|
|
37
|
-
value?: string;
|
|
38
|
-
onClick?: MouseEventHandler<HTMLInputElement>;
|
|
39
|
-
onChange?: ChangeEventHandler<HTMLInputElement>;
|
|
40
|
-
onKeyDown?: KeyboardEventHandler<HTMLInputElement>;
|
|
41
|
-
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
42
|
-
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
43
|
-
as?: ElementType<any>;
|
|
44
|
-
innerAs?: ElementType<any>;
|
|
45
|
-
id?: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const ComboboxInput = forwardRef<HTMLInputElement, ComboboxInputProps>(
|
|
49
|
-
function ComboboxInput(
|
|
50
|
-
{
|
|
51
|
-
as: Comp = 'input',
|
|
52
|
-
innerAs,
|
|
53
|
-
selectOnClick = false,
|
|
54
|
-
autocomplete = true,
|
|
55
|
-
clearOnEscape = false,
|
|
56
|
-
|
|
57
|
-
// wrapped events
|
|
58
|
-
onClick,
|
|
59
|
-
onChange,
|
|
60
|
-
onKeyDown,
|
|
61
|
-
onBlur,
|
|
62
|
-
onFocus,
|
|
63
|
-
|
|
64
|
-
id: preferredId,
|
|
65
|
-
|
|
66
|
-
defaultValue = '',
|
|
67
|
-
|
|
68
|
-
// might be controlled
|
|
69
|
-
value: controlledValue,
|
|
70
|
-
...props
|
|
71
|
-
},
|
|
72
|
-
forwardedRef
|
|
73
|
-
) {
|
|
74
|
-
const {
|
|
75
|
-
data: { navigationItem, text, lastActionType },
|
|
76
|
-
inputRef,
|
|
77
|
-
state,
|
|
78
|
-
transition,
|
|
79
|
-
listboxIdRef,
|
|
80
|
-
autocompletePropRef,
|
|
81
|
-
clearOnEscapeRef,
|
|
82
|
-
openOnFocus,
|
|
83
|
-
optionsRef,
|
|
84
|
-
labelIdRef,
|
|
85
|
-
} = useComboBoxContext();
|
|
86
|
-
|
|
87
|
-
// Keep focus on the input component
|
|
88
|
-
useFocusManagement(lastActionType, inputRef);
|
|
89
|
-
|
|
90
|
-
// Keep using the defaultValue until the user started interacting
|
|
91
|
-
const hasStartedInteracting = useRef(false);
|
|
92
|
-
|
|
93
|
-
// Because we close the List on blur, we need to track if the blur is
|
|
94
|
-
// caused by clicking inside the list, and if so, don't close the List.
|
|
95
|
-
const selectOnClickRef = useRef(false);
|
|
96
|
-
|
|
97
|
-
const handleBlur = useBlur();
|
|
98
|
-
|
|
99
|
-
// Update ref props
|
|
100
|
-
autocompletePropRef.current = autocomplete;
|
|
101
|
-
clearOnEscapeRef.current = clearOnEscape;
|
|
102
|
-
listboxIdRef.current = preferredId || listboxIdRef.current;
|
|
103
|
-
|
|
104
|
-
// [*]... and when controlled, we don't trigger handleValueChange as the user
|
|
105
|
-
// types, instead the developer controls it with the normal input onChange
|
|
106
|
-
// prop
|
|
107
|
-
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
108
|
-
// After the user started typing, lets forget the defaultValue
|
|
109
|
-
hasStartedInteracting.current = true;
|
|
110
|
-
|
|
111
|
-
const text = e.target.value;
|
|
112
|
-
if (text.trim() === '') {
|
|
113
|
-
transition(CLEAR);
|
|
114
|
-
} else {
|
|
115
|
-
transition(CHANGE, { text });
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const handleKeyDown = useKeyDown();
|
|
120
|
-
|
|
121
|
-
const handleFocus = () => {
|
|
122
|
-
if (selectOnClick) {
|
|
123
|
-
selectOnClickRef.current = true;
|
|
124
|
-
}
|
|
125
|
-
// If we select an option with click, useFocusManagement will focus the
|
|
126
|
-
// input, in those cases we don't want to cause the menu to open back up,
|
|
127
|
-
// so we guard behind these states
|
|
128
|
-
if (openOnFocus && lastActionType !== SELECT_WITH_CLICK) {
|
|
129
|
-
transition(FOCUS, {
|
|
130
|
-
item: navigationItem,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const handleClick = () => {
|
|
136
|
-
if (selectOnClickRef.current) {
|
|
137
|
-
selectOnClickRef.current = false;
|
|
138
|
-
inputRef.current && inputRef.current.select();
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const navigationText =
|
|
143
|
-
navigationItem !== ''
|
|
144
|
-
? optionsRef.current[navigationItem].text
|
|
145
|
-
: undefined;
|
|
146
|
-
|
|
147
|
-
const fallbackValue = hasStartedInteracting.current ? '' : defaultValue;
|
|
148
|
-
|
|
149
|
-
const inputStrings =
|
|
150
|
-
// When idle, we don't have a navigationText on ArrowUp/Down
|
|
151
|
-
autocomplete && state === NAVIGATING
|
|
152
|
-
? [navigationText, controlledValue, text, fallbackValue]
|
|
153
|
-
: [controlledValue, text, fallbackValue];
|
|
154
|
-
|
|
155
|
-
const inputValue = inputStrings.find((str) => str !== undefined);
|
|
156
|
-
|
|
157
|
-
// If they are controlling the value we still need to do our transitions, so
|
|
158
|
-
// we have this derived state to emulate onChange of the input as we receive
|
|
159
|
-
// new `value`s ...[*]
|
|
160
|
-
useEffect(() => {
|
|
161
|
-
transition(INIT, { text: inputValue, item: '' });
|
|
162
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
163
|
-
}, []);
|
|
164
|
-
|
|
165
|
-
return (
|
|
166
|
-
<Comp
|
|
167
|
-
{...props}
|
|
168
|
-
as={innerAs}
|
|
169
|
-
data-reach-combobox-input=""
|
|
170
|
-
ref={assignMultipleRefs(inputRef, forwardedRef)}
|
|
171
|
-
value={inputValue}
|
|
172
|
-
onClick={wrapEvent(onClick, handleClick)}
|
|
173
|
-
onBlur={wrapEvent(onBlur, handleBlur)}
|
|
174
|
-
onFocus={wrapEvent(onFocus, handleFocus)}
|
|
175
|
-
onChange={wrapEvent(onChange, handleChange)}
|
|
176
|
-
onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}
|
|
177
|
-
aria-labelledby={labelIdRef.current}
|
|
178
|
-
id={listboxIdRef.current}
|
|
179
|
-
aria-autocomplete="both"
|
|
180
|
-
aria-activedescendant={
|
|
181
|
-
navigationItem !== '' ? navigationItem : undefined
|
|
182
|
-
}
|
|
183
|
-
autoComplete="off"
|
|
184
|
-
/>
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
);
|
|
1
|
+
import type {
|
|
2
|
+
ChangeEvent,
|
|
3
|
+
ChangeEventHandler,
|
|
4
|
+
ElementType,
|
|
5
|
+
FocusEventHandler,
|
|
6
|
+
InputHTMLAttributes,
|
|
7
|
+
KeyboardEventHandler,
|
|
8
|
+
MouseEventHandler,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import { forwardRef, useEffect, useRef } from 'react';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
useBlur,
|
|
14
|
+
CLEAR,
|
|
15
|
+
CHANGE,
|
|
16
|
+
useKeyDown,
|
|
17
|
+
SELECT_WITH_CLICK,
|
|
18
|
+
FOCUS,
|
|
19
|
+
NAVIGATING,
|
|
20
|
+
INIT,
|
|
21
|
+
useFocusManagement,
|
|
22
|
+
} from './hooks';
|
|
23
|
+
import { assignMultipleRefs, wrapEvent } from '../utils';
|
|
24
|
+
import { useComboBoxContext } from './context';
|
|
25
|
+
|
|
26
|
+
export interface ComboboxInputProps
|
|
27
|
+
extends InputHTMLAttributes<HTMLInputElement> {
|
|
28
|
+
// clear on ESC
|
|
29
|
+
clearOnEscape?: boolean;
|
|
30
|
+
// highlights all the text in the box on click when true
|
|
31
|
+
selectOnClick?: boolean;
|
|
32
|
+
// updates the value in the input when navigating w/ the keyboard
|
|
33
|
+
autocomplete?: boolean;
|
|
34
|
+
// initial value for uncontrolled mode
|
|
35
|
+
defaultValue?: string;
|
|
36
|
+
// value for controlled mode
|
|
37
|
+
value?: string;
|
|
38
|
+
onClick?: MouseEventHandler<HTMLInputElement>;
|
|
39
|
+
onChange?: ChangeEventHandler<HTMLInputElement>;
|
|
40
|
+
onKeyDown?: KeyboardEventHandler<HTMLInputElement>;
|
|
41
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
42
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
43
|
+
as?: ElementType<any>;
|
|
44
|
+
innerAs?: ElementType<any>;
|
|
45
|
+
id?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const ComboboxInput = forwardRef<HTMLInputElement, ComboboxInputProps>(
|
|
49
|
+
function ComboboxInput(
|
|
50
|
+
{
|
|
51
|
+
as: Comp = 'input',
|
|
52
|
+
innerAs,
|
|
53
|
+
selectOnClick = false,
|
|
54
|
+
autocomplete = true,
|
|
55
|
+
clearOnEscape = false,
|
|
56
|
+
|
|
57
|
+
// wrapped events
|
|
58
|
+
onClick,
|
|
59
|
+
onChange,
|
|
60
|
+
onKeyDown,
|
|
61
|
+
onBlur,
|
|
62
|
+
onFocus,
|
|
63
|
+
|
|
64
|
+
id: preferredId,
|
|
65
|
+
|
|
66
|
+
defaultValue = '',
|
|
67
|
+
|
|
68
|
+
// might be controlled
|
|
69
|
+
value: controlledValue,
|
|
70
|
+
...props
|
|
71
|
+
},
|
|
72
|
+
forwardedRef
|
|
73
|
+
) {
|
|
74
|
+
const {
|
|
75
|
+
data: { navigationItem, text, lastActionType },
|
|
76
|
+
inputRef,
|
|
77
|
+
state,
|
|
78
|
+
transition,
|
|
79
|
+
listboxIdRef,
|
|
80
|
+
autocompletePropRef,
|
|
81
|
+
clearOnEscapeRef,
|
|
82
|
+
openOnFocus,
|
|
83
|
+
optionsRef,
|
|
84
|
+
labelIdRef,
|
|
85
|
+
} = useComboBoxContext();
|
|
86
|
+
|
|
87
|
+
// Keep focus on the input component
|
|
88
|
+
useFocusManagement(lastActionType, inputRef);
|
|
89
|
+
|
|
90
|
+
// Keep using the defaultValue until the user started interacting
|
|
91
|
+
const hasStartedInteracting = useRef(false);
|
|
92
|
+
|
|
93
|
+
// Because we close the List on blur, we need to track if the blur is
|
|
94
|
+
// caused by clicking inside the list, and if so, don't close the List.
|
|
95
|
+
const selectOnClickRef = useRef(false);
|
|
96
|
+
|
|
97
|
+
const handleBlur = useBlur();
|
|
98
|
+
|
|
99
|
+
// Update ref props
|
|
100
|
+
autocompletePropRef.current = autocomplete;
|
|
101
|
+
clearOnEscapeRef.current = clearOnEscape;
|
|
102
|
+
listboxIdRef.current = preferredId || listboxIdRef.current;
|
|
103
|
+
|
|
104
|
+
// [*]... and when controlled, we don't trigger handleValueChange as the user
|
|
105
|
+
// types, instead the developer controls it with the normal input onChange
|
|
106
|
+
// prop
|
|
107
|
+
const handleChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
108
|
+
// After the user started typing, lets forget the defaultValue
|
|
109
|
+
hasStartedInteracting.current = true;
|
|
110
|
+
|
|
111
|
+
const text = e.target.value;
|
|
112
|
+
if (text.trim() === '') {
|
|
113
|
+
transition(CLEAR);
|
|
114
|
+
} else {
|
|
115
|
+
transition(CHANGE, { text });
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const handleKeyDown = useKeyDown();
|
|
120
|
+
|
|
121
|
+
const handleFocus = () => {
|
|
122
|
+
if (selectOnClick) {
|
|
123
|
+
selectOnClickRef.current = true;
|
|
124
|
+
}
|
|
125
|
+
// If we select an option with click, useFocusManagement will focus the
|
|
126
|
+
// input, in those cases we don't want to cause the menu to open back up,
|
|
127
|
+
// so we guard behind these states
|
|
128
|
+
if (openOnFocus && lastActionType !== SELECT_WITH_CLICK) {
|
|
129
|
+
transition(FOCUS, {
|
|
130
|
+
item: navigationItem,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const handleClick = () => {
|
|
136
|
+
if (selectOnClickRef.current) {
|
|
137
|
+
selectOnClickRef.current = false;
|
|
138
|
+
inputRef.current && inputRef.current.select();
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const navigationText =
|
|
143
|
+
navigationItem !== ''
|
|
144
|
+
? optionsRef.current[navigationItem].text
|
|
145
|
+
: undefined;
|
|
146
|
+
|
|
147
|
+
const fallbackValue = hasStartedInteracting.current ? '' : defaultValue;
|
|
148
|
+
|
|
149
|
+
const inputStrings =
|
|
150
|
+
// When idle, we don't have a navigationText on ArrowUp/Down
|
|
151
|
+
autocomplete && state === NAVIGATING
|
|
152
|
+
? [navigationText, controlledValue, text, fallbackValue]
|
|
153
|
+
: [controlledValue, text, fallbackValue];
|
|
154
|
+
|
|
155
|
+
const inputValue = inputStrings.find((str) => str !== undefined);
|
|
156
|
+
|
|
157
|
+
// If they are controlling the value we still need to do our transitions, so
|
|
158
|
+
// we have this derived state to emulate onChange of the input as we receive
|
|
159
|
+
// new `value`s ...[*]
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
transition(INIT, { text: inputValue, item: '' });
|
|
162
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
163
|
+
}, []);
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<Comp
|
|
167
|
+
{...props}
|
|
168
|
+
as={innerAs}
|
|
169
|
+
data-reach-combobox-input=""
|
|
170
|
+
ref={assignMultipleRefs(inputRef, forwardedRef)}
|
|
171
|
+
value={inputValue}
|
|
172
|
+
onClick={wrapEvent(onClick, handleClick)}
|
|
173
|
+
onBlur={wrapEvent(onBlur, handleBlur)}
|
|
174
|
+
onFocus={wrapEvent(onFocus, handleFocus)}
|
|
175
|
+
onChange={wrapEvent(onChange, handleChange)}
|
|
176
|
+
onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}
|
|
177
|
+
aria-labelledby={labelIdRef.current}
|
|
178
|
+
id={listboxIdRef.current}
|
|
179
|
+
aria-autocomplete="both"
|
|
180
|
+
aria-activedescendant={
|
|
181
|
+
navigationItem !== '' ? navigationItem : undefined
|
|
182
|
+
}
|
|
183
|
+
autoComplete="off"
|
|
184
|
+
/>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
);
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import type { ElementType, LabelHTMLAttributes } from 'react';
|
|
2
|
-
import { forwardRef } from 'react';
|
|
3
|
-
|
|
4
|
-
import { useComboBoxContext } from './context';
|
|
5
|
-
|
|
6
|
-
export interface ComboboxLabelProps
|
|
7
|
-
extends LabelHTMLAttributes<HTMLLabelElement> {
|
|
8
|
-
as?: ElementType<any>;
|
|
9
|
-
innerAs?: ElementType<any>;
|
|
10
|
-
id?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const ComboboxLabel = forwardRef<HTMLLabelElement, ComboboxLabelProps>(
|
|
14
|
-
function ComboboxButton(
|
|
15
|
-
{ as: Comp = 'label', innerAs, id: preferredId, ...props },
|
|
16
|
-
ref
|
|
17
|
-
) {
|
|
18
|
-
const { listboxIdRef, labelIdRef } = useComboBoxContext();
|
|
19
|
-
|
|
20
|
-
labelIdRef.current = preferredId || labelIdRef.current;
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<Comp
|
|
24
|
-
as={innerAs}
|
|
25
|
-
data-reach-combobox-label=""
|
|
26
|
-
htmlFor={listboxIdRef.current}
|
|
27
|
-
id={labelIdRef.current}
|
|
28
|
-
ref={ref}
|
|
29
|
-
{...props}
|
|
30
|
-
/>
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
);
|
|
1
|
+
import type { ElementType, LabelHTMLAttributes } from 'react';
|
|
2
|
+
import { forwardRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import { useComboBoxContext } from './context';
|
|
5
|
+
|
|
6
|
+
export interface ComboboxLabelProps
|
|
7
|
+
extends LabelHTMLAttributes<HTMLLabelElement> {
|
|
8
|
+
as?: ElementType<any>;
|
|
9
|
+
innerAs?: ElementType<any>;
|
|
10
|
+
id?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const ComboboxLabel = forwardRef<HTMLLabelElement, ComboboxLabelProps>(
|
|
14
|
+
function ComboboxButton(
|
|
15
|
+
{ as: Comp = 'label', innerAs, id: preferredId, ...props },
|
|
16
|
+
ref
|
|
17
|
+
) {
|
|
18
|
+
const { listboxIdRef, labelIdRef } = useComboBoxContext();
|
|
19
|
+
|
|
20
|
+
labelIdRef.current = preferredId || labelIdRef.current;
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Comp
|
|
24
|
+
as={innerAs}
|
|
25
|
+
data-reach-combobox-label=""
|
|
26
|
+
htmlFor={listboxIdRef.current}
|
|
27
|
+
id={labelIdRef.current}
|
|
28
|
+
ref={ref}
|
|
29
|
+
{...props}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
);
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import type { HTMLAttributes, ElementType, ReactNode } from 'react';
|
|
2
|
-
import { forwardRef, useRef, useEffect } from 'react';
|
|
3
|
-
|
|
4
|
-
import { useComboBoxContext } from './context';
|
|
5
|
-
import { getScope } from '../hooks';
|
|
6
|
-
import { assignMultipleRefs } from '../utils';
|
|
7
|
-
|
|
8
|
-
export interface ComboboxListProps extends HTMLAttributes<HTMLUListElement> {
|
|
9
|
-
as?: ElementType<any>;
|
|
10
|
-
innerAs?: ElementType<any>;
|
|
11
|
-
persistSelection?: boolean;
|
|
12
|
-
children?: ReactNode;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const ComboboxList = forwardRef<HTMLUListElement, ComboboxListProps>(
|
|
16
|
-
function ComboboxList(
|
|
17
|
-
{
|
|
18
|
-
// when true, and the list opens again, the option with a matching value will be
|
|
19
|
-
// automatically highleted.
|
|
20
|
-
persistSelection = false,
|
|
21
|
-
as: Comp = 'ul',
|
|
22
|
-
innerAs,
|
|
23
|
-
...props
|
|
24
|
-
},
|
|
25
|
-
ref
|
|
26
|
-
) {
|
|
27
|
-
const { persistSelectionRef, labelIdRef, listScope } = useComboBoxContext();
|
|
28
|
-
|
|
29
|
-
const listRef = useRef<HTMLUListElement>();
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
listScope.current = getScope(listRef);
|
|
32
|
-
}, [listScope]);
|
|
33
|
-
|
|
34
|
-
persistSelectionRef.current = persistSelection;
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<Comp
|
|
38
|
-
{...props}
|
|
39
|
-
as={innerAs}
|
|
40
|
-
ref={assignMultipleRefs(ref, listRef)}
|
|
41
|
-
data-reach-combobox-list=""
|
|
42
|
-
role="listbox"
|
|
43
|
-
aria-labelledby={labelIdRef.current}
|
|
44
|
-
/>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
);
|
|
1
|
+
import type { HTMLAttributes, ElementType, ReactNode } from 'react';
|
|
2
|
+
import { forwardRef, useRef, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
import { useComboBoxContext } from './context';
|
|
5
|
+
import { getScope } from '../hooks';
|
|
6
|
+
import { assignMultipleRefs } from '../utils';
|
|
7
|
+
|
|
8
|
+
export interface ComboboxListProps extends HTMLAttributes<HTMLUListElement> {
|
|
9
|
+
as?: ElementType<any>;
|
|
10
|
+
innerAs?: ElementType<any>;
|
|
11
|
+
persistSelection?: boolean;
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const ComboboxList = forwardRef<HTMLUListElement, ComboboxListProps>(
|
|
16
|
+
function ComboboxList(
|
|
17
|
+
{
|
|
18
|
+
// when true, and the list opens again, the option with a matching value will be
|
|
19
|
+
// automatically highleted.
|
|
20
|
+
persistSelection = false,
|
|
21
|
+
as: Comp = 'ul',
|
|
22
|
+
innerAs,
|
|
23
|
+
...props
|
|
24
|
+
},
|
|
25
|
+
ref
|
|
26
|
+
) {
|
|
27
|
+
const { persistSelectionRef, labelIdRef, listScope } = useComboBoxContext();
|
|
28
|
+
|
|
29
|
+
const listRef = useRef<HTMLUListElement>();
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
listScope.current = getScope(listRef);
|
|
32
|
+
}, [listScope]);
|
|
33
|
+
|
|
34
|
+
persistSelectionRef.current = persistSelection;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Comp
|
|
38
|
+
{...props}
|
|
39
|
+
as={innerAs}
|
|
40
|
+
ref={assignMultipleRefs(ref, listRef)}
|
|
41
|
+
data-reach-combobox-list=""
|
|
42
|
+
role="listbox"
|
|
43
|
+
aria-labelledby={labelIdRef.current}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
);
|