@basic-ui/core 0.0.38 → 0.0.41
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/build/cjs/index.js +1 -1
- package/build/cjs/index.js.map +1 -1
- package/build/esm/Accordion/Accordion.d.ts +7 -7
- package/build/esm/Accordion/Accordion.js +22 -17
- package/build/esm/Accordion/Accordion.js.map +1 -1
- package/build/esm/Accordion/AccordionBody.d.ts +5 -5
- package/build/esm/Accordion/AccordionBody.js +23 -15
- package/build/esm/Accordion/AccordionBody.js.map +1 -1
- package/build/esm/Accordion/AccordionHeader.d.ts +6 -6
- package/build/esm/Accordion/AccordionHeader.js +45 -31
- package/build/esm/Accordion/AccordionHeader.js.map +1 -1
- package/build/esm/Accordion/AccordionItem.d.ts +7 -7
- package/build/esm/Accordion/AccordionItem.js +16 -16
- package/build/esm/Accordion/AccordionItem.js.map +1 -1
- package/build/esm/Accordion/context.d.ts +4 -4
- package/build/esm/Accordion/context.js +12 -10
- package/build/esm/Accordion/context.js.map +1 -1
- package/build/esm/CheckBox/CheckBox.d.ts +6 -6
- package/build/esm/CheckBox/CheckBox.js +19 -12
- package/build/esm/CheckBox/CheckBox.js.map +1 -1
- package/build/esm/ComboBox/Combobox.d.ts +10 -10
- package/build/esm/ComboBox/Combobox.js +52 -46
- package/build/esm/ComboBox/Combobox.js.map +1 -1
- package/build/esm/ComboBox/ComboboxButton.d.ts +8 -8
- package/build/esm/ComboBox/ComboboxButton.js +19 -20
- package/build/esm/ComboBox/ComboboxButton.js.map +1 -1
- package/build/esm/ComboBox/ComboboxInput.d.ts +10 -10
- package/build/esm/ComboBox/ComboboxInput.js +52 -50
- package/build/esm/ComboBox/ComboboxInput.js.map +1 -1
- package/build/esm/ComboBox/ComboboxLabel.d.ts +5 -5
- package/build/esm/ComboBox/ComboboxLabel.js +11 -12
- package/build/esm/ComboBox/ComboboxLabel.js.map +1 -1
- package/build/esm/ComboBox/ComboboxList.d.ts +6 -6
- package/build/esm/ComboBox/ComboboxList.js +15 -17
- package/build/esm/ComboBox/ComboboxList.js.map +1 -1
- package/build/esm/ComboBox/ComboboxOption.d.ts +7 -7
- package/build/esm/ComboBox/ComboboxOption.js +31 -34
- package/build/esm/ComboBox/ComboboxOption.js.map +1 -1
- package/build/esm/ComboBox/ComboboxPopover.d.ts +8 -8
- package/build/esm/ComboBox/ComboboxPopover.js +15 -17
- package/build/esm/ComboBox/ComboboxPopover.js.map +1 -1
- package/build/esm/ComboBox/context.d.ts +13 -13
- package/build/esm/ComboBox/context.js +6 -5
- package/build/esm/ComboBox/context.js.map +1 -1
- package/build/esm/ComboBox/hooks.d.ts +4 -4
- package/build/esm/ComboBox/hooks.js +82 -115
- package/build/esm/ComboBox/hooks.js.map +1 -1
- package/build/esm/ComboBox/makeHash.js +3 -3
- package/build/esm/ComboBox/makeHash.js.map +1 -1
- package/build/esm/FocusLock/FocusLock.d.ts +7 -7
- package/build/esm/FocusLock/FocusLock.js +17 -16
- package/build/esm/FocusLock/FocusLock.js.map +1 -1
- package/build/esm/FocusLock/tabUtils.js +4 -4
- package/build/esm/FocusLock/tabUtils.js.map +1 -1
- package/build/esm/FocusLock/useFocusLock.d.ts +4 -4
- package/build/esm/FocusLock/useFocusLock.js +10 -11
- package/build/esm/FocusLock/useFocusLock.js.map +1 -1
- package/build/esm/List/List.d.ts +6 -6
- package/build/esm/List/List.js +5 -6
- package/build/esm/List/List.js.map +1 -1
- package/build/esm/List/ListItem.d.ts +6 -6
- package/build/esm/List/ListItem.js +5 -6
- package/build/esm/List/ListItem.js.map +1 -1
- package/build/esm/List/context.js +3 -3
- package/build/esm/List/context.js.map +1 -1
- package/build/esm/Menu/Menu.d.ts +6 -6
- package/build/esm/Menu/Menu.js +29 -21
- package/build/esm/Menu/Menu.js.map +1 -1
- package/build/esm/Menu/MenuButton.d.ts +10 -10
- package/build/esm/Menu/MenuButton.js +27 -24
- package/build/esm/Menu/MenuButton.js.map +1 -1
- package/build/esm/Menu/MenuItem.d.ts +6 -6
- package/build/esm/Menu/MenuItem.js +23 -24
- package/build/esm/Menu/MenuItem.js.map +1 -1
- package/build/esm/Menu/MenuList.d.ts +5 -5
- package/build/esm/Menu/MenuList.js +61 -45
- package/build/esm/Menu/MenuList.js.map +1 -1
- package/build/esm/Menu/MenuPopover.d.ts +6 -6
- package/build/esm/Menu/MenuPopover.js +8 -10
- package/build/esm/Menu/MenuPopover.js.map +1 -1
- package/build/esm/Menu/context.d.ts +2 -2
- package/build/esm/Menu/context.js +11 -8
- package/build/esm/Menu/context.js.map +1 -1
- package/build/esm/Modal/Modal.d.ts +6 -7
- package/build/esm/Modal/Modal.js +11 -10
- package/build/esm/Modal/Modal.js.map +1 -1
- package/build/esm/Modal/ModalBackdrop.d.ts +6 -6
- package/build/esm/Modal/ModalBackdrop.js +20 -19
- package/build/esm/Modal/ModalBackdrop.js.map +1 -1
- package/build/esm/Popper/Popper.d.ts +8 -8
- package/build/esm/Popper/Popper.js +46 -37
- package/build/esm/Popper/Popper.js.map +1 -1
- package/build/esm/Popper/PopperArrow.d.ts +5 -5
- package/build/esm/Popper/PopperArrow.js +8 -9
- package/build/esm/Popper/PopperArrow.js.map +1 -1
- package/build/esm/Popper/context.d.ts +1 -1
- package/build/esm/Popper/context.js +5 -3
- package/build/esm/Popper/context.js.map +1 -1
- package/build/esm/Portal/Portal.d.ts +1 -1
- package/build/esm/Portal/Portal.js +6 -5
- package/build/esm/Portal/Portal.js.map +1 -1
- package/build/esm/RadioButton/RadioButton.d.ts +7 -7
- package/build/esm/RadioButton/RadioButton.js +12 -13
- package/build/esm/RadioButton/RadioButton.js.map +1 -1
- package/build/esm/RadioButton/RadioGroup.d.ts +8 -8
- package/build/esm/RadioButton/RadioGroup.js +22 -16
- package/build/esm/RadioButton/RadioGroup.js.map +1 -1
- package/build/esm/RadioButton/context.d.ts +2 -2
- package/build/esm/RadioButton/context.js +6 -5
- package/build/esm/RadioButton/context.js.map +1 -1
- package/build/esm/SkipNav/SkipNav.d.ts +6 -6
- package/build/esm/SkipNav/SkipNav.js +5 -6
- package/build/esm/SkipNav/SkipNav.js.map +1 -1
- package/build/esm/Spinner/Spinner.d.ts +7 -7
- package/build/esm/Spinner/Spinner.js +41 -31
- package/build/esm/Spinner/Spinner.js.map +1 -1
- package/build/esm/Spinner/SpinnerButton.d.ts +6 -6
- package/build/esm/Spinner/SpinnerButton.js +11 -12
- package/build/esm/Spinner/SpinnerButton.js.map +1 -1
- package/build/esm/Spinner/context.d.ts +2 -2
- package/build/esm/Spinner/context.js +6 -5
- package/build/esm/Spinner/context.js.map +1 -1
- package/build/esm/Tabs/Tab.d.ts +6 -6
- package/build/esm/Tabs/Tab.js +29 -29
- package/build/esm/Tabs/Tab.js.map +1 -1
- package/build/esm/Tabs/TabList.d.ts +6 -6
- package/build/esm/Tabs/TabList.js +24 -21
- package/build/esm/Tabs/TabList.js.map +1 -1
- package/build/esm/Tabs/TabPanel.d.ts +6 -6
- package/build/esm/Tabs/TabPanel.js +12 -12
- package/build/esm/Tabs/TabPanel.js.map +1 -1
- package/build/esm/Tabs/TabPanels.d.ts +5 -5
- package/build/esm/Tabs/TabPanels.js +13 -12
- package/build/esm/Tabs/TabPanels.js.map +1 -1
- package/build/esm/Tabs/Tabs.d.ts +6 -6
- package/build/esm/Tabs/Tabs.js +27 -14
- package/build/esm/Tabs/Tabs.js.map +1 -1
- package/build/esm/Tabs/context.d.ts +3 -3
- package/build/esm/Tabs/context.js +12 -10
- package/build/esm/Tabs/context.js.map +1 -1
- package/build/esm/Tooltip/Tooltip.d.ts +7 -7
- package/build/esm/Tooltip/Tooltip.js +18 -16
- package/build/esm/Tooltip/Tooltip.js.map +1 -1
- package/build/esm/Tooltip/stateMachine.js +56 -80
- package/build/esm/Tooltip/stateMachine.js.map +1 -1
- package/build/esm/Tooltip/useTooltip.d.ts +7 -7
- package/build/esm/Tooltip/useTooltip.js +32 -30
- package/build/esm/Tooltip/useTooltip.js.map +1 -1
- package/build/esm/hooks/useAutoFocus.d.ts +2 -2
- package/build/esm/hooks/useAutoFocus.js +1 -1
- package/build/esm/hooks/useAutoFocus.js.map +1 -1
- package/build/esm/hooks/useChildrenCounter.d.ts +1 -1
- package/build/esm/hooks/useChildrenCounter.js +6 -4
- package/build/esm/hooks/useChildrenCounter.js.map +1 -1
- package/build/esm/hooks/useControlledState.d.ts +3 -7
- package/build/esm/hooks/useControlledState.js +7 -2
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/esm/hooks/useFocusReturn.d.ts +1 -1
- package/build/esm/hooks/useFocusReturn.js +6 -6
- package/build/esm/hooks/useFocusReturn.js.map +1 -1
- package/build/esm/hooks/useFocusState.d.ts +3 -3
- package/build/esm/hooks/useFocusState.js +13 -9
- package/build/esm/hooks/useFocusState.js.map +1 -1
- package/build/esm/hooks/useGestureHandlers.d.ts +5 -5
- package/build/esm/hooks/useGestureHandlers.js +59 -63
- package/build/esm/hooks/useGestureHandlers.js.map +1 -1
- package/build/esm/hooks/useMeasure.d.ts +2 -2
- package/build/esm/hooks/useMeasure.js +13 -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 +5 -4
- package/build/esm/hooks/useOnClickOutside.js.map +1 -1
- package/build/esm/hooks/useOnKeyDown.js +4 -3
- package/build/esm/hooks/useOnKeyDown.js.map +1 -1
- package/build/esm/hooks/useReducerMachine.d.ts +1 -1
- package/build/esm/hooks/useReducerMachine.js +13 -10
- package/build/esm/hooks/useReducerMachine.js.map +1 -1
- package/build/esm/hooks/useRemoveBodyScroll.js +4 -4
- package/build/esm/hooks/useRemoveBodyScroll.js.map +1 -1
- package/build/esm/hooks/useScope.d.ts +1 -1
- package/build/esm/hooks/useScope.js +10 -12
- package/build/esm/hooks/useScope.js.map +1 -1
- package/build/esm/hooks/useThrottle.js +10 -5
- package/build/esm/hooks/useThrottle.js.map +1 -1
- package/build/esm/utils/assignRef.d.ts +1 -1
- package/build/esm/utils/assignRef.js +7 -3
- package/build/esm/utils/assignRef.js.map +1 -1
- package/build/esm/utils/createSubscription.js +7 -5
- package/build/esm/utils/createSubscription.js.map +1 -1
- package/build/esm/utils/rubberBandClamp.js +5 -2
- package/build/esm/utils/rubberBandClamp.js.map +1 -1
- package/build/esm/utils/wrapEvent.d.ts +3 -3
- package/build/esm/utils/wrapEvent.js +7 -3
- package/build/esm/utils/wrapEvent.js.map +1 -1
- package/build/tsconfig-build.tsbuildinfo +1 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/Accordion/Accordion.story.tsx +1 -0
- package/src/Accordion/Accordion.tsx +15 -7
- package/src/Accordion/AccordionBody.tsx +7 -8
- package/src/Accordion/AccordionHeader.tsx +35 -33
- package/src/Accordion/AccordionItem.tsx +15 -7
- package/src/Accordion/context.ts +5 -3
- package/src/CheckBox/CheckBox.tsx +6 -6
- package/src/ComboBox/ComboBox.story.tsx +5 -5
- package/src/ComboBox/Combobox.tsx +12 -17
- package/src/ComboBox/ComboboxButton.tsx +16 -15
- package/src/ComboBox/ComboboxInput.tsx +19 -10
- package/src/ComboBox/ComboboxLabel.tsx +5 -4
- package/src/ComboBox/ComboboxList.tsx +6 -6
- package/src/ComboBox/ComboboxOption.tsx +11 -7
- package/src/ComboBox/ComboboxPopover.tsx +14 -8
- package/src/ComboBox/context.ts +14 -12
- package/src/ComboBox/hooks.tsx +9 -11
- package/src/FocusLock/FocusLock.tsx +14 -7
- package/src/FocusLock/useFocusLock.ts +5 -3
- package/src/List/List.tsx +5 -5
- package/src/List/ListItem.tsx +5 -5
- package/src/Menu/Menu.story.tsx +7 -6
- package/src/Menu/Menu.tsx +16 -8
- package/src/Menu/MenuButton.tsx +15 -16
- package/src/Menu/MenuItem.tsx +15 -10
- package/src/Menu/MenuList.tsx +8 -12
- package/src/Menu/MenuPopover.tsx +7 -5
- package/src/Menu/context.ts +10 -4
- package/src/Modal/Modal.story.tsx +1 -0
- package/src/Modal/Modal.tsx +12 -6
- package/src/Modal/ModalBackdrop.tsx +15 -9
- package/src/Modal/NavDrawer.story.tsx +3 -3
- package/src/Popper/Popper.story.tsx +3 -4
- package/src/Popper/Popper.tsx +13 -12
- package/src/Popper/PopperArrow.tsx +5 -4
- package/src/Popper/context.ts +2 -1
- package/src/Portal/Portal.tsx +1 -1
- package/src/RadioButton/RadioButton.story.tsx +1 -0
- package/src/RadioButton/RadioButton.tsx +14 -7
- package/src/RadioButton/RadioGroup.tsx +14 -10
- package/src/RadioButton/context.ts +2 -4
- package/src/SkipNav/SkipNav.tsx +5 -5
- package/src/Spinner/Spinner.story.tsx +1 -0
- package/src/Spinner/Spinner.tsx +14 -9
- package/src/Spinner/SpinnerButton.tsx +12 -6
- package/src/Spinner/context.ts +2 -3
- package/src/Tabs/Tab.story.tsx +1 -0
- package/src/Tabs/Tab.tsx +16 -11
- package/src/Tabs/TabList.tsx +6 -5
- package/src/Tabs/TabPanel.tsx +6 -5
- package/src/Tabs/TabPanels.tsx +4 -4
- package/src/Tabs/Tabs.tsx +6 -7
- package/src/Tabs/context.ts +4 -4
- package/src/Tooltip/Tooltip.story.tsx +3 -2
- package/src/Tooltip/Tooltip.tsx +11 -9
- package/src/Tooltip/stateMachine.ts +1 -1
- package/src/Tooltip/useTooltip.ts +19 -10
- package/src/hooks/useAutoFocus.ts +3 -1
- package/src/hooks/useChildrenCounter.ts +2 -1
- package/src/hooks/useControlledState.ts +7 -8
- package/src/hooks/useFocusReturn.ts +2 -1
- package/src/hooks/useFocusState.ts +4 -2
- package/src/hooks/useGestureHandlers.ts +11 -7
- package/src/hooks/useMeasure.ts +2 -1
- package/src/hooks/useOnClickOutside.ts +2 -2
- package/src/hooks/useReducerMachine.ts +2 -1
- package/src/hooks/useScope.ts +2 -1
- package/src/utils/assignRef.ts +1 -1
- package/src/utils/wrapEvent.ts +4 -5
|
@@ -1,50 +1,48 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
4
|
import { forwardRef, useRef, useMemo, useId } from 'react';
|
|
4
5
|
import { stateChart, comboboxReducer, isVisible, INIT } from './hooks';
|
|
5
6
|
import { ComboBoxProvider } from './context';
|
|
6
7
|
import { useReducerMachine } from '../hooks/useReducerMachine';
|
|
7
8
|
import { getScope } from '../hooks';
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
innerAs
|
|
21
|
-
} = _ref,
|
|
22
|
-
rest = _objectWithoutPropertiesLoose(_ref, ["onSelect", "openOnFocus", "selectOnBlur", "children", "as", "innerAs"]);
|
|
10
|
+
export var Combobox = /*#__PURE__*/forwardRef(function Combobox(_ref, ref) {
|
|
11
|
+
var onSelect = _ref.onSelect,
|
|
12
|
+
_ref$openOnFocus = _ref.openOnFocus,
|
|
13
|
+
openOnFocus = _ref$openOnFocus === void 0 ? false : _ref$openOnFocus,
|
|
14
|
+
_ref$selectOnBlur = _ref.selectOnBlur,
|
|
15
|
+
selectOnBlur = _ref$selectOnBlur === void 0 ? false : _ref$selectOnBlur,
|
|
16
|
+
children = _ref.children,
|
|
17
|
+
_ref$as = _ref.as,
|
|
18
|
+
Comp = _ref$as === void 0 ? 'div' : _ref$as,
|
|
19
|
+
innerAs = _ref.innerAs,
|
|
20
|
+
rest = _objectWithoutProperties(_ref, ["onSelect", "openOnFocus", "selectOnBlur", "children", "as", "innerAs"]);
|
|
23
21
|
|
|
24
22
|
// We store the values of all the ComboboxOptions on this ref. This makes it
|
|
25
23
|
// possible to perform the keyboard navigation from the input on the list. We
|
|
26
24
|
// manipulate this array through context so that we don't have to enforce a
|
|
27
25
|
// parent/child relationship between ComboboxList and ComboboxOption.
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
var optionsRef = useRef({});
|
|
27
|
+
var listScope = useRef(getScope({
|
|
30
28
|
current: null
|
|
31
29
|
})); // Need this to focus it
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
var inputRef = useRef(null);
|
|
32
|
+
var popoverRef = useRef(null);
|
|
33
|
+
var buttonRef = useRef(null); // When <ComboboxInput autocomplete={false} /> we don't want cycle back to
|
|
36
34
|
// the user's value while navigating (because it's always the user's value),
|
|
37
35
|
// but we need to know this in useKeyDown which is far away from the prop
|
|
38
36
|
// here, so we do something sneaky and write it to this ref on context so we
|
|
39
37
|
// can use it anywhere else 😛. Another new trick for me and I'm excited
|
|
40
38
|
// about this one too!
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
var autocompletePropRef = useRef(false);
|
|
41
|
+
var persistSelectionRef = useRef(false);
|
|
42
|
+
var clearOnEscapeRef = useRef(false);
|
|
43
|
+
var listboxIdRef = useRef();
|
|
44
|
+
var labelIdRef = useRef();
|
|
45
|
+
var defaultData = {
|
|
48
46
|
// initial state
|
|
49
47
|
state: stateChart.initial,
|
|
50
48
|
// the value the user has typed, we derived this also when the developer is
|
|
@@ -58,28 +56,36 @@ export const Combobox = /*#__PURE__*/forwardRef(function Combobox(_ref, ref) {
|
|
|
58
56
|
// the last submitted action
|
|
59
57
|
lastActionType: INIT
|
|
60
58
|
};
|
|
61
|
-
|
|
59
|
+
|
|
60
|
+
var _useReducerMachine = useReducerMachine(stateChart, comboboxReducer, defaultData),
|
|
61
|
+
_useReducerMachine2 = _slicedToArray(_useReducerMachine, 3),
|
|
62
|
+
state = _useReducerMachine2[0],
|
|
63
|
+
data = _useReducerMachine2[1],
|
|
64
|
+
transition = _useReducerMachine2[2];
|
|
65
|
+
|
|
62
66
|
listboxIdRef.current = useId();
|
|
63
67
|
labelIdRef.current = useId();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
68
|
+
var context = useMemo(function () {
|
|
69
|
+
return {
|
|
70
|
+
data: data,
|
|
71
|
+
inputRef: inputRef,
|
|
72
|
+
popoverRef: popoverRef,
|
|
73
|
+
buttonRef: buttonRef,
|
|
74
|
+
onSelect: onSelect,
|
|
75
|
+
optionsRef: optionsRef,
|
|
76
|
+
listScope: listScope,
|
|
77
|
+
state: state,
|
|
78
|
+
transition: transition,
|
|
79
|
+
listboxIdRef: listboxIdRef,
|
|
80
|
+
labelIdRef: labelIdRef,
|
|
81
|
+
autocompletePropRef: autocompletePropRef,
|
|
82
|
+
persistSelectionRef: persistSelectionRef,
|
|
83
|
+
clearOnEscapeRef: clearOnEscapeRef,
|
|
84
|
+
isVisible: isVisible(state),
|
|
85
|
+
openOnFocus: openOnFocus,
|
|
86
|
+
selectOnBlur: selectOnBlur
|
|
87
|
+
};
|
|
88
|
+
}, [data, onSelect, listScope, state, transition, openOnFocus, selectOnBlur]);
|
|
83
89
|
return /*#__PURE__*/_jsx(ComboBoxProvider, {
|
|
84
90
|
value: context,
|
|
85
91
|
children: /*#__PURE__*/_jsx(Comp, _extends({}, rest, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ComboBox/Combobox.tsx"],"names":["forwardRef","useRef","useMemo","useId","stateChart","comboboxReducer","isVisible","INIT","ComboBoxProvider","useReducerMachine","getScope","Combobox","ref","onSelect","openOnFocus","selectOnBlur","children","as","Comp","innerAs","rest","optionsRef","listScope","current","inputRef","popoverRef","buttonRef","autocompletePropRef","persistSelectionRef","clearOnEscapeRef","listboxIdRef","labelIdRef","defaultData","state","initial","text","item","navigationItem","lastActionType","data","transition","context"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/ComboBox/Combobox.tsx"],"names":["forwardRef","useRef","useMemo","useId","stateChart","comboboxReducer","isVisible","INIT","ComboBoxProvider","useReducerMachine","getScope","Combobox","ref","onSelect","openOnFocus","selectOnBlur","children","as","Comp","innerAs","rest","optionsRef","listScope","current","inputRef","popoverRef","buttonRef","autocompletePropRef","persistSelectionRef","clearOnEscapeRef","listboxIdRef","labelIdRef","defaultData","state","initial","text","item","navigationItem","lastActionType","data","transition","context"],"mappings":";;;AACA,SAASA,UAAT,EAAqBC,MAArB,EAA6BC,OAA7B,EAAsCC,KAAtC,QAAmD,OAAnD;AAGA,SAASC,UAAT,EAAqBC,eAArB,EAAsCC,SAAtC,EAAiDC,IAAjD,QAA6D,SAA7D;AAEA,SAASC,gBAAT,QAAiC,WAAjC;AACA,SAASC,iBAAT,QAAkC,4BAAlC;AAEA,SAASC,QAAT,QAAyB,UAAzB;;AAiBA,OAAO,IAAMC,QAAQ,gBAAGX,UAAU,CAChC,SAASW,QAAT,OAiBEC,GAjBF,EAkBE;AAAA,MAfEC,QAeF,QAfEA,QAeF;AAAA,8BAXEC,WAWF;AAAA,MAXEA,WAWF,iCAXgB,KAWhB;AAAA,+BAREC,YAQF;AAAA,MAREA,YAQF,kCARiB,KAQjB;AAAA,MANEC,QAMF,QANEA,QAMF;AAAA,qBALEC,EAKF;AAAA,MALMC,IAKN,wBALa,KAKb;AAAA,MAJEC,OAIF,QAJEA,OAIF;AAAA,MAHKC,IAGL;;AACA;AACA;AACA;AACA;AACA,MAAMC,UAAU,GAAGpB,MAAM,CAKtB,EALsB,CAAzB;AAOA,MAAMqB,SAA6B,GAAGrB,MAAM,CAACS,QAAQ,CAAC;AAAEa,IAAAA,OAAO,EAAE;AAAX,GAAD,CAAT,CAA5C,CAZA,CAcA;;AACA,MAAMC,QAAQ,GAAGvB,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AA,SAAS,EAATA,SAP2B;AAQ3BW,MAAAA,KAAK,EAALA,KAR2B;AAS3BO,MAAAA,UAAU,EAAVA,UAT2B;AAU3BV,MAAAA,YAAY,EAAZA,YAV2B;AAW3BC,MAAAA,UAAU,EAAVA,UAX2B;AAY3BJ,MAAAA,mBAAmB,EAAnBA,mBAZ2B;AAa3BC,MAAAA,mBAAmB,EAAnBA,mBAb2B;AAc3BC,MAAAA,gBAAgB,EAAhBA,gBAd2B;AAe3BvB,MAAAA,SAAS,EAAEA,SAAS,CAAC2B,KAAD,CAfO;AAgB3BnB,MAAAA,WAAW,EAAXA,WAhB2B;AAiB3BC,MAAAA,YAAY,EAAZA;AAjB2B,KAA7B;AAAA,GADqB,EAoBrB,CAACwB,IAAD,EAAO1B,QAAP,EAAiBS,SAAjB,EAA4BW,KAA5B,EAAmCO,UAAnC,EAA+C1B,WAA/C,EAA4DC,YAA5D,CApBqB,CAAvB;AAuBA,sBACE,KAAC,gBAAD;AAAkB,IAAA,KAAK,EAAE0B,OAAzB;AAAA,2BACE,KAAC,IAAD,eACMrB,IADN;AAEE,MAAA,EAAE,EAAED,OAFN;AAGE,6BAAoB,EAHtB;AAIE,MAAA,GAAG,EAAEP,GAJP;AAKE,MAAA,IAAI,EAAC,UALP;AAME,uBAAc,SANhB;AAOE,mBAAWkB,YAAY,CAACP,OAP1B;AAQE,uBAAekB,OAAO,CAACnC,SARzB;AAAA,gBAUGU;AAVH;AADF,IADF;AAgBD,CAxH+B,CAA3B","sourcesContent":["import type { HTMLAttributes, ReactNode, ElementType } from 'react';\nimport { forwardRef, useRef, useMemo, useId } from 'react';\n\nimport type { ActionTypes } from './hooks';\nimport { stateChart, comboboxReducer, isVisible, INIT } from './hooks';\nimport type { ComboBoxContextProps } from './context';\nimport { ComboBoxProvider } from './context';\nimport { useReducerMachine } from '../hooks/useReducerMachine';\nimport type { Scope } from '../hooks';\nimport { getScope } from '../hooks';\n\nexport type SelectEventHandler = (\n text: string,\n itemId: string,\n obj: any\n) => void;\n\nexport type ComboboxProps = Omit<HTMLAttributes<HTMLDivElement>, 'onSelect'> & {\n onSelect?: SelectEventHandler;\n openOnFocus?: boolean;\n selectOnBlur?: boolean;\n children?: ReactNode;\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n};\n\nexport const Combobox = forwardRef<HTMLDivElement, ComboboxProps>(\n function Combobox(\n {\n // Called whenever the user selects an item from the list\n onSelect,\n\n // opens the list when the input receives focused (but only if there are\n // items in the list)\n openOnFocus = false,\n\n // if set to true, it will select an item after blurring\n selectOnBlur = false,\n\n children,\n as: Comp = 'div',\n innerAs,\n ...rest\n }: ComboboxProps,\n ref\n ) {\n // We store the values of all the ComboboxOptions on this ref. This makes it\n // possible to perform the keyboard navigation from the input on the list. We\n // manipulate this array through context so that we don't have to enforce a\n // parent/child relationship between ComboboxList and ComboboxOption.\n const optionsRef = useRef<{\n [itemId: string]: {\n value: string | unknown;\n text: string;\n };\n }>({});\n\n const listScope: Scope<HTMLElement> = useRef(getScope({ current: null }));\n\n // Need this to focus it\n const inputRef = useRef<HTMLInputElement>(null);\n\n const popoverRef = useRef<HTMLDivElement>(null);\n\n const buttonRef = useRef<HTMLButtonElement>(null);\n\n // When <ComboboxInput autocomplete={false} /> we don't want cycle back to\n // the user's value while navigating (because it's always the user's value),\n // but we need to know this in useKeyDown which is far away from the prop\n // here, so we do something sneaky and write it to this ref on context so we\n // can use it anywhere else 😛. Another new trick for me and I'm excited\n // about this one too!\n const autocompletePropRef = useRef<boolean>(false);\n\n const persistSelectionRef = useRef<boolean>(false);\n\n const clearOnEscapeRef = useRef<boolean>(false);\n\n const listboxIdRef = useRef<string | undefined>();\n\n const labelIdRef = useRef<string | undefined>();\n\n const defaultData = {\n // initial state\n state: stateChart.initial,\n // the value the user has typed, we derived this also when the developer is\n // controlling the value of ComboboxInput\n text: '',\n // the index the user has typed, we derived this also when the developer is\n // controlling the value of ComboboxInput\n item: '',\n // the hash of the currently navigated item\n navigationItem: '',\n // the last submitted action\n lastActionType: INIT as ActionTypes,\n };\n\n const [state, data, transition] = useReducerMachine(\n stateChart,\n comboboxReducer,\n defaultData\n );\n\n listboxIdRef.current = useId();\n\n labelIdRef.current = useId();\n\n const context = useMemo(\n (): ComboBoxContextProps => ({\n data,\n inputRef,\n popoverRef,\n buttonRef,\n onSelect,\n optionsRef,\n listScope,\n state,\n transition,\n listboxIdRef,\n labelIdRef,\n autocompletePropRef,\n persistSelectionRef,\n clearOnEscapeRef,\n isVisible: isVisible(state),\n openOnFocus,\n selectOnBlur,\n }),\n [data, onSelect, listScope, state, transition, openOnFocus, selectOnBlur]\n );\n\n return (\n <ComboBoxProvider value={context}>\n <Comp\n {...rest}\n as={innerAs}\n data-reach-combobox=\"\"\n ref={ref}\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-owns={listboxIdRef.current}\n aria-expanded={context.isVisible}\n >\n {children}\n </Comp>\n </ComboBoxProvider>\n );\n }\n);\n"],"file":"Combobox.js"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export interface ComboboxButtonProps extends
|
|
3
|
-
as?:
|
|
4
|
-
innerAs?:
|
|
5
|
-
onClick?:
|
|
6
|
-
onKeyDown?:
|
|
7
|
-
children?:
|
|
1
|
+
import type { ButtonHTMLAttributes, ElementType, KeyboardEventHandler, MouseEventHandler, ReactNode } from 'react';
|
|
2
|
+
export interface ComboboxButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
3
|
+
as?: ElementType<any>;
|
|
4
|
+
innerAs?: ElementType<any>;
|
|
5
|
+
onClick?: MouseEventHandler<HTMLButtonElement>;
|
|
6
|
+
onKeyDown?: KeyboardEventHandler<HTMLButtonElement>;
|
|
7
|
+
children?: ReactNode;
|
|
8
8
|
}
|
|
9
|
-
export declare const ComboboxButton:
|
|
9
|
+
export declare const ComboboxButton: import("react").ForwardRefExoticComponent<ComboboxButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
import { forwardRef } from 'react';
|
|
4
4
|
import { useComboBoxContext } from './context';
|
|
5
5
|
import { useKeyDown, IDLE, OPEN_WITH_BUTTON, CLOSE_WITH_BUTTON } from './hooks';
|
|
6
6
|
import { wrapEvent } from '../utils/wrapEvent';
|
|
7
7
|
import { assignMultipleRefs } from '../utils/assignRef';
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
props = _objectWithoutPropertiesLoose(_ref, ["as", "innerAs", "onClick", "onKeyDown"]);
|
|
9
|
+
export var ComboboxButton = /*#__PURE__*/forwardRef(function ComboboxButton(_ref, ref) {
|
|
10
|
+
var _ref$as = _ref.as,
|
|
11
|
+
Comp = _ref$as === void 0 ? 'button' : _ref$as,
|
|
12
|
+
innerAs = _ref.innerAs,
|
|
13
|
+
onClick = _ref.onClick,
|
|
14
|
+
onKeyDown = _ref.onKeyDown,
|
|
15
|
+
props = _objectWithoutProperties(_ref, ["as", "innerAs", "onClick", "onKeyDown"]);
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} = useComboBoxContext();
|
|
26
|
-
const handleKeyDown = useKeyDown();
|
|
17
|
+
var _useComboBoxContext = useComboBoxContext(),
|
|
18
|
+
transition = _useComboBoxContext.transition,
|
|
19
|
+
data = _useComboBoxContext.data,
|
|
20
|
+
state = _useComboBoxContext.state,
|
|
21
|
+
buttonRef = _useComboBoxContext.buttonRef,
|
|
22
|
+
listboxIdRef = _useComboBoxContext.listboxIdRef,
|
|
23
|
+
isVisible = _useComboBoxContext.isVisible;
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
var handleKeyDown = useKeyDown();
|
|
26
|
+
|
|
27
|
+
var handleClick = function handleClick() {
|
|
28
|
+
var payload = {
|
|
30
29
|
item: data.navigationItem
|
|
31
30
|
};
|
|
32
31
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ComboBox/ComboboxButton.tsx"],"names":["forwardRef","useComboBoxContext","useKeyDown","IDLE","OPEN_WITH_BUTTON","CLOSE_WITH_BUTTON","wrapEvent","assignMultipleRefs","ComboboxButton","ref","as","Comp","innerAs","onClick","onKeyDown","props","transition","data","state","buttonRef","listboxIdRef","isVisible","handleKeyDown","handleClick","payload","item","navigationItem","current"],"mappings":";;
|
|
1
|
+
{"version":3,"sources":["../../../src/ComboBox/ComboboxButton.tsx"],"names":["forwardRef","useComboBoxContext","useKeyDown","IDLE","OPEN_WITH_BUTTON","CLOSE_WITH_BUTTON","wrapEvent","assignMultipleRefs","ComboboxButton","ref","as","Comp","innerAs","onClick","onKeyDown","props","transition","data","state","buttonRef","listboxIdRef","isVisible","handleKeyDown","handleClick","payload","item","navigationItem","current"],"mappings":";;AAOA,SAASA,UAAT,QAA2B,OAA3B;AAEA,SAASC,kBAAT,QAAmC,WAAnC;AACA,SAASC,UAAT,EAAqBC,IAArB,EAA2BC,gBAA3B,EAA6CC,iBAA7C,QAAsE,SAAtE;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,SAASC,kBAAT,QAAmC,oBAAnC;;AAWA,OAAO,IAAMC,cAAc,gBAAGR,UAAU,CAGtC,SAASQ,cAAT,OAEAC,GAFA,EAGA;AAAA,qBAFEC,EAEF;AAAA,MAFMC,IAEN,wBAFa,QAEb;AAAA,MAFuBC,OAEvB,QAFuBA,OAEvB;AAAA,MAFgCC,OAEhC,QAFgCA,OAEhC;AAAA,MAFyCC,SAEzC,QAFyCA,SAEzC;AAAA,MAFuDC,KAEvD;;AAAA,4BAEEd,kBAAkB,EAFpB;AAAA,MACQe,UADR,uBACQA,UADR;AAAA,MACoBC,IADpB,uBACoBA,IADpB;AAAA,MAC0BC,KAD1B,uBAC0BA,KAD1B;AAAA,MACiCC,SADjC,uBACiCA,SADjC;AAAA,MAC4CC,YAD5C,uBAC4CA,YAD5C;AAAA,MAC0DC,SAD1D,uBAC0DA,SAD1D;;AAIA,MAAMC,aAAa,GAAGpB,UAAU,EAAhC;;AAEA,MAAMqB,WAAW,GAAG,SAAdA,WAAc,GAAM;AACxB,QAAMC,OAAO,GAAG;AACdC,MAAAA,IAAI,EAAER,IAAI,CAACS;AADG,KAAhB;;AAIA,QAAIR,KAAK,KAAKf,IAAd,EAAoB;AAClBa,MAAAA,UAAU,CAACZ,gBAAD,EAAmBoB,OAAnB,CAAV;AACD,KAFD,MAEO;AACLR,MAAAA,UAAU,CAACX,iBAAD,EAAoBmB,OAApB,CAAV;AACD;AACF,GAVD;;AAYA,sBACE,KAAC,IAAD;AACE,IAAA,EAAE,EAAEZ,OADN;AAEE,kCAA2B,EAF7B;AAGE,qBAAeQ,YAAY,CAACO,OAH9B;AAIE,qBAAc,SAJhB;AAKE,qBAAeN,SALjB;AAME,IAAA,GAAG,EAAEd,kBAAkB,CAACE,GAAD,EAAMU,SAAN,CANzB;AAOE,IAAA,OAAO,EAAEb,SAAS,CAACO,OAAD,EAAUU,WAAV,CAPpB;AAQE,IAAA,SAAS,EAAEjB,SAAS,CAACQ,SAAD,EAAYQ,aAAZ;AARtB,KASMP,KATN,EADF;AAaD,CArCuC,CAAjC","sourcesContent":["import type {\n ButtonHTMLAttributes,\n ElementType,\n KeyboardEventHandler,\n MouseEventHandler,\n ReactNode,\n} from 'react';\nimport { forwardRef } from 'react';\n\nimport { useComboBoxContext } from './context';\nimport { useKeyDown, IDLE, OPEN_WITH_BUTTON, CLOSE_WITH_BUTTON } from './hooks';\nimport { wrapEvent } from '../utils/wrapEvent';\nimport { assignMultipleRefs } from '../utils/assignRef';\n\nexport interface ComboboxButtonProps\n extends ButtonHTMLAttributes<HTMLButtonElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n onClick?: MouseEventHandler<HTMLButtonElement>;\n onKeyDown?: KeyboardEventHandler<HTMLButtonElement>;\n children?: ReactNode;\n}\n\nexport const ComboboxButton = forwardRef<\n HTMLButtonElement,\n ComboboxButtonProps\n>(function ComboboxButton(\n { as: Comp = 'button', innerAs, onClick, onKeyDown, ...props },\n ref\n) {\n const { transition, data, state, buttonRef, listboxIdRef, isVisible } =\n useComboBoxContext();\n\n const handleKeyDown = useKeyDown();\n\n const handleClick = () => {\n const payload = {\n item: data.navigationItem,\n };\n\n if (state === IDLE) {\n transition(OPEN_WITH_BUTTON, payload);\n } else {\n transition(CLOSE_WITH_BUTTON, payload);\n }\n };\n\n return (\n <Comp\n as={innerAs}\n data-reach-combobox-button=\"\"\n aria-controls={listboxIdRef.current}\n aria-haspopup=\"listbox\"\n aria-expanded={isVisible}\n ref={assignMultipleRefs(ref, buttonRef)}\n onClick={wrapEvent(onClick, handleClick)}\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n {...props}\n />\n );\n});\n"],"file":"ComboboxButton.js"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export interface ComboboxInputProps extends
|
|
1
|
+
import type { ChangeEventHandler, ElementType, FocusEventHandler, InputHTMLAttributes, KeyboardEventHandler, MouseEventHandler } from 'react';
|
|
2
|
+
export interface ComboboxInputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
3
3
|
clearOnEscape?: boolean;
|
|
4
4
|
selectOnClick?: boolean;
|
|
5
5
|
autocomplete?: boolean;
|
|
6
6
|
defaultValue?: string;
|
|
7
7
|
value?: string;
|
|
8
|
-
onClick?:
|
|
9
|
-
onChange?:
|
|
10
|
-
onKeyDown?:
|
|
11
|
-
onBlur?:
|
|
12
|
-
onFocus?:
|
|
13
|
-
as?:
|
|
14
|
-
innerAs?:
|
|
8
|
+
onClick?: MouseEventHandler<HTMLInputElement>;
|
|
9
|
+
onChange?: ChangeEventHandler<HTMLInputElement>;
|
|
10
|
+
onKeyDown?: KeyboardEventHandler<HTMLInputElement>;
|
|
11
|
+
onBlur?: FocusEventHandler<HTMLInputElement>;
|
|
12
|
+
onFocus?: FocusEventHandler<HTMLInputElement>;
|
|
13
|
+
as?: ElementType<any>;
|
|
14
|
+
innerAs?: ElementType<any>;
|
|
15
15
|
id?: string;
|
|
16
16
|
}
|
|
17
|
-
export declare const ComboboxInput:
|
|
17
|
+
export declare const ComboboxInput: import("react").ForwardRefExoticComponent<ComboboxInputProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -1,54 +1,54 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
import { forwardRef, useEffect, useRef } from 'react';
|
|
4
4
|
import { useBlur, CLEAR, CHANGE, useKeyDown, SELECT_WITH_CLICK, FOCUS, NAVIGATING, INIT, useFocusManagement } from './hooks';
|
|
5
5
|
import { assignMultipleRefs, wrapEvent } from '../utils';
|
|
6
6
|
import { useComboBoxContext } from './context';
|
|
7
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
export var ComboboxInput = /*#__PURE__*/forwardRef(function ComboboxInput(_ref, forwardedRef) {
|
|
9
|
+
var _ref$as = _ref.as,
|
|
10
|
+
Comp = _ref$as === void 0 ? 'input' : _ref$as,
|
|
11
|
+
innerAs = _ref.innerAs,
|
|
12
|
+
_ref$selectOnClick = _ref.selectOnClick,
|
|
13
|
+
selectOnClick = _ref$selectOnClick === void 0 ? false : _ref$selectOnClick,
|
|
14
|
+
_ref$autocomplete = _ref.autocomplete,
|
|
15
|
+
autocomplete = _ref$autocomplete === void 0 ? true : _ref$autocomplete,
|
|
16
|
+
_ref$clearOnEscape = _ref.clearOnEscape,
|
|
17
|
+
clearOnEscape = _ref$clearOnEscape === void 0 ? false : _ref$clearOnEscape,
|
|
18
|
+
onClick = _ref.onClick,
|
|
19
|
+
onChange = _ref.onChange,
|
|
20
|
+
onKeyDown = _ref.onKeyDown,
|
|
21
|
+
onBlur = _ref.onBlur,
|
|
22
|
+
onFocus = _ref.onFocus,
|
|
23
|
+
preferredId = _ref.id,
|
|
24
|
+
_ref$defaultValue = _ref.defaultValue,
|
|
25
|
+
defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
|
|
26
|
+
controlledValue = _ref.value,
|
|
27
|
+
props = _objectWithoutProperties(_ref, ["as", "innerAs", "selectOnClick", "autocomplete", "clearOnEscape", "onClick", "onChange", "onKeyDown", "onBlur", "onFocus", "id", "defaultValue", "value"]);
|
|
28
|
+
|
|
29
|
+
var _useComboBoxContext = useComboBoxContext(),
|
|
30
|
+
_useComboBoxContext$d = _useComboBoxContext.data,
|
|
31
|
+
navigationItem = _useComboBoxContext$d.navigationItem,
|
|
32
|
+
text = _useComboBoxContext$d.text,
|
|
33
|
+
lastActionType = _useComboBoxContext$d.lastActionType,
|
|
34
|
+
inputRef = _useComboBoxContext.inputRef,
|
|
35
|
+
state = _useComboBoxContext.state,
|
|
36
|
+
transition = _useComboBoxContext.transition,
|
|
37
|
+
listboxIdRef = _useComboBoxContext.listboxIdRef,
|
|
38
|
+
autocompletePropRef = _useComboBoxContext.autocompletePropRef,
|
|
39
|
+
clearOnEscapeRef = _useComboBoxContext.clearOnEscapeRef,
|
|
40
|
+
openOnFocus = _useComboBoxContext.openOnFocus,
|
|
41
|
+
optionsRef = _useComboBoxContext.optionsRef,
|
|
42
|
+
labelIdRef = _useComboBoxContext.labelIdRef; // Keep focus on the input component
|
|
27
43
|
|
|
28
|
-
const {
|
|
29
|
-
data: {
|
|
30
|
-
navigationItem,
|
|
31
|
-
text,
|
|
32
|
-
lastActionType
|
|
33
|
-
},
|
|
34
|
-
inputRef,
|
|
35
|
-
state,
|
|
36
|
-
transition,
|
|
37
|
-
listboxIdRef,
|
|
38
|
-
autocompletePropRef,
|
|
39
|
-
clearOnEscapeRef,
|
|
40
|
-
openOnFocus,
|
|
41
|
-
optionsRef,
|
|
42
|
-
labelIdRef
|
|
43
|
-
} = useComboBoxContext(); // Keep focus on the input component
|
|
44
44
|
|
|
45
45
|
useFocusManagement(lastActionType, inputRef); // Keep using the defaultValue until the user started interacting
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
var hasStartedInteracting = useRef(false); // Because we close the List on blur, we need to track if the blur is
|
|
48
48
|
// caused by clicking inside the list, and if so, don't close the List.
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
var selectOnClickRef = useRef(false);
|
|
51
|
+
var handleBlur = useBlur(); // Update ref props
|
|
52
52
|
|
|
53
53
|
autocompletePropRef.current = autocomplete;
|
|
54
54
|
clearOnEscapeRef.current = clearOnEscape;
|
|
@@ -56,23 +56,23 @@ export const ComboboxInput = /*#__PURE__*/forwardRef(function ComboboxInput(_ref
|
|
|
56
56
|
// types, instead the developer controls it with the normal input onChange
|
|
57
57
|
// prop
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
var handleChange = function handleChange(e) {
|
|
60
60
|
// After the user started typing, lets forget the defaultValue
|
|
61
61
|
hasStartedInteracting.current = true;
|
|
62
|
-
|
|
62
|
+
var text = e.target.value;
|
|
63
63
|
|
|
64
64
|
if (text.trim() === '') {
|
|
65
65
|
transition(CLEAR);
|
|
66
66
|
} else {
|
|
67
67
|
transition(CHANGE, {
|
|
68
|
-
text
|
|
68
|
+
text: text
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
var handleKeyDown = useKeyDown();
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
var handleFocus = function handleFocus() {
|
|
76
76
|
if (selectOnClick) {
|
|
77
77
|
selectOnClickRef.current = true;
|
|
78
78
|
} // If we select an option with click, useFocusManagement will focus the
|
|
@@ -87,22 +87,24 @@ export const ComboboxInput = /*#__PURE__*/forwardRef(function ComboboxInput(_ref
|
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
var handleClick = function handleClick() {
|
|
91
91
|
if (selectOnClickRef.current) {
|
|
92
92
|
selectOnClickRef.current = false;
|
|
93
93
|
inputRef.current && inputRef.current.select();
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
var navigationText = navigationItem !== '' ? optionsRef.current[navigationItem].text : undefined;
|
|
98
|
+
var fallbackValue = hasStartedInteracting.current ? '' : defaultValue;
|
|
99
|
+
var inputStrings = // When idle, we don't have a navigationText on ArrowUp/Down
|
|
100
100
|
autocomplete && state === NAVIGATING ? [navigationText, controlledValue, text, fallbackValue] : [controlledValue, text, fallbackValue];
|
|
101
|
-
|
|
101
|
+
var inputValue = inputStrings.find(function (str) {
|
|
102
|
+
return str !== undefined;
|
|
103
|
+
}); // If they are controlling the value we still need to do our transitions, so
|
|
102
104
|
// we have this derived state to emulate onChange of the input as we receive
|
|
103
105
|
// new `value`s ...[*]
|
|
104
106
|
|
|
105
|
-
useEffect(()
|
|
107
|
+
useEffect(function () {
|
|
106
108
|
transition(INIT, {
|
|
107
109
|
text: inputValue,
|
|
108
110
|
item: ''
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ComboBox/ComboboxInput.tsx"],"names":["forwardRef","useEffect","useRef","useBlur","CLEAR","CHANGE","useKeyDown","SELECT_WITH_CLICK","FOCUS","NAVIGATING","INIT","useFocusManagement","assignMultipleRefs","wrapEvent","useComboBoxContext","ComboboxInput","forwardedRef","as","Comp","innerAs","selectOnClick","autocomplete","clearOnEscape","onClick","onChange","onKeyDown","onBlur","onFocus","id","preferredId","defaultValue","value","controlledValue","props","data","navigationItem","text","lastActionType","inputRef","state","transition","listboxIdRef","autocompletePropRef","clearOnEscapeRef","openOnFocus","optionsRef","labelIdRef","hasStartedInteracting","selectOnClickRef","handleBlur","current","handleChange","e","target","trim","handleKeyDown","handleFocus","item","handleClick","select","navigationText","undefined","fallbackValue","inputStrings","inputValue","find","str"],"mappings":";;AAAA,SAASA,UAAT,EAAqBC,SAArB,EAAgCC,MAAhC,QAA8C,OAA9C;AAEA,SACEC,OADF,EAEEC,KAFF,EAGEC,MAHF,EAIEC,UAJF,EAKEC,iBALF,EAMEC,KANF,EAOEC,UAPF,EAQEC,IARF,EASEC,kBATF,QAUO,SAVP;AAWA,SAASC,kBAAT,EAA6BC,SAA7B,QAA8C,UAA9C;AACA,SAASC,kBAAT,QAAmC,WAAnC;;AAwBA,OAAO,MAAMC,aAAa,gBAAGf,UAAU,CACrC,SAASe,aAAT,OAuBEC,YAvBF,EAwBE;AAAA,MAvBA;AACEC,IAAAA,EAAE,EAAEC,IAAI,GAAG,OADb;AAEEC,IAAAA,OAFF;AAGEC,IAAAA,aAAa,GAAG,KAHlB;AAIEC,IAAAA,YAAY,GAAG,IAJjB;AAKEC,IAAAA,aAAa,GAAG,KALlB;AAOE;AACAC,IAAAA,OARF;AASEC,IAAAA,QATF;AAUEC,IAAAA,SAVF;AAWEC,IAAAA,MAXF;AAYEC,IAAAA,OAZF;AAcEC,IAAAA,EAAE,EAAEC,WAdN;AAgBEC,IAAAA,YAAY,GAAG,EAhBjB;AAkBE;AACAC,IAAAA,KAAK,EAAEC;AAnBT,GAuBA;AAAA,MAHKC,KAGL;;AACA,QAAM;AACJC,IAAAA,IAAI,EAAE;AAAEC,MAAAA,cAAF;AAAkBC,MAAAA,IAAlB;AAAwBC,MAAAA;AAAxB,KADF;AAEJC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WtB,YAAX,CAJzB;AAKE,IAAA,KAAK,EAAEgD,UALT;AAME,IAAA,OAAO,EAAEnD,SAAS,CAACU,OAAD,EAAUmC,WAAV,CANpB;AAOE,IAAA,MAAM,EAAE7C,SAAS,CAACa,MAAD,EAASuB,UAAT,CAPnB;AAQE,IAAA,OAAO,EAAEpC,SAAS,CAACc,OAAD,EAAU6B,WAAV,CARpB;AASE,IAAA,QAAQ,EAAE3C,SAAS,CAACW,QAAD,EAAW2B,YAAX,CATrB;AAUE,IAAA,SAAS,EAAEtC,SAAS,CAACY,SAAD,EAAY8B,aAAZ,CAVtB;AAWE,uBAAiBT,UAAU,CAACI,OAX9B;AAYE,IAAA,EAAE,EAAET,YAAY,CAACS,OAZnB;AAaE,yBAAkB,MAbpB;AAcE,6BACEf,cAAc,KAAK,EAAnB,GAAwBA,cAAxB,GAAyC0B,SAf7C;AAiBE,IAAA,YAAY,EAAC;AAjBf,KADF;AAqBD,CA1IoC,CAAhC","sourcesContent":["import { forwardRef, useEffect, useRef } from 'react';\nimport type * as React from 'react';\nimport {\n useBlur,\n CLEAR,\n CHANGE,\n useKeyDown,\n SELECT_WITH_CLICK,\n FOCUS,\n NAVIGATING,\n INIT,\n useFocusManagement,\n} from './hooks';\nimport { assignMultipleRefs, wrapEvent } from '../utils';\nimport { useComboBoxContext } from './context';\n\nexport interface ComboboxInputProps\n extends React.InputHTMLAttributes<HTMLInputElement> {\n // clear on ESC\n clearOnEscape?: boolean;\n // highlights all the text in the box on click when true\n selectOnClick?: boolean;\n // updates the value in the input when navigating w/ the keyboard\n autocomplete?: boolean;\n // initial value for uncontrolled mode\n defaultValue?: string;\n // value for controlled mode\n value?: string;\n onClick?: React.MouseEventHandler<HTMLInputElement>;\n onChange?: React.ChangeEventHandler<HTMLInputElement>;\n onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;\n onBlur?: React.FocusEventHandler<HTMLInputElement>;\n onFocus?: React.FocusEventHandler<HTMLInputElement>;\n as?: React.ElementType<any>;\n innerAs?: React.ElementType<any>;\n id?: string;\n}\n\nexport const ComboboxInput = forwardRef<HTMLInputElement, ComboboxInputProps>(\n function ComboboxInput(\n {\n as: Comp = 'input',\n innerAs,\n selectOnClick = false,\n autocomplete = true,\n clearOnEscape = false,\n\n // wrapped events\n onClick,\n onChange,\n onKeyDown,\n onBlur,\n onFocus,\n\n id: preferredId,\n\n defaultValue = '',\n\n // might be controlled\n value: controlledValue,\n ...props\n },\n forwardedRef\n ) {\n const {\n data: { navigationItem, text, lastActionType },\n inputRef,\n state,\n transition,\n listboxIdRef,\n autocompletePropRef,\n clearOnEscapeRef,\n openOnFocus,\n optionsRef,\n labelIdRef,\n } = useComboBoxContext();\n\n // Keep focus on the input component\n useFocusManagement(lastActionType, inputRef);\n\n // Keep using the defaultValue until the user started interacting\n const hasStartedInteracting = useRef(false);\n\n // Because we close the List on blur, we need to track if the blur is\n // caused by clicking inside the list, and if so, don't close the List.\n const selectOnClickRef = useRef(false);\n\n const handleBlur = useBlur();\n\n // Update ref props\n autocompletePropRef.current = autocomplete;\n clearOnEscapeRef.current = clearOnEscape;\n listboxIdRef.current = preferredId || listboxIdRef.current;\n\n // [*]... and when controlled, we don't trigger handleValueChange as the user\n // types, instead the developer controls it with the normal input onChange\n // prop\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n // After the user started typing, lets forget the defaultValue\n hasStartedInteracting.current = true;\n\n const text = e.target.value;\n if (text.trim() === '') {\n transition(CLEAR);\n } else {\n transition(CHANGE, { text });\n }\n };\n\n const handleKeyDown = useKeyDown();\n\n const handleFocus = () => {\n if (selectOnClick) {\n selectOnClickRef.current = true;\n }\n // If we select an option with click, useFocusManagement will focus the\n // input, in those cases we don't want to cause the menu to open back up,\n // so we guard behind these states\n if (openOnFocus && lastActionType !== SELECT_WITH_CLICK) {\n transition(FOCUS, {\n item: navigationItem,\n });\n }\n };\n\n const handleClick = () => {\n if (selectOnClickRef.current) {\n selectOnClickRef.current = false;\n inputRef.current && inputRef.current.select();\n }\n };\n\n const navigationText =\n navigationItem !== ''\n ? optionsRef.current[navigationItem].text\n : undefined;\n\n const fallbackValue = hasStartedInteracting.current ? '' : defaultValue;\n\n const inputStrings =\n // When idle, we don't have a navigationText on ArrowUp/Down\n autocomplete && state === NAVIGATING\n ? [navigationText, controlledValue, text, fallbackValue]\n : [controlledValue, text, fallbackValue];\n\n const inputValue = inputStrings.find((str) => str !== undefined);\n\n // If they are controlling the value we still need to do our transitions, so\n // we have this derived state to emulate onChange of the input as we receive\n // new `value`s ...[*]\n useEffect(() => {\n transition(INIT, { text: inputValue, item: '' });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <Comp\n {...props}\n as={innerAs}\n data-reach-combobox-input=\"\"\n ref={assignMultipleRefs(inputRef, forwardedRef)}\n value={inputValue}\n onClick={wrapEvent(onClick, handleClick)}\n onBlur={wrapEvent(onBlur, handleBlur)}\n onFocus={wrapEvent(onFocus, handleFocus)}\n onChange={wrapEvent(onChange, handleChange)}\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n aria-labelledby={labelIdRef.current}\n id={listboxIdRef.current}\n aria-autocomplete=\"both\"\n aria-activedescendant={\n navigationItem !== '' ? navigationItem : undefined\n }\n autoComplete=\"off\"\n />\n );\n }\n);\n"],"file":"ComboboxInput.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/ComboBox/ComboboxInput.tsx"],"names":["forwardRef","useEffect","useRef","useBlur","CLEAR","CHANGE","useKeyDown","SELECT_WITH_CLICK","FOCUS","NAVIGATING","INIT","useFocusManagement","assignMultipleRefs","wrapEvent","useComboBoxContext","ComboboxInput","forwardedRef","as","Comp","innerAs","selectOnClick","autocomplete","clearOnEscape","onClick","onChange","onKeyDown","onBlur","onFocus","preferredId","id","defaultValue","controlledValue","value","props","data","navigationItem","text","lastActionType","inputRef","state","transition","listboxIdRef","autocompletePropRef","clearOnEscapeRef","openOnFocus","optionsRef","labelIdRef","hasStartedInteracting","selectOnClickRef","handleBlur","current","handleChange","e","target","trim","handleKeyDown","handleFocus","item","handleClick","select","navigationText","undefined","fallbackValue","inputStrings","inputValue","find","str"],"mappings":";;AASA,SAASA,UAAT,EAAqBC,SAArB,EAAgCC,MAAhC,QAA8C,OAA9C;AAEA,SACEC,OADF,EAEEC,KAFF,EAGEC,MAHF,EAIEC,UAJF,EAKEC,iBALF,EAMEC,KANF,EAOEC,UAPF,EAQEC,IARF,EASEC,kBATF,QAUO,SAVP;AAWA,SAASC,kBAAT,EAA6BC,SAA7B,QAA8C,UAA9C;AACA,SAASC,kBAAT,QAAmC,WAAnC;;AAwBA,OAAO,IAAMC,aAAa,gBAAGf,UAAU,CACrC,SAASe,aAAT,OAuBEC,YAvBF,EAwBE;AAAA,qBAtBEC,EAsBF;AAAA,MAtBMC,IAsBN,wBAtBa,OAsBb;AAAA,MArBEC,OAqBF,QArBEA,OAqBF;AAAA,gCApBEC,aAoBF;AAAA,MApBEA,aAoBF,mCApBkB,KAoBlB;AAAA,+BAnBEC,YAmBF;AAAA,MAnBEA,YAmBF,kCAnBiB,IAmBjB;AAAA,gCAlBEC,aAkBF;AAAA,MAlBEA,aAkBF,mCAlBkB,KAkBlB;AAAA,MAfEC,OAeF,QAfEA,OAeF;AAAA,MAdEC,QAcF,QAdEA,QAcF;AAAA,MAbEC,SAaF,QAbEA,SAaF;AAAA,MAZEC,MAYF,QAZEA,MAYF;AAAA,MAXEC,OAWF,QAXEA,OAWF;AAAA,MATMC,WASN,QATEC,EASF;AAAA,+BAPEC,YAOF;AAAA,MAPEA,YAOF,kCAPiB,EAOjB;AAAA,MAJSC,eAIT,QAJEC,KAIF;AAAA,MAHKC,KAGL;;AAAA,4BAYInB,kBAAkB,EAZtB;AAAA,kDAEEoB,IAFF;AAAA,MAEUC,cAFV,yBAEUA,cAFV;AAAA,MAE0BC,IAF1B,yBAE0BA,IAF1B;AAAA,MAEgCC,cAFhC,yBAEgCA,cAFhC;AAAA,MAGEC,QAHF,uBAGEA,QAHF;AAA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A,sBACE,KAAC,IAAD,eACMxB,KADN;AAEE,IAAA,EAAE,EAAEd,OAFN;AAGE,iCAA0B,EAH5B;AAIE,IAAA,GAAG,EAAEP,kBAAkB,CAAC0B,QAAD,EAAWtB,YAAX,CAJzB;AAKE,IAAA,KAAK,EAAEgD,UALT;AAME,IAAA,OAAO,EAAEnD,SAAS,CAACU,OAAD,EAAUmC,WAAV,CANpB;AAOE,IAAA,MAAM,EAAE7C,SAAS,CAACa,MAAD,EAASuB,UAAT,CAPnB;AAQE,IAAA,OAAO,EAAEpC,SAAS,CAACc,OAAD,EAAU6B,WAAV,CARpB;AASE,IAAA,QAAQ,EAAE3C,SAAS,CAACW,QAAD,EAAW2B,YAAX,CATrB;AAUE,IAAA,SAAS,EAAEtC,SAAS,CAACY,SAAD,EAAY8B,aAAZ,CAVtB;AAWE,uBAAiBT,UAAU,CAACI,OAX9B;AAYE,IAAA,EAAE,EAAET,YAAY,CAACS,OAZnB;AAaE,yBAAkB,MAbpB;AAcE,6BACEf,cAAc,KAAK,EAAnB,GAAwBA,cAAxB,GAAyC0B,SAf7C;AAiBE,IAAA,YAAY,EAAC;AAjBf,KADF;AAqBD,CA1IoC,CAAhC","sourcesContent":["import type {\n ChangeEvent,\n ChangeEventHandler,\n ElementType,\n FocusEventHandler,\n InputHTMLAttributes,\n KeyboardEventHandler,\n MouseEventHandler,\n} from 'react';\nimport { forwardRef, useEffect, useRef } from 'react';\n\nimport {\n useBlur,\n CLEAR,\n CHANGE,\n useKeyDown,\n SELECT_WITH_CLICK,\n FOCUS,\n NAVIGATING,\n INIT,\n useFocusManagement,\n} from './hooks';\nimport { assignMultipleRefs, wrapEvent } from '../utils';\nimport { useComboBoxContext } from './context';\n\nexport interface ComboboxInputProps\n extends InputHTMLAttributes<HTMLInputElement> {\n // clear on ESC\n clearOnEscape?: boolean;\n // highlights all the text in the box on click when true\n selectOnClick?: boolean;\n // updates the value in the input when navigating w/ the keyboard\n autocomplete?: boolean;\n // initial value for uncontrolled mode\n defaultValue?: string;\n // value for controlled mode\n value?: string;\n onClick?: MouseEventHandler<HTMLInputElement>;\n onChange?: ChangeEventHandler<HTMLInputElement>;\n onKeyDown?: KeyboardEventHandler<HTMLInputElement>;\n onBlur?: FocusEventHandler<HTMLInputElement>;\n onFocus?: FocusEventHandler<HTMLInputElement>;\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n id?: string;\n}\n\nexport const ComboboxInput = forwardRef<HTMLInputElement, ComboboxInputProps>(\n function ComboboxInput(\n {\n as: Comp = 'input',\n innerAs,\n selectOnClick = false,\n autocomplete = true,\n clearOnEscape = false,\n\n // wrapped events\n onClick,\n onChange,\n onKeyDown,\n onBlur,\n onFocus,\n\n id: preferredId,\n\n defaultValue = '',\n\n // might be controlled\n value: controlledValue,\n ...props\n },\n forwardedRef\n ) {\n const {\n data: { navigationItem, text, lastActionType },\n inputRef,\n state,\n transition,\n listboxIdRef,\n autocompletePropRef,\n clearOnEscapeRef,\n openOnFocus,\n optionsRef,\n labelIdRef,\n } = useComboBoxContext();\n\n // Keep focus on the input component\n useFocusManagement(lastActionType, inputRef);\n\n // Keep using the defaultValue until the user started interacting\n const hasStartedInteracting = useRef(false);\n\n // Because we close the List on blur, we need to track if the blur is\n // caused by clicking inside the list, and if so, don't close the List.\n const selectOnClickRef = useRef(false);\n\n const handleBlur = useBlur();\n\n // Update ref props\n autocompletePropRef.current = autocomplete;\n clearOnEscapeRef.current = clearOnEscape;\n listboxIdRef.current = preferredId || listboxIdRef.current;\n\n // [*]... and when controlled, we don't trigger handleValueChange as the user\n // types, instead the developer controls it with the normal input onChange\n // prop\n const handleChange = (e: ChangeEvent<HTMLInputElement>) => {\n // After the user started typing, lets forget the defaultValue\n hasStartedInteracting.current = true;\n\n const text = e.target.value;\n if (text.trim() === '') {\n transition(CLEAR);\n } else {\n transition(CHANGE, { text });\n }\n };\n\n const handleKeyDown = useKeyDown();\n\n const handleFocus = () => {\n if (selectOnClick) {\n selectOnClickRef.current = true;\n }\n // If we select an option with click, useFocusManagement will focus the\n // input, in those cases we don't want to cause the menu to open back up,\n // so we guard behind these states\n if (openOnFocus && lastActionType !== SELECT_WITH_CLICK) {\n transition(FOCUS, {\n item: navigationItem,\n });\n }\n };\n\n const handleClick = () => {\n if (selectOnClickRef.current) {\n selectOnClickRef.current = false;\n inputRef.current && inputRef.current.select();\n }\n };\n\n const navigationText =\n navigationItem !== ''\n ? optionsRef.current[navigationItem].text\n : undefined;\n\n const fallbackValue = hasStartedInteracting.current ? '' : defaultValue;\n\n const inputStrings =\n // When idle, we don't have a navigationText on ArrowUp/Down\n autocomplete && state === NAVIGATING\n ? [navigationText, controlledValue, text, fallbackValue]\n : [controlledValue, text, fallbackValue];\n\n const inputValue = inputStrings.find((str) => str !== undefined);\n\n // If they are controlling the value we still need to do our transitions, so\n // we have this derived state to emulate onChange of the input as we receive\n // new `value`s ...[*]\n useEffect(() => {\n transition(INIT, { text: inputValue, item: '' });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <Comp\n {...props}\n as={innerAs}\n data-reach-combobox-input=\"\"\n ref={assignMultipleRefs(inputRef, forwardedRef)}\n value={inputValue}\n onClick={wrapEvent(onClick, handleClick)}\n onBlur={wrapEvent(onBlur, handleBlur)}\n onFocus={wrapEvent(onFocus, handleFocus)}\n onChange={wrapEvent(onChange, handleChange)}\n onKeyDown={wrapEvent(onKeyDown, handleKeyDown)}\n aria-labelledby={labelIdRef.current}\n id={listboxIdRef.current}\n aria-autocomplete=\"both\"\n aria-activedescendant={\n navigationItem !== '' ? navigationItem : undefined\n }\n autoComplete=\"off\"\n />\n );\n }\n);\n"],"file":"ComboboxInput.js"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export interface ComboboxLabelProps extends
|
|
3
|
-
as?:
|
|
4
|
-
innerAs?:
|
|
1
|
+
import type { ElementType, LabelHTMLAttributes } from 'react';
|
|
2
|
+
export interface ComboboxLabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
|
|
3
|
+
as?: ElementType<any>;
|
|
4
|
+
innerAs?: ElementType<any>;
|
|
5
5
|
id?: string;
|
|
6
6
|
}
|
|
7
|
-
export declare const ComboboxLabel:
|
|
7
|
+
export declare const ComboboxLabel: import("react").ForwardRefExoticComponent<ComboboxLabelProps & import("react").RefAttributes<HTMLLabelElement>>;
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
import { forwardRef } from 'react';
|
|
4
4
|
import { useComboBoxContext } from './context';
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
export var ComboboxLabel = /*#__PURE__*/forwardRef(function ComboboxButton(_ref, ref) {
|
|
7
|
+
var _ref$as = _ref.as,
|
|
8
|
+
Comp = _ref$as === void 0 ? 'label' : _ref$as,
|
|
9
|
+
innerAs = _ref.innerAs,
|
|
10
|
+
preferredId = _ref.id,
|
|
11
|
+
props = _objectWithoutProperties(_ref, ["as", "innerAs", "id"]);
|
|
12
|
+
|
|
13
|
+
var _useComboBoxContext = useComboBoxContext(),
|
|
14
|
+
listboxIdRef = _useComboBoxContext.listboxIdRef,
|
|
15
|
+
labelIdRef = _useComboBoxContext.labelIdRef;
|
|
13
16
|
|
|
14
|
-
const {
|
|
15
|
-
listboxIdRef,
|
|
16
|
-
labelIdRef
|
|
17
|
-
} = useComboBoxContext();
|
|
18
17
|
labelIdRef.current = preferredId || labelIdRef.current;
|
|
19
18
|
return /*#__PURE__*/_jsx(Comp, _extends({
|
|
20
19
|
as: innerAs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/ComboBox/ComboboxLabel.tsx"],"names":["forwardRef","useComboBoxContext","ComboboxLabel","ComboboxButton","ref","as","Comp","innerAs","
|
|
1
|
+
{"version":3,"sources":["../../../src/ComboBox/ComboboxLabel.tsx"],"names":["forwardRef","useComboBoxContext","ComboboxLabel","ComboboxButton","ref","as","Comp","innerAs","preferredId","id","props","listboxIdRef","labelIdRef","current"],"mappings":";;AACA,SAASA,UAAT,QAA2B,OAA3B;AAEA,SAASC,kBAAT,QAAmC,WAAnC;;AASA,OAAO,IAAMC,aAAa,gBAAGF,UAAU,CACrC,SAASG,cAAT,OAEEC,GAFF,EAGE;AAAA,qBAFEC,EAEF;AAAA,MAFMC,IAEN,wBAFa,OAEb;AAAA,MAFsBC,OAEtB,QAFsBA,OAEtB;AAAA,MAFmCC,WAEnC,QAF+BC,EAE/B;AAAA,MAFmDC,KAEnD;;AAAA,4BACqCT,kBAAkB,EADvD;AAAA,MACQU,YADR,uBACQA,YADR;AAAA,MACsBC,UADtB,uBACsBA,UADtB;;AAGAA,EAAAA,UAAU,CAACC,OAAX,GAAqBL,WAAW,IAAII,UAAU,CAACC,OAA/C;AAEA,sBACE,KAAC,IAAD;AACE,IAAA,EAAE,EAAEN,OADN;AAEE,iCAA0B,EAF5B;AAGE,IAAA,OAAO,EAAEI,YAAY,CAACE,OAHxB;AAIE,IAAA,EAAE,EAAED,UAAU,CAACC,OAJjB;AAKE,IAAA,GAAG,EAAET;AALP,KAMMM,KANN,EADF;AAUD,CAnBoC,CAAhC","sourcesContent":["import type { ElementType, LabelHTMLAttributes } from 'react';\nimport { forwardRef } from 'react';\n\nimport { useComboBoxContext } from './context';\n\nexport interface ComboboxLabelProps\n extends LabelHTMLAttributes<HTMLLabelElement> {\n as?: ElementType<any>;\n innerAs?: ElementType<any>;\n id?: string;\n}\n\nexport const ComboboxLabel = forwardRef<HTMLLabelElement, ComboboxLabelProps>(\n function ComboboxButton(\n { as: Comp = 'label', innerAs, id: preferredId, ...props },\n ref\n ) {\n const { listboxIdRef, labelIdRef } = useComboBoxContext();\n\n labelIdRef.current = preferredId || labelIdRef.current;\n\n return (\n <Comp\n as={innerAs}\n data-reach-combobox-label=\"\"\n htmlFor={listboxIdRef.current}\n id={labelIdRef.current}\n ref={ref}\n {...props}\n />\n );\n }\n);\n"],"file":"ComboboxLabel.js"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export interface ComboboxListProps extends
|
|
3
|
-
as?:
|
|
4
|
-
innerAs?:
|
|
1
|
+
import type { HTMLAttributes, ElementType, ReactNode } from 'react';
|
|
2
|
+
export interface ComboboxListProps extends HTMLAttributes<HTMLUListElement> {
|
|
3
|
+
as?: ElementType<any>;
|
|
4
|
+
innerAs?: ElementType<any>;
|
|
5
5
|
persistSelection?: boolean;
|
|
6
|
-
children?:
|
|
6
|
+
children?: ReactNode;
|
|
7
7
|
}
|
|
8
|
-
export declare const ComboboxList:
|
|
8
|
+
export declare const ComboboxList: import("react").ForwardRefExoticComponent<ComboboxListProps & import("react").RefAttributes<HTMLUListElement>>;
|