@fluentui/react-combobox 9.17.7 → 9.17.8
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/CHANGELOG.md +19 -2
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/lib/components/Combobox/useCombobox.js +57 -35
- package/lib/components/Combobox/useCombobox.js.map +1 -1
- package/lib/components/Combobox/useComboboxExpandIconSlot.js +40 -0
- package/lib/components/Combobox/useComboboxExpandIconSlot.js.map +1 -0
- package/lib/components/Combobox/useInputTriggerSlot.js +3 -2
- package/lib/components/Combobox/useInputTriggerSlot.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/useComboboxBaseState.js +5 -4
- package/lib/utils/useComboboxBaseState.js.map +1 -1
- package/lib/utils/useTriggerSlot.js +6 -3
- package/lib/utils/useTriggerSlot.js.map +1 -1
- package/lib-commonjs/components/Combobox/useCombobox.cjs +54 -34
- package/lib-commonjs/components/Combobox/useCombobox.cjs.map +1 -1
- package/lib-commonjs/components/Combobox/useComboboxExpandIconSlot.cjs +46 -0
- package/lib-commonjs/components/Combobox/useComboboxExpandIconSlot.cjs.map +1 -0
- package/lib-commonjs/components/Combobox/useInputTriggerSlot.cjs +3 -2
- package/lib-commonjs/components/Combobox/useInputTriggerSlot.cjs.map +1 -1
- package/lib-commonjs/index.cjs +4 -0
- package/lib-commonjs/index.cjs.map +1 -1
- package/lib-commonjs/utils/useComboboxBaseState.cjs +5 -4
- package/lib-commonjs/utils/useComboboxBaseState.cjs.map +1 -1
- package/lib-commonjs/utils/useTriggerSlot.cjs +6 -3
- package/lib-commonjs/utils/useTriggerSlot.cjs.map +1 -1
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/useComboboxBaseState.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport * as ReactDOM from 'react-dom';\nimport { useControllableState, useEventCallback, useFirstMount } from '@fluentui/react-utilities';\nimport type { ActiveDescendantChangeEvent, ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { useOptionCollection } from '../utils/useOptionCollection';\nimport type { OptionValue } from '../utils/OptionCollection.types';\nimport { useSelection } from '../utils/useSelection';\nimport type { ComboboxBaseProps, ComboboxBaseOpenEvents, ComboboxBaseState } from './ComboboxBase.types';\nimport type { SelectionEvents } from './Selection.types';\n\n/**\n * State shared between Combobox and Dropdown components\n *\n * @internal\n */\nexport const useComboboxBaseState = (\n props: ComboboxBaseProps & {\n children?: React.ReactNode;\n editable?: boolean;\n disabled?: boolean;\n freeform?: boolean;\n activeDescendantController: ActiveDescendantImperativeRef;\n },\n): ComboboxBaseState => {\n const {\n appearance = 'outline',\n disableAutoFocus,\n children,\n clearable = false,\n editable = false,\n inlinePopup = false,\n mountNode = undefined,\n multiselect,\n onOpenChange,\n size = 'medium',\n activeDescendantController,\n freeform = false,\n disabled = false,\n onActiveOptionChange = null,\n } = props;\n\n const optionCollection = useOptionCollection();\n const { getOptionsMatchingValue } = optionCollection;\n\n const { getOptionById } = optionCollection;\n const getActiveOption = React.useCallback(() => {\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [activeDescendantController, getOptionById]);\n\n // Keeping some kind of backwards compatible functionality here\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const UNSAFE_activeOption = getActiveOption();\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const UNSAFE_setActiveOption = React.useCallback(\n (option: OptionValue | undefined | ((prev: OptionValue | undefined) => OptionValue | undefined)) => {\n let nextOption: OptionValue | undefined = undefined;\n if (typeof option === 'function') {\n const activeOption = getActiveOption();\n nextOption = option(activeOption);\n }\n\n if (nextOption) {\n activeDescendantController.focus(nextOption.id);\n } else {\n activeDescendantController.blur();\n }\n },\n [activeDescendantController, getActiveOption],\n );\n\n // track whether keyboard focus outline should be shown\n // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move\n const [focusVisible, setFocusVisible] = React.useState(false);\n\n // track focused state to conditionally render collapsed listbox\n // when the trigger is focused - the listbox should but hidden until the open state is changed\n const [hasFocus, setHasFocus] = React.useState(false);\n\n const ignoreNextBlur = React.useRef(false);\n\n // calculate value based on props, internal value changes, and selected options\n const isFirstMount = useFirstMount();\n const [controllableValue, setValue] = useControllableState({\n state: props.value,\n initialState: undefined,\n });\n\n const { selectedOptions, selectOption: baseSelectOption, clearSelection } = useSelection(props);\n\n // reset any typed value when an option is selected\n const selectOption = React.useCallback(\n (ev: SelectionEvents, option: OptionValue) => {\n ReactDOM.unstable_batchedUpdates(() => {\n setValue(undefined);\n baseSelectOption(ev, option);\n });\n },\n [setValue, baseSelectOption],\n );\n\n const value = React.useMemo(() => {\n // don't compute the value if it is defined through props or setValue,\n if (controllableValue !== undefined) {\n return controllableValue;\n }\n\n // handle defaultValue here, so it is overridden by selection\n if (isFirstMount && props.defaultValue !== undefined) {\n return props.defaultValue;\n }\n\n const selectedOptionsText = getOptionsMatchingValue(optionValue => {\n return selectedOptions.includes(optionValue);\n }).map(option => option.text);\n\n if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptionsText.join(', ');\n }\n\n return selectedOptionsText[0];\n\n // do not change value after isFirstMount changes,\n // we do not want to accidentally override defaultValue on a second render\n // unless another value is intentionally set\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [controllableValue, editable, getOptionsMatchingValue, multiselect, selectedOptions]);\n\n // Handle open state, which is shared with options in context\n const [open, setOpenState] = useControllableState({\n state: props.open,\n defaultState: props.defaultOpen,\n initialState: false,\n });\n\n const setOpen = React.useCallback(\n (event: ComboboxBaseOpenEvents, newState: boolean) => {\n if (disabled) {\n return;\n }\n onOpenChange?.(event, { open: newState });\n ReactDOM.unstable_batchedUpdates(() => {\n if (!newState && !freeform) {\n setValue(undefined);\n }\n setOpenState(newState);\n });\n },\n [onOpenChange, setOpenState, setValue, freeform, disabled],\n );\n\n // update active option based on change in open state\n React.useEffect(() => {\n if (open) {\n // if it is single-select and there is a selected option, start at the selected option\n if (!multiselect && selectedOptions.length > 0) {\n const selectedOption = getOptionsMatchingValue(v => v === selectedOptions[0]).pop();\n if (selectedOption?.id) {\n activeDescendantController.focus(selectedOption.id);\n }\n }\n } else {\n activeDescendantController.blur();\n }\n // this should only be run in response to changes in the open state\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open, activeDescendantController]);\n\n // Fallback focus when children are updated in an open popover results in no item being focused\n React.useEffect(() => {\n if (open && !disableAutoFocus && !activeDescendantController.active()) {\n activeDescendantController.first();\n }\n // this should only be run in response to changes in the open state or children\n }, [open, children, disableAutoFocus, activeDescendantController, getOptionById]);\n\n const onActiveDescendantChange = useEventCallback((event: ActiveDescendantChangeEvent) => {\n const previousOption = event.detail.previousId ? optionCollection.getOptionById(event.detail.previousId) : null;\n const nextOption = optionCollection.getOptionById(event.detail.id);\n onActiveOptionChange?.(event, { event, type: 'change', previousOption, nextOption });\n });\n\n return {\n ...optionCollection,\n freeform,\n disabled,\n selectOption,\n clearSelection,\n selectedOptions,\n activeOption: UNSAFE_activeOption,\n appearance,\n clearable,\n focusVisible,\n ignoreNextBlur,\n inlinePopup,\n mountNode,\n open,\n hasFocus,\n setActiveOption: UNSAFE_setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n setValue,\n size,\n value,\n multiselect,\n onOptionClick: useEventCallback((e: React.MouseEvent<HTMLElement>) => {\n if (!multiselect) {\n setOpen(e, false);\n }\n }),\n onActiveDescendantChange,\n };\n};\n"],"names":["React","ReactDOM","useControllableState","useEventCallback","useFirstMount","useOptionCollection","useSelection","useComboboxBaseState","props","appearance","disableAutoFocus","children","clearable","editable","inlinePopup","mountNode","undefined","multiselect","onOpenChange","size","activeDescendantController","freeform","disabled","onActiveOptionChange","optionCollection","getOptionsMatchingValue","getOptionById","getActiveOption","useCallback","activeOptionId","active","UNSAFE_activeOption","UNSAFE_setActiveOption","option","nextOption","activeOption","focus","id","blur","focusVisible","setFocusVisible","useState","hasFocus","setHasFocus","ignoreNextBlur","useRef","isFirstMount","controllableValue","setValue","state","value","initialState","selectedOptions","selectOption","baseSelectOption","clearSelection","ev","unstable_batchedUpdates","useMemo","defaultValue","selectedOptionsText","optionValue","includes","map","text","join","open","setOpenState","defaultState","defaultOpen","setOpen","event","newState","useEffect","length","selectedOption","v","pop","first","onActiveDescendantChange","previousOption","detail","previousId","type","setActiveOption","onOptionClick","e"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,YAAYC,cAAc,YAAY;AACtC,SAASC,oBAAoB,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAElG,SAASC,mBAAmB,QAAQ,2BAA+B;AAEnE,SAASC,YAAY,QAAQ,oBAAwB;AAIrD;;;;CAIC,GACD,OAAO,MAAMC,uBAAuB,CAClCC;IAQA,MAAM,EACJC,aAAa,SAAS,EACtBC,gBAAgB,EAChBC,QAAQ,EACRC,YAAY,KAAK,EACjBC,WAAW,KAAK,EAChBC,cAAc,KAAK,EACnBC,YAAYC,SAAS,EACrBC,WAAW,EACXC,YAAY,EACZC,OAAO,QAAQ,EACfC,0BAA0B,EAC1BC,WAAW,KAAK,EAChBC,WAAW,KAAK,EAChBC,uBAAuB,IAAI,EAC5B,GAAGf;IAEJ,MAAMgB,mBAAmBnB;IACzB,MAAM,EAAEoB,uBAAuB,EAAE,GAAGD;IAEpC,MAAM,EAAEE,aAAa,EAAE,GAAGF;IAC1B,MAAMG,kBAAkB3B,MAAM4B,WAAW,CAAC;QACxC,MAAMC,iBAAiBT,2BAA2BU,MAAM;QACxD,OAAOD,iBAAiBH,cAAcG,kBAAkBb;IAC1D,GAAG;QAACI;QAA4BM;KAAc;IAE9C,+DAA+D;IAC/D,gEAAgE;IAChE,MAAMK,sBAAsBJ;IAC5B,gEAAgE;IAChE,MAAMK,yBAAyBhC,MAAM4B,WAAW,CAC9C,CAACK;QACC,IAAIC,aAAsClB;QAC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V,2BAA2B0D,KAAK;QAClC;IACA,+EAA+E;IACjF,GAAG;QAACZ;QAAMvD;QAAUD;QAAkBU;QAA4BM;KAAc;IAEhF,MAAMqD,2BAA2B5E,iBAAiB,CAACoE;QACjD,MAAMS,iBAAiBT,MAAMU,MAAM,CAACC,UAAU,GAAG1D,iBAAiBE,aAAa,CAAC6C,MAAMU,MAAM,CAACC,UAAU,IAAI;QAC3G,MAAMhD,aAAaV,iBAAiBE,aAAa,CAAC6C,MAAMU,MAAM,CAAC5C,EAAE;QACjEd,iCAAAA,2CAAAA,qBAAuBgD,OAAO;YAAEA;YAAOY,MAAM;YAAUH;YAAgB9C;QAAW;IACpF;IAEA,OAAO;QACL,GAAGV,gBAAgB;QACnBH;QACAC;QACA+B;QACAE;QACAH;QACAjB,cAAcJ;QACdtB;QACAG;QACA2B;QACAK;QACA9B;QACAC;QACAmD;QACAxB;QACA0C,iBAAiBpD;QACjBQ;QACAG;QACA2B;QACAtB;QACA7B;QACA+B;QACAjC;QACAoE,eAAelF,iBAAiB,CAACmF;YAC/B,IAAI,CAACrE,aAAa;gBAChBqD,QAAQgB,GAAG;YACb;QACF;QACAP;IACF;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../src/utils/useComboboxBaseState.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport * as ReactDOM from 'react-dom';\nimport { useControllableState, useEventCallback, useFirstMount } from '@fluentui/react-utilities';\nimport type { ActiveDescendantChangeEvent, ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { useOptionCollection } from '../utils/useOptionCollection';\nimport type { OptionValue } from '../utils/OptionCollection.types';\nimport { useSelection } from '../utils/useSelection';\nimport type { ComboboxBaseProps, ComboboxBaseOpenEvents, ComboboxBaseState } from './ComboboxBase.types';\nimport type { SelectionEvents } from './Selection.types';\n\n/**\n * State shared between Combobox and Dropdown components\n *\n * @internal\n */\nexport const useComboboxBaseState = (\n props: ComboboxBaseProps & {\n children?: React.ReactNode;\n editable?: boolean;\n disabled?: boolean;\n freeform?: boolean;\n activeDescendantController: ActiveDescendantImperativeRef;\n },\n): ComboboxBaseState => {\n const {\n appearance = 'outline',\n disableAutoFocus,\n children,\n clearable = false,\n editable = false,\n inlinePopup = false,\n mountNode = undefined,\n multiselect,\n onOpenChange,\n size = 'medium',\n activeDescendantController,\n freeform = false,\n disabled = false,\n onActiveOptionChange = null,\n } = props;\n\n const optionCollection = useOptionCollection();\n const { getOptionsMatchingValue } = optionCollection;\n\n const { getOptionById } = optionCollection;\n const getActiveOption = React.useCallback(() => {\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [activeDescendantController, getOptionById]);\n\n // Keeping some kind of backwards compatible functionality here\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const UNSAFE_activeOption = getActiveOption();\n // eslint-disable-next-line @typescript-eslint/naming-convention\n const UNSAFE_setActiveOption = React.useCallback(\n (option: OptionValue | undefined | ((prev: OptionValue | undefined) => OptionValue | undefined)) => {\n let nextOption: OptionValue | undefined = undefined;\n if (typeof option === 'function') {\n const activeOption = getActiveOption();\n nextOption = option(activeOption);\n }\n\n if (nextOption) {\n activeDescendantController.focus(nextOption.id);\n } else {\n activeDescendantController.blur();\n }\n },\n [activeDescendantController, getActiveOption],\n );\n\n // track whether keyboard focus outline should be shown\n // tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move\n const [focusVisible, setFocusVisible] = React.useState(false);\n\n // track focused state to conditionally render collapsed listbox\n // when the trigger is focused - the listbox should but hidden until the open state is changed\n const [hasFocus, setHasFocus] = React.useState(false);\n\n const ignoreNextBlur = React.useRef(false);\n\n // calculate value based on props, internal value changes, and selected options\n const isFirstMount = useFirstMount();\n const [controllableValue, setValue] = useControllableState({\n state: props.value,\n initialState: undefined,\n });\n\n const { selectedOptions, selectOption: baseSelectOption, clearSelection } = useSelection(props);\n\n // reset any typed value when an option is selected\n const selectOption = React.useCallback(\n (ev: SelectionEvents, option: OptionValue) => {\n ReactDOM.unstable_batchedUpdates(() => {\n setValue(undefined);\n baseSelectOption(ev, option);\n });\n },\n [setValue, baseSelectOption],\n );\n\n const value = React.useMemo(() => {\n // don't compute the value if it is defined through props or setValue,\n if (controllableValue !== undefined) {\n return controllableValue;\n }\n\n // handle defaultValue here, so it is overridden by selection\n if (isFirstMount && props.defaultValue !== undefined) {\n return props.defaultValue;\n }\n\n const selectedOptionsText = getOptionsMatchingValue(optionValue => {\n return selectedOptions.includes(optionValue);\n }).map(option => option.text);\n\n if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptionsText.join(', ');\n }\n\n return selectedOptionsText[0];\n\n // do not change value after isFirstMount changes,\n // we do not want to accidentally override defaultValue on a second render\n // unless another value is intentionally set\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [controllableValue, editable, getOptionsMatchingValue, multiselect, selectedOptions]);\n\n // Handle open state, which is shared with options in context\n const [open, setOpenState] = useControllableState({\n state: props.open,\n defaultState: props.defaultOpen,\n initialState: false,\n });\n\n const setOpen = React.useCallback(\n (event: ComboboxBaseOpenEvents, newState: boolean) => {\n if (disabled || newState === open) {\n return;\n }\n onOpenChange?.(event, { open: newState });\n ReactDOM.unstable_batchedUpdates(() => {\n if (!newState && !freeform) {\n setValue(undefined);\n }\n setOpenState(newState);\n });\n },\n [disabled, freeform, onOpenChange, open, setOpenState, setValue],\n );\n\n // update active option based on change in open state\n React.useEffect(() => {\n if (open) {\n // if it is single-select and there is a selected option, start at the selected option\n if (!multiselect && selectedOptions.length > 0) {\n const selectedOption = getOptionsMatchingValue(v => v === selectedOptions[0]).pop();\n if (selectedOption?.id) {\n activeDescendantController.focus(selectedOption.id);\n }\n }\n } else {\n activeDescendantController.blur();\n }\n // this should only be run in response to changes in the open state\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open, activeDescendantController]);\n\n // Fallback focus when children are updated in an open popover results in no item being focused\n React.useEffect(() => {\n if (open && !disableAutoFocus && !activeDescendantController.active()) {\n activeDescendantController.first();\n }\n // this should only be run in response to changes in the open state or children\n }, [open, children, disableAutoFocus, activeDescendantController, getOptionById]);\n\n const onActiveDescendantChange = useEventCallback((event: ActiveDescendantChangeEvent) => {\n const previousOption = event.detail.previousId ? optionCollection.getOptionById(event.detail.previousId) : null;\n const nextOption = optionCollection.getOptionById(event.detail.id);\n onActiveOptionChange?.(event, { event, type: 'change', previousOption, nextOption });\n });\n\n return {\n ...optionCollection,\n freeform,\n disabled,\n selectOption,\n clearSelection,\n selectedOptions,\n activeOption: UNSAFE_activeOption,\n appearance,\n clearable,\n focusVisible,\n ignoreNextBlur,\n inlinePopup,\n mountNode,\n open,\n hasFocus,\n setActiveOption: UNSAFE_setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n setValue,\n size,\n value,\n multiselect,\n onOptionClick: useEventCallback((e: React.MouseEvent<HTMLElement>) => {\n if (!multiselect) {\n setOpen(e, false);\n }\n }),\n onActiveDescendantChange,\n };\n};\n"],"names":["React","ReactDOM","useControllableState","useEventCallback","useFirstMount","useOptionCollection","useSelection","useComboboxBaseState","props","appearance","disableAutoFocus","children","clearable","editable","inlinePopup","mountNode","undefined","multiselect","onOpenChange","size","activeDescendantController","freeform","disabled","onActiveOptionChange","optionCollection","getOptionsMatchingValue","getOptionById","getActiveOption","useCallback","activeOptionId","active","UNSAFE_activeOption","UNSAFE_setActiveOption","option","nextOption","activeOption","focus","id","blur","focusVisible","setFocusVisible","useState","hasFocus","setHasFocus","ignoreNextBlur","useRef","isFirstMount","controllableValue","setValue","state","value","initialState","selectedOptions","selectOption","baseSelectOption","clearSelection","ev","unstable_batchedUpdates","useMemo","defaultValue","selectedOptionsText","optionValue","includes","map","text","join","open","setOpenState","defaultState","defaultOpen","setOpen","event","newState","useEffect","length","selectedOption","v","pop","first","onActiveDescendantChange","previousOption","detail","previousId","type","setActiveOption","onOptionClick","e"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,YAAYC,cAAc,YA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AAAA,2CAAAA,qBAAuBgD,OAAO;YAAEA;YAAOY,MAAM;YAAUH;YAAgB9C;QAAW;IACpF;IAEA,OAAO;QACL,GAAGV,gBAAgB;QACnBH;QACAC;QACA+B;QACAE;QACAH;QACAjB,cAAcJ;QACdtB;QACAG;QACA2B;QACAK;QACA9B;QACAC;QACAmD;QACAxB;QACA0C,iBAAiBpD;QACjBQ;QACAG;QACA2B;QACAtB;QACA7B;QACA+B;QACAjC;QACAoE,eAAelF,iBAAiB,CAACmF;YAC/B,IAAI,CAACrE,aAAa;gBAChBqD,QAAQgB,GAAG;YACb;QACF;QACAP;IACF;AACF,EAAE"}
|
|
@@ -7,7 +7,7 @@ import { getDropdownActionFromKey } from "./dropdownKeyActions.js";
|
|
|
7
7
|
* Shared trigger behaviour for combobox and dropdown
|
|
8
8
|
* @returns trigger slot with desired behaviour and props
|
|
9
9
|
*/ export function useTriggerSlot(triggerSlotFromProp, ref, options) {
|
|
10
|
-
const { state: { open, setOpen, setHasFocus }, defaultProps, elementType, activeDescendantController } = options;
|
|
10
|
+
const { state: { open, setOpen, setHasFocus }, defaultProps, elementType, activeDescendantController, shouldCloseOnBlur } = options;
|
|
11
11
|
const trigger = slot.always(triggerSlotFromProp, {
|
|
12
12
|
defaultProps: {
|
|
13
13
|
type: 'text',
|
|
@@ -22,8 +22,11 @@ import { getDropdownActionFromKey } from "./dropdownKeyActions.js";
|
|
|
22
22
|
trigger.ref = useMergedRefs(triggerRef, trigger.ref, ref);
|
|
23
23
|
// the trigger should open/close the popup on click or blur
|
|
24
24
|
trigger.onBlur = mergeCallbacks((event)=>{
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
var _shouldCloseOnBlur;
|
|
26
|
+
if ((_shouldCloseOnBlur = shouldCloseOnBlur === null || shouldCloseOnBlur === void 0 ? void 0 : shouldCloseOnBlur(event)) !== null && _shouldCloseOnBlur !== void 0 ? _shouldCloseOnBlur : true) {
|
|
27
|
+
setOpen(event, false);
|
|
28
|
+
setHasFocus(false);
|
|
29
|
+
}
|
|
27
30
|
}, trigger.onBlur);
|
|
28
31
|
trigger.onFocus = mergeCallbacks((event)=>{
|
|
29
32
|
if (event.target === event.currentTarget) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/useTriggerSlot.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useSetKeyboardNavigation } from '@fluentui/react-tabster';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { mergeCallbacks, slot, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from '../utils/dropdownKeyActions';\nimport type { ComboboxBaseState } from './ComboboxBase.types';\nimport type { OptionValue } from './OptionCollection.types';\n\nexport type UseTriggerSlotState = Pick<\n ComboboxBaseState,\n 'open' | 'getOptionById' | 'selectOption' | 'setOpen' | 'multiselect' | 'setHasFocus'\n>;\n\ntype UseTriggerSlotOptions = {\n state: UseTriggerSlotState;\n defaultProps: unknown;\n activeDescendantController: ActiveDescendantImperativeRef;\n};\n\nexport function useTriggerSlot(\n triggerSlotFromProp: NonNullable<Slot<'button'>>,\n ref: React.Ref<HTMLButtonElement>,\n options: UseTriggerSlotOptions & { elementType: 'button' },\n): SlotComponentType<ExtractSlotProps<Slot<'button'>>>;\n\nexport function useTriggerSlot(\n triggerSlotFromProp: NonNullable<Slot<'input'>>,\n ref: React.Ref<HTMLInputElement>,\n options: UseTriggerSlotOptions & { elementType: 'input' },\n): SlotComponentType<ExtractSlotProps<Slot<'input'>>>;\n\n/**\n * Shared trigger behaviour for combobox and dropdown\n * @returns trigger slot with desired behaviour and props\n */\nexport function useTriggerSlot(\n triggerSlotFromProp: NonNullable<Slot<'input'>> | NonNullable<Slot<'button'>>,\n ref: React.Ref<HTMLButtonElement> | React.Ref<HTMLInputElement>,\n options: UseTriggerSlotOptions & { elementType: 'input' | 'button' },\n): SlotComponentType<ExtractSlotProps<Slot<'button'>>> | SlotComponentType<ExtractSlotProps<Slot<'input'>>> {\n const {\n state: { open, setOpen, setHasFocus },\n defaultProps,\n elementType,\n activeDescendantController,\n } = options;\n\n const trigger = slot.always(triggerSlotFromProp, {\n defaultProps: {\n type: 'text',\n 'aria-expanded': open,\n role: 'combobox',\n ...(typeof defaultProps === 'object' && defaultProps),\n },\n elementType,\n });\n\n // handle trigger focus/blur\n const triggerRef = React.useRef<HTMLButtonElement | HTMLInputElement>(null);\n trigger.ref = useMergedRefs(triggerRef, trigger.ref, ref) as React.Ref<HTMLButtonElement & HTMLInputElement>;\n\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n setOpen(event, false);\n setHasFocus(false);\n }, trigger.onBlur);\n\n trigger.onFocus = mergeCallbacks(\n (event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n if (event.target === event.currentTarget) {\n setHasFocus(true);\n }\n },\n trigger.onFocus,\n );\n trigger.onClick = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setOpen(event, !open);\n },\n trigger.onClick,\n );\n\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks(\n useTriggerKeydown({ activeDescendantController, ...options.state }),\n trigger.onKeyDown,\n );\n\n return trigger as SlotComponentType<ExtractSlotProps<Slot<'input'>>>;\n}\n\nfunction useTriggerKeydown(\n options: {\n activeDescendantController: ActiveDescendantImperativeRef;\n } & Pick<UseTriggerSlotState, 'setOpen' | 'selectOption' | 'getOptionById' | 'multiselect' | 'open'>,\n) {\n const { activeDescendantController, getOptionById, setOpen, selectOption, multiselect, open } = options;\n\n const getActiveOption = React.useCallback(() => {\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [activeDescendantController, getOptionById]);\n\n const first = () => {\n activeDescendantController.first();\n };\n\n const last = () => {\n activeDescendantController.last();\n };\n\n const next = (activeOption: OptionValue | undefined) => {\n if (activeOption) {\n activeDescendantController.next();\n } else {\n activeDescendantController.first();\n }\n };\n\n const previous = (activeOption: OptionValue | undefined) => {\n if (activeOption) {\n activeDescendantController.prev();\n } else {\n activeDescendantController.first();\n }\n };\n\n const pageUp = () => {\n for (let i = 0; i < 10; i++) {\n activeDescendantController.prev();\n }\n };\n\n const pageDown = () => {\n for (let i = 0; i < 10; i++) {\n activeDescendantController.next();\n }\n };\n\n const setKeyboardNavigation = useSetKeyboardNavigation();\n return useEventCallback((e: React.KeyboardEvent<HTMLInputElement> & React.KeyboardEvent<HTMLButtonElement>) => {\n const action = getDropdownActionFromKey(e, { open, multiselect });\n const activeOption = getActiveOption();\n\n switch (action) {\n case 'First':\n case 'Last':\n case 'Next':\n case 'Previous':\n case 'PageDown':\n case 'PageUp':\n case 'Open':\n case 'Close':\n case 'CloseSelect':\n case 'Select':\n e.preventDefault();\n break;\n }\n\n setKeyboardNavigation(true);\n\n switch (action) {\n case 'First':\n first();\n break;\n case 'Last':\n last();\n break;\n case 'Next':\n next(activeOption);\n break;\n case 'Previous':\n previous(activeOption);\n break;\n case 'PageDown':\n pageDown();\n break;\n case 'PageUp':\n pageUp();\n break;\n case 'Open':\n setOpen(e, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n e.stopPropagation();\n setOpen(e, false);\n break;\n case 'CloseSelect':\n !multiselect && !activeOption?.disabled && setOpen(e, false);\n // fallthrough\n case 'Select':\n activeOption && selectOption(e, activeOption);\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(e, activeOption);\n break;\n }\n });\n}\n"],"names":["React","useSetKeyboardNavigation","mergeCallbacks","slot","useEventCallback","useMergedRefs","getDropdownActionFromKey","useTriggerSlot","triggerSlotFromProp","ref","options","state","open","setOpen","setHasFocus","defaultProps","elementType","activeDescendantController","trigger","always","type","role","triggerRef","useRef","onBlur","event","onFocus","target","currentTarget","onClick","onKeyDown","useTriggerKeydown","getOptionById","selectOption","multiselect","getActiveOption","useCallback","activeOptionId","active","undefined","first","last","next","activeOption","previous","prev","pageUp","i","pageDown","setKeyboardNavigation","e","action","preventDefault","stopPropagation","disabled"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,wBAAwB,QAAQ,0BAA0B;AAEnE,SAASC,cAAc,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAElG,SAASC,wBAAwB,QAAQ,0BAA8B;AA2BvE;;;CAGC,GACD,OAAO,SAASC,eACdC,mBAA6E,EAC7EC,GAA+D,EAC/DC,OAAoE;IAEpE,MAAM,EACJC,OAAO,EAAEC,IAAI,EAAEC,OAAO,EAAEC,WAAW,EAAE,EACrCC,YAAY,EACZC,WAAW,EACXC,0BAA0B,EAC3B,GAAGP;IAEJ,MAAMQ,UAAUf,KAAKgB,MAAM,CAACX,qBAAqB;QAC/CO,cAAc;YACZK,MAAM;YACN,iBAAiBR;YACjBS,MAAM;YACN,GAAI,OAAON,iBAAiB,YAAYA,YAAY;QACtD;QACAC;IACF;IAEA,4BAA4B;IAC5B,MAAMM,aAAatB,MAAMuB,MAAM,CAAuC;IACtEL,QAAQT,GAAG,GAAGJ,cAAciB,YAAYJ,QAAQT,GAAG,EAAEA;IAErD,2DAA2D;IAC3DS,QAAQM,MAAM,GAAGtB,eAAe,CAACuB;QAC/BZ,QAAQY,OAAO;QACfX,YAAY;IACd,GAAGI,QAAQM,MAAM;IAEjBN,QAAQQ,OAAO,GAAGxB,eAChB,CAACuB;QACC,IAAIA,MAAME,MAAM,KAAKF,MAAMG,aAAa,EAAE;YACxCd,YAAY;QACd;IACF,GACAI,QAAQQ,OAAO;IAEjBR,QAAQW,OAAO,GAAG3B,eAChB,CAACuB;QACCZ,QAAQY,OAAO,CAACb;IAClB,GACAM,QAAQW,OAAO;IAGjB,uCAAuC;IACvCX,QAAQY,SAAS,GAA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Ac;gBAChB;QACJ;QAEAH,sBAAsB;QAEtB,OAAQE;YACN,KAAK;gBACHX;gBACA;YACF,KAAK;gBACHC;gBACA;YACF,KAAK;gBACHC,KAAKC;gBACL;YACF,KAAK;gBACHC,SAASD;gBACT;YACF,KAAK;gBACHK;gBACA;YACF,KAAK;gBACHF;gBACA;YACF,KAAK;gBACHjC,QAAQqC,GAAG;gBACX;YACF,KAAK;gBACH,wEAAwE;gBACxEA,EAAEG,eAAe;gBACjBxC,QAAQqC,GAAG;gBACX;YACF,KAAK;gBACH,CAAChB,eAAe,EAACS,yBAAAA,mCAAAA,aAAcW,QAAQ,KAAIzC,QAAQqC,GAAG;YACxD,cAAc;YACd,KAAK;gBACHP,gBAAgBV,aAAaiB,GAAGP;gBAChC;YACF,KAAK;gBACH,CAACT,eAAeS,gBAAgBV,aAAaiB,GAAGP;gBAChD;QACJ;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../src/utils/useTriggerSlot.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useSetKeyboardNavigation } from '@fluentui/react-tabster';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { mergeCallbacks, slot, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from '../utils/dropdownKeyActions';\nimport type { ComboboxBaseState } from './ComboboxBase.types';\nimport type { OptionValue } from './OptionCollection.types';\n\nexport type UseTriggerSlotState = Pick<\n ComboboxBaseState,\n 'open' | 'getOptionById' | 'selectOption' | 'setOpen' | 'multiselect' | 'setHasFocus'\n>;\n\nexport type UseTriggerSlotOptions = {\n state: UseTriggerSlotState;\n defaultProps: unknown;\n activeDescendantController: ActiveDescendantImperativeRef;\n shouldCloseOnBlur?: (event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => boolean;\n};\n\nexport function useTriggerSlot(\n triggerSlotFromProp: NonNullable<Slot<'button'>>,\n ref: React.Ref<HTMLButtonElement>,\n options: UseTriggerSlotOptions & { elementType: 'button' },\n): SlotComponentType<ExtractSlotProps<Slot<'button'>>>;\n\nexport function useTriggerSlot(\n triggerSlotFromProp: NonNullable<Slot<'input'>>,\n ref: React.Ref<HTMLInputElement>,\n options: UseTriggerSlotOptions & { elementType: 'input' },\n): SlotComponentType<ExtractSlotProps<Slot<'input'>>>;\n\n/**\n * Shared trigger behaviour for combobox and dropdown\n * @returns trigger slot with desired behaviour and props\n */\nexport function useTriggerSlot(\n triggerSlotFromProp: NonNullable<Slot<'input'>> | NonNullable<Slot<'button'>>,\n ref: React.Ref<HTMLButtonElement> | React.Ref<HTMLInputElement>,\n options: UseTriggerSlotOptions & { elementType: 'input' | 'button' },\n): SlotComponentType<ExtractSlotProps<Slot<'button'>>> | SlotComponentType<ExtractSlotProps<Slot<'input'>>> {\n const {\n state: { open, setOpen, setHasFocus },\n defaultProps,\n elementType,\n activeDescendantController,\n shouldCloseOnBlur,\n } = options;\n\n const trigger = slot.always(triggerSlotFromProp, {\n defaultProps: {\n type: 'text',\n 'aria-expanded': open,\n role: 'combobox',\n ...(typeof defaultProps === 'object' && defaultProps),\n },\n elementType,\n });\n\n // handle trigger focus/blur\n const triggerRef = React.useRef<HTMLButtonElement | HTMLInputElement>(null);\n trigger.ref = useMergedRefs(triggerRef, trigger.ref, ref) as React.Ref<HTMLButtonElement & HTMLInputElement>;\n\n // the trigger should open/close the popup on click or blur\n trigger.onBlur = mergeCallbacks((event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n if (shouldCloseOnBlur?.(event) ?? true) {\n setOpen(event, false);\n setHasFocus(false);\n }\n }, trigger.onBlur);\n\n trigger.onFocus = mergeCallbacks(\n (event: React.FocusEvent<HTMLButtonElement> & React.FocusEvent<HTMLInputElement>) => {\n if (event.target === event.currentTarget) {\n setHasFocus(true);\n }\n },\n trigger.onFocus,\n );\n trigger.onClick = mergeCallbacks(\n (event: React.MouseEvent<HTMLButtonElement> & React.MouseEvent<HTMLInputElement>) => {\n setOpen(event, !open);\n },\n trigger.onClick,\n );\n\n // handle combobox keyboard interaction\n trigger.onKeyDown = mergeCallbacks(\n useTriggerKeydown({ activeDescendantController, ...options.state }),\n trigger.onKeyDown,\n );\n\n return trigger as SlotComponentType<ExtractSlotProps<Slot<'input'>>>;\n}\n\nfunction useTriggerKeydown(\n options: {\n activeDescendantController: ActiveDescendantImperativeRef;\n } & Pick<UseTriggerSlotState, 'setOpen' | 'selectOption' | 'getOptionById' | 'multiselect' | 'open'>,\n) {\n const { activeDescendantController, getOptionById, setOpen, selectOption, multiselect, open } = options;\n\n const getActiveOption = React.useCallback(() => {\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [activeDescendantController, getOptionById]);\n\n const first = () => {\n activeDescendantController.first();\n };\n\n const last = () => {\n activeDescendantController.last();\n };\n\n const next = (activeOption: OptionValue | undefined) => {\n if (activeOption) {\n activeDescendantController.next();\n } else {\n activeDescendantController.first();\n }\n };\n\n const previous = (activeOption: OptionValue | undefined) => {\n if (activeOption) {\n activeDescendantController.prev();\n } else {\n activeDescendantController.first();\n }\n };\n\n const pageUp = () => {\n for (let i = 0; i < 10; i++) {\n activeDescendantController.prev();\n }\n };\n\n const pageDown = () => {\n for (let i = 0; i < 10; i++) {\n activeDescendantController.next();\n }\n };\n\n const setKeyboardNavigation = useSetKeyboardNavigation();\n return useEventCallback((e: React.KeyboardEvent<HTMLInputElement> & React.KeyboardEvent<HTMLButtonElement>) => {\n const action = getDropdownActionFromKey(e, { open, multiselect });\n const activeOption = getActiveOption();\n\n switch (action) {\n case 'First':\n case 'Last':\n case 'Next':\n case 'Previous':\n case 'PageDown':\n case 'PageUp':\n case 'Open':\n case 'Close':\n case 'CloseSelect':\n case 'Select':\n e.preventDefault();\n break;\n }\n\n setKeyboardNavigation(true);\n\n switch (action) {\n case 'First':\n first();\n break;\n case 'Last':\n last();\n break;\n case 'Next':\n next(activeOption);\n break;\n case 'Previous':\n previous(activeOption);\n break;\n case 'PageDown':\n pageDown();\n break;\n case 'PageUp':\n pageUp();\n break;\n case 'Open':\n setOpen(e, true);\n break;\n case 'Close':\n // stop propagation for escape key to avoid dismissing any parent popups\n e.stopPropagation();\n setOpen(e, false);\n break;\n case 'CloseSelect':\n !multiselect && !activeOption?.disabled && setOpen(e, false);\n // fallthrough\n case 'Select':\n activeOption && selectOption(e, activeOption);\n break;\n case 'Tab':\n !multiselect && activeOption && selectOption(e, activeOption);\n break;\n }\n });\n}\n"],"names":["React","useSetKeyboardNavigation","mergeCallbacks","slot","useEventCallback","useMergedRefs","getDropdownActionFromKey","useTriggerSlot","triggerSlotFromProp","ref","options","state","open","setOpen","setHasFocus","defaultProps","elementType","activeDescendantController","shouldCloseOnBlur","trigger","always","type","role","triggerRef","useRef","onBlur","event","onFocus","target","currentTarget","onClick","onKeyDown","useTriggerKeydown","getOptionById","selectOption","multiselect","getActiveOption","useCallback","activeOptionId","active","undefined","first","last","next","activeOption","previous","prev","pageUp","i","pageDown","setKeyboardNavigation","e","action","preventDefault","stopPropagation","disabled"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,wBAAwB,QAAQ,0BAA0B;AAEnE,SAASC,cAAc,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAElG,SAASC,wBAAwB,QAAQ,0BAA8B;AA4BvE;;;CAGC,GACD,OAAO,SAASC,eACdC,mBAA6E,EAC7EC,GAA+D,EAC/DC,OAAoE;IAEpE,MAAM,EACJC,OAAO,EAAEC,IAAI,EAAEC,OAAO,EAAEC,WAAW,EAAE,EACrCC,YAAY,EACZC,WAAW,EACXC,0BAA0B,EAC1BC,iBAAiB,EAClB,GAAGR;IAEJ,MAAMS,UAAUhB,KAAKiB,MAAM,CAACZ,qBAAqB;QAC/CO,cAAc;YACZM,MAAM;YACN,iBAAiBT;YACjBU,MA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|
|
@@ -31,8 +31,9 @@ const _useListboxSlot = require("../../utils/useListboxSlot.cjs");
|
|
|
31
31
|
const _useInputTriggerSlot = require("./useInputTriggerSlot.cjs");
|
|
32
32
|
const _isComboboxOptionElement = require("../../utils/isComboboxOptionElement.cjs");
|
|
33
33
|
const _useTabsterEscapeIgnore = require("../../hooks/useTabsterEscapeIgnore.cjs");
|
|
34
|
+
const _useComboboxExpandIconSlot = require("./useComboboxExpandIconSlot.cjs");
|
|
34
35
|
const useComboboxBase_unstable = (props, ref)=>{
|
|
35
|
-
var _state_clearIcon, _state_clearIcon1;
|
|
36
|
+
var _state_expandIcon, _state_expandIcon1, _state_expandIcon2, _state_clearIcon, _state_clearIcon1;
|
|
36
37
|
// Merge props from surrounding <Field>, if any
|
|
37
38
|
props = (0, _reactfield.useFieldControlProps_unstable)(props, {
|
|
38
39
|
supportsLabelFor: true,
|
|
@@ -50,7 +51,7 @@ const useComboboxBase_unstable = (props, ref)=>{
|
|
|
50
51
|
const { clearable, clearSelection, disabled, multiselect, open, selectedOptions, setOpen, value, hasFocus } = baseState;
|
|
51
52
|
const [comboboxPopupRef, comboboxTargetRef] = (0, _useComboboxPositioning.useComboboxPositioning)(props);
|
|
52
53
|
const { disableAutoFocus = false, freeform, inlinePopup } = props;
|
|
53
|
-
const
|
|
54
|
+
const expandIconRef = _react.useRef(null);
|
|
54
55
|
const { primary: triggerNativeProps, root: rootNativeProps } = (0, _reactutilities.getPartitionedNativeProps)({
|
|
55
56
|
props,
|
|
56
57
|
primarySlotTagName: 'input',
|
|
@@ -77,7 +78,8 @@ const useComboboxBase_unstable = (props, ref)=>{
|
|
|
77
78
|
'aria-controls': open ? listbox === null || listbox === void 0 ? void 0 : listbox.id : undefined,
|
|
78
79
|
...triggerNativeProps
|
|
79
80
|
},
|
|
80
|
-
activeDescendantController
|
|
81
|
+
activeDescendantController,
|
|
82
|
+
shouldCloseOnBlur: (event)=>!expandIconRef.current || event.relatedTarget !== expandIconRef.current
|
|
81
83
|
});
|
|
82
84
|
const rootSlot = _reactutilities.slot.always(props.root, {
|
|
83
85
|
defaultProps: {
|
|
@@ -87,6 +89,14 @@ const useComboboxBase_unstable = (props, ref)=>{
|
|
|
87
89
|
elementType: 'div'
|
|
88
90
|
});
|
|
89
91
|
rootSlot.ref = (0, _reactutilities.useMergedRefs)(rootSlot.ref, comboboxTargetRef);
|
|
92
|
+
rootSlot.onBlur = (0, _reactutilities.mergeCallbacks)(rootSlot.onBlur, (event)=>{
|
|
93
|
+
if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) {
|
|
94
|
+
if (event.target !== event.currentTarget.querySelector('input')) {
|
|
95
|
+
comboboxInternalState.setOpen(event, false);
|
|
96
|
+
}
|
|
97
|
+
comboboxInternalState.setHasFocus(false);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
90
100
|
const showClearIcon = selectedOptions.length > 0 && !disabled && clearable && !multiselect;
|
|
91
101
|
const state = {
|
|
92
102
|
components: {
|
|
@@ -106,14 +116,13 @@ const useComboboxBase_unstable = (props, ref)=>{
|
|
|
106
116
|
elementType: 'span',
|
|
107
117
|
renderByDefault: true
|
|
108
118
|
}),
|
|
109
|
-
expandIcon:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
elementType: 'span'
|
|
119
|
+
expandIcon: (0, _useComboboxExpandIconSlot.useComboboxExpandIconSlot)(props.expandIcon, {
|
|
120
|
+
disabled,
|
|
121
|
+
hideFromTabOrder: showClearIcon,
|
|
122
|
+
open,
|
|
123
|
+
'aria-label': props['aria-label'],
|
|
124
|
+
'aria-labelledby': props['aria-labelledby'],
|
|
125
|
+
triggerLabelledBy: triggerSlot['aria-labelledby']
|
|
117
126
|
}),
|
|
118
127
|
showClearIcon,
|
|
119
128
|
activeDescendantController,
|
|
@@ -134,33 +143,44 @@ const useComboboxBase_unstable = (props, ref)=>{
|
|
|
134
143
|
const onExpandIconMouseDown = (0, _reactutilities.useEventCallback)((0, _reactutilities.mergeCallbacks)(onIconMouseDown, (event)=>{
|
|
135
144
|
var _triggerRef_current;
|
|
136
145
|
event.preventDefault();
|
|
137
|
-
|
|
146
|
+
if (!state.disabled) {
|
|
147
|
+
state.setOpen(event, !state.open);
|
|
148
|
+
}
|
|
138
149
|
(_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
|
|
139
150
|
}));
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
// We can't fall back to a label/htmlFor name because of https://github.com/w3c/accname/issues/179
|
|
148
|
-
const hasExpandLabel = state.expandIcon['aria-label'] || state.expandIcon['aria-labelledby'];
|
|
149
|
-
const defaultOpenString = 'Open'; // this is english-only since it is the fallback
|
|
150
|
-
if (!hasExpandLabel) {
|
|
151
|
-
if (props['aria-labelledby']) {
|
|
152
|
-
var _state_expandIcon_id;
|
|
153
|
-
const chevronId = (_state_expandIcon_id = state.expandIcon.id) !== null && _state_expandIcon_id !== void 0 ? _state_expandIcon_id : `${comboId}-chevron`;
|
|
154
|
-
const chevronLabelledBy = `${chevronId} ${state.input['aria-labelledby']}`;
|
|
155
|
-
state.expandIcon['aria-label'] = defaultOpenString;
|
|
156
|
-
state.expandIcon.id = chevronId;
|
|
157
|
-
state.expandIcon['aria-labelledby'] = chevronLabelledBy;
|
|
158
|
-
} else if (props['aria-label']) {
|
|
159
|
-
state.expandIcon['aria-label'] = `${defaultOpenString} ${props['aria-label']}`;
|
|
160
|
-
} else {
|
|
161
|
-
state.expandIcon['aria-label'] = defaultOpenString;
|
|
151
|
+
const onExpandIconClick = (0, _reactutilities.useEventCallback)((0, _reactutilities.mergeCallbacks)((_state_expandIcon = state.expandIcon) === null || _state_expandIcon === void 0 ? void 0 : _state_expandIcon.onClick, (event)=>{
|
|
152
|
+
// Pointer clicks already toggle on mousedown; click-only activation has detail 0.
|
|
153
|
+
if (event.detail === 0) {
|
|
154
|
+
var _triggerRef_current;
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
if (!state.disabled) {
|
|
157
|
+
state.setOpen(event, !state.open);
|
|
162
158
|
}
|
|
159
|
+
(_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
|
|
160
|
+
}
|
|
161
|
+
}));
|
|
162
|
+
const onExpandIconKeyDown = (0, _reactutilities.useEventCallback)((0, _reactutilities.mergeCallbacks)((_state_expandIcon1 = state.expandIcon) === null || _state_expandIcon1 === void 0 ? void 0 : _state_expandIcon1.onKeyDown, (event)=>{
|
|
163
|
+
if (state.open && event.key === 'Escape') {
|
|
164
|
+
var _triggerRef_current;
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
event.stopPropagation();
|
|
167
|
+
state.setOpen(event, false);
|
|
168
|
+
(_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
|
|
169
|
+
return;
|
|
163
170
|
}
|
|
171
|
+
if (!state.disabled && (event.key === 'Enter' || event.key === ' ')) {
|
|
172
|
+
var _triggerRef_current1;
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
state.setOpen(event, !state.open);
|
|
175
|
+
(_triggerRef_current1 = triggerRef.current) === null || _triggerRef_current1 === void 0 ? void 0 : _triggerRef_current1.focus();
|
|
176
|
+
}
|
|
177
|
+
}));
|
|
178
|
+
const expandIconSlotRef = (0, _reactutilities.useMergedRefs)((_state_expandIcon2 = state.expandIcon) === null || _state_expandIcon2 === void 0 ? void 0 : _state_expandIcon2.ref, expandIconRef);
|
|
179
|
+
if (state.expandIcon) {
|
|
180
|
+
state.expandIcon.ref = expandIconSlotRef;
|
|
181
|
+
state.expandIcon.onMouseDown = onExpandIconMouseDown;
|
|
182
|
+
state.expandIcon.onClick = onExpandIconClick;
|
|
183
|
+
state.expandIcon.onKeyDown = onExpandIconKeyDown;
|
|
164
184
|
}
|
|
165
185
|
const onClearIconMouseDown = (0, _reactutilities.useEventCallback)((0, _reactutilities.mergeCallbacks)((_state_clearIcon = state.clearIcon) === null || _state_clearIcon === void 0 ? void 0 : _state_clearIcon.onMouseDown, (ev)=>{
|
|
166
186
|
ev.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Combobox/useCombobox.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useActiveDescendant } from '@fluentui/react-aria';\nimport { useFieldContext_unstable, useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { ChevronDownRegular as ChevronDownIcon, DismissRegular as DismissIcon } from '@fluentui/react-icons';\nimport {\n getPartitionedNativeProps,\n mergeCallbacks,\n useEventCallback,\n useId,\n useMergedRefs,\n slot,\n useOnClickOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPositioning } from '../../utils/useComboboxPositioning';\nimport { Listbox } from '../Listbox/Listbox';\nimport type {\n BaseComboboxProps,\n BaseComboboxState,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxState,\n} from './Combobox.types';\nimport { useListboxSlot } from '../../utils/useListboxSlot';\nimport { useInputTriggerSlot } from './useInputTriggerSlot';\nimport { isComboboxOptionElement } from '../../utils/isComboboxOptionElement';\nimport { useTabsterEscapeIgnore } from '../../hooks/useTabsterEscapeIgnore';\n\n/**\n * Create the base state required to render Combobox, without design-only props.\n *\n * @param props - props from this instance of Combobox (without appearance and size)\n * @param ref - reference to root HTMLInputElement of Combobox\n */\nexport const useComboboxBase_unstable = (\n props: BaseComboboxProps,\n ref: React.Ref<HTMLInputElement>,\n): BaseComboboxState => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });\n const {\n listboxRef: activeDescendantListboxRef,\n activeParentRef,\n controller: activeDescendantController,\n } = useActiveDescendant<HTMLInputElement, HTMLDivElement>({\n matchOption: isComboboxOptionElement,\n });\n const comboboxInternalState = useComboboxBaseState({ ...props, editable: true, activeDescendantController });\n const { appearance: _appearance, size: _size, ...baseState } = comboboxInternalState;\n\n const { clearable, clearSelection, disabled, multiselect, open, selectedOptions, setOpen, value, hasFocus } =\n baseState;\n const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);\n const { disableAutoFocus = false, freeform, inlinePopup } = props;\n const comboId = useId('combobox-');\n\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['children'],\n });\n\n const triggerRef = React.useRef<HTMLInputElement>(null);\n\n const listbox = useListboxSlot(props.listbox, useMergedRefs(comboboxPopupRef, activeDescendantListboxRef), {\n state: comboboxInternalState,\n triggerRef,\n defaultProps: {\n children: props.children,\n disableAutoFocus,\n },\n });\n\n const triggerSlot = useInputTriggerSlot(props.input ?? {}, useMergedRefs(triggerRef, activeParentRef, ref), {\n state: comboboxInternalState,\n freeform,\n defaultProps: {\n type: 'text',\n value: value ?? '',\n 'aria-controls': open ? listbox?.id : undefined,\n ...triggerNativeProps,\n },\n activeDescendantController,\n });\n\n const rootSlot = slot.always(props.root, {\n defaultProps: {\n 'aria-owns': !inlinePopup && open ? listbox?.id : undefined,\n ...rootNativeProps,\n },\n elementType: 'div',\n });\n rootSlot.ref = useMergedRefs(rootSlot.ref, comboboxTargetRef);\n\n const showClearIcon = selectedOptions.length > 0 && !disabled && clearable && !multiselect;\n const state: BaseComboboxState = {\n components: { root: 'div', input: 'input', expandIcon: 'span', listbox: Listbox, clearIcon: 'span' },\n root: rootSlot,\n input: triggerSlot,\n listbox: open || hasFocus ? listbox : undefined,\n clearIcon: slot.optional(props.clearIcon, {\n defaultProps: {\n 'aria-hidden': 'true',\n },\n elementType: 'span',\n renderByDefault: true,\n }),\n expandIcon: slot.optional(props.expandIcon, {\n renderByDefault: true,\n defaultProps: {\n 'aria-disabled': disabled ? 'true' : undefined,\n 'aria-expanded': open,\n role: 'button',\n },\n elementType: 'span',\n }),\n showClearIcon,\n activeDescendantController,\n ...baseState,\n };\n\n const { targetDocument } = useFluent();\n\n useOnClickOutside({\n element: targetDocument,\n callback: event => setOpen(event as unknown as ComboboxOpenEvents, false),\n refs: [triggerRef, comboboxPopupRef, comboboxTargetRef],\n disabled: !open,\n });\n\n /* handle open/close + focus change when clicking expandIcon */\n const { onMouseDown: onIconMouseDown } = state.expandIcon || {};\n\n const onExpandIconMouseDown = useEventCallback(\n // eslint-disable-next-line react-hooks/refs\n mergeCallbacks(onIconMouseDown, (event: React.MouseEvent<HTMLSpanElement>) => {\n event.preventDefault();\n state.setOpen(event, !state.open);\n triggerRef.current?.focus();\n }),\n );\n\n if (state.expandIcon) {\n state.expandIcon.onMouseDown = onExpandIconMouseDown;\n\n // If there is no explicit aria-label, calculate default accName attribute for expandIcon button,\n // using the following steps:\n // 1. If there is an aria-label, it is \"Open [aria-label]\"\n // 2. If there is an aria-labelledby, it is \"Open [aria-labelledby target]\" (using aria-labelledby + ids)\n // 3. If there is no aria-label/ledby attr, it falls back to \"Open\"\n // We can't fall back to a label/htmlFor name because of https://github.com/w3c/accname/issues/179\n const hasExpandLabel = state.expandIcon['aria-label'] || state.expandIcon['aria-labelledby'];\n const defaultOpenString = 'Open'; // this is english-only since it is the fallback\n if (!hasExpandLabel) {\n if (props['aria-labelledby']) {\n const chevronId = state.expandIcon.id ?? `${comboId}-chevron`;\n const chevronLabelledBy = `${chevronId} ${state.input['aria-labelledby']}`;\n\n state.expandIcon['aria-label'] = defaultOpenString;\n state.expandIcon.id = chevronId;\n state.expandIcon['aria-labelledby'] = chevronLabelledBy;\n } else if (props['aria-label']) {\n state.expandIcon['aria-label'] = `${defaultOpenString} ${props['aria-label']}`;\n } else {\n state.expandIcon['aria-label'] = defaultOpenString;\n }\n }\n }\n\n const onClearIconMouseDown = useEventCallback(\n mergeCallbacks(state.clearIcon?.onMouseDown, (ev: React.MouseEvent<HTMLSpanElement>) => {\n ev.preventDefault();\n }),\n );\n const onClearIconClick = useEventCallback(\n mergeCallbacks(state.clearIcon?.onClick, (ev: React.MouseEvent<HTMLSpanElement>) => {\n clearSelection(ev);\n }),\n );\n\n if (state.clearIcon) {\n state.clearIcon.onMouseDown = onClearIconMouseDown;\n state.clearIcon.onClick = onClearIconClick;\n }\n\n // Heads up! We don't support \"clearable\" in multiselect mode, so we should never display a slot\n if (multiselect) {\n state.clearIcon = undefined;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- \"process.env\" does not change in runtime\n React.useEffect(() => {\n if (clearable && multiselect) {\n // eslint-disable-next-line no-console\n console.error(`[@fluentui/react-combobox] \"clearable\" prop is not supported in multiselect mode.`);\n }\n }, [clearable, multiselect]);\n }\n\n return state;\n};\n\n/**\n * Create the state required to render Combobox.\n *\n * The returned state can be modified with hooks such as useComboboxStyles_unstable,\n * before being passed to renderCombobox_unstable.\n *\n * @param props - props from this instance of Combobox\n * @param ref - reference to root HTMLElement of Combobox\n */\nexport const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLInputElement>): ComboboxState => {\n const fieldContext = useFieldContext_unstable();\n const { appearance = 'outline', size = fieldContext?.size ?? 'medium', ...baseProps } = props;\n const baseState = useComboboxBase_unstable(baseProps, ref);\n\n if (baseState.clearIcon) {\n baseState.clearIcon.children ??= <DismissIcon />;\n }\n\n if (baseState.expandIcon) {\n baseState.expandIcon.children ??= <ChevronDownIcon />;\n }\n\n return {\n ...baseState,\n appearance,\n size,\n input: {\n ...useTabsterEscapeIgnore(baseState.input, baseState.open),\n ...baseState.input,\n },\n };\n};\n"],"names":["React","useActiveDescendant","useFieldContext_unstable","useFieldControlProps_unstable","ChevronDownRegular","ChevronDownIcon","DismissRegular","DismissIcon","getPartitionedNativeProps","mergeCallbacks","useEventCallback","useId","useMergedRefs","slot","useOnClickOutside","useFluent_unstable","useFluent","useComboboxBaseState","useComboboxPositioning","Listbox","useListboxSlot","useInputTriggerSlot","isComboboxOptionElement","useTabsterEscapeIgnore","useComboboxBase_unstable","props","ref","state","supportsLabelFor","supportsRequired","listboxRef","activeDescendantListboxRef","activeParentRef","controller","activeDescendantController","matchOption","comboboxInternalState","editable","appearance","_appearance","size","_size","baseState","clearable","clearSelection","disabled","multiselect","open","selectedOptions","setOpen","value","hasFocus","comboboxPopupRef","comboboxTargetRef","disableAutoFocus","freeform","inlinePopup","comboId","primary","triggerNativeProps","root","rootNativeProps","primarySlotTagName","excludedPropNames","triggerRef","useRef","listbox","defaultProps","children","triggerSlot","input","type","id","undefined","rootSlot","always","elementType","showClearIcon","length","components","expandIcon","clearIcon","optional","renderByDefault","role","targetDocument","element","callback","event","refs","onMouseDown","onIconMouseDown","onExpandIconMouseDown","preventDefault","current","focus","hasExpandLabel","defaultOpenString","chevronId","chevronLabelledBy","onClearIconMouseDown","ev","onClearIconClick","onClick","process","env","NODE_ENV","useEffect","console","error","useCombobox_unstable","fieldContext","baseProps"],"mappings":"AAAA;;;;;;;;;;;;IAqCawB,wBAAAA;;;wBAkLAsF;eAAAA;;;;iEArNU,QAAQ;2BACK,uBAAuB;4BACa,wBAAwB;4BACX,wBAAwB;gCAStG,4BAA4B;qCACa,kCAAkC;sCAC7C,sCAAmC;wCACjC,wCAAqC;yBACpD,wBAAqB;gCAQd,gCAA6B;qCACxB,2BAAwB;yCACpB,yCAAsC;wCACvC,wCAAqC;AAQrE,iCAAiC,CACtCrF,OACAC;QAsIiBC,kBAKAA;IAzIjB,+CAA+C;IAC/CF,QAAQtB,6CAAAA,EAA8BsB,OAAO;QAAEG,kBAAkB;QAAMC,kBAAkB;IAAK;IAC9F,MAAM,EACJC,YAAYC,0BAA0B,EACtCC,eAAe,EACfC,YAAYC,0BAA0B,EACvC,OAAGjC,8BAAAA,EAAsD;QACxDkC,aAAab,gDAAAA;IACf;IACA,MAAMc,4BAAwBnB,0CAAAA,EAAqB;QAAE,GAAGQ,KAAK;QAA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A,uBAAAA,UAAUuC,SAAAA,AAAS,EAACb,QAAAA,MAAAA,QAAAA,cAAAA,KAAAA,IAAAA,YAApB1B,qBAAoB0B,QAAAA,GAAAA,WAAAA,GAAa,OAAA,aAAA,CAAC7D,0BAAAA,EAAAA;IACpC;IAEA,IAAImC,UAAUsC,UAAU,EAAE;YACxBtC;;QAAAA,CAAAA,aAAAA,CAAAA,wBAAAA,UAAUsC,UAAAA,AAAU,EAACZ,QAAAA,MAAAA,QAAAA,eAAAA,KAAAA,IAAAA,aAArB1B,sBAAqB0B,QAAAA,GAAAA,WAAAA,GAAa,OAAA,aAAA,CAAC/D,8BAAAA,EAAAA;IACrC;IAEA,OAAO;QACL,GAAGqC,SAAS;QACZJ;QACAE;QACA8B,OAAO;YACL,OAAG/C,8CAAAA,EAAuBmB,UAAU4B,KAAK,EAAE5B,UAAUK,IAAI,CAAC;YAC1D,GAAGL,UAAU4B,KAAK;QACpB;IACF;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../src/components/Combobox/useCombobox.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useActiveDescendant } from '@fluentui/react-aria';\nimport { useFieldContext_unstable, useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { ChevronDownRegular as ChevronDownIcon, DismissRegular as DismissIcon } from '@fluentui/react-icons';\nimport {\n getPartitionedNativeProps,\n mergeCallbacks,\n useEventCallback,\n useMergedRefs,\n slot,\n useOnClickOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPositioning } from '../../utils/useComboboxPositioning';\nimport { Listbox } from '../Listbox/Listbox';\nimport type {\n BaseComboboxProps,\n BaseComboboxState,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxState,\n} from './Combobox.types';\nimport { useListboxSlot } from '../../utils/useListboxSlot';\nimport { useInputTriggerSlot } from './useInputTriggerSlot';\nimport { isComboboxOptionElement } from '../../utils/isComboboxOptionElement';\nimport { useTabsterEscapeIgnore } from '../../hooks/useTabsterEscapeIgnore';\nimport { useComboboxExpandIconSlot } from './useComboboxExpandIconSlot';\n\n/**\n * Create the base state required to render Combobox, without design-only props.\n *\n * @param props - props from this instance of Combobox (without appearance and size)\n * @param ref - reference to root HTMLInputElement of Combobox\n */\nexport const useComboboxBase_unstable = (\n props: BaseComboboxProps,\n ref: React.Ref<HTMLInputElement>,\n): BaseComboboxState => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });\n const {\n listboxRef: activeDescendantListboxRef,\n activeParentRef,\n controller: activeDescendantController,\n } = useActiveDescendant<HTMLInputElement, HTMLDivElement>({\n matchOption: isComboboxOptionElement,\n });\n const comboboxInternalState = useComboboxBaseState({ ...props, editable: true, activeDescendantController });\n const { appearance: _appearance, size: _size, ...baseState } = comboboxInternalState;\n\n const { clearable, clearSelection, disabled, multiselect, open, selectedOptions, setOpen, value, hasFocus } =\n baseState;\n const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);\n const { disableAutoFocus = false, freeform, inlinePopup } = props;\n const expandIconRef = React.useRef<HTMLSpanElement>(null);\n\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['children'],\n });\n\n const triggerRef = React.useRef<HTMLInputElement>(null);\n\n const listbox = useListboxSlot(props.listbox, useMergedRefs(comboboxPopupRef, activeDescendantListboxRef), {\n state: comboboxInternalState,\n triggerRef,\n defaultProps: {\n children: props.children,\n disableAutoFocus,\n },\n });\n\n const triggerSlot = useInputTriggerSlot(props.input ?? {}, useMergedRefs(triggerRef, activeParentRef, ref), {\n state: comboboxInternalState,\n freeform,\n defaultProps: {\n type: 'text',\n value: value ?? '',\n 'aria-controls': open ? listbox?.id : undefined,\n ...triggerNativeProps,\n },\n activeDescendantController,\n shouldCloseOnBlur: event => !expandIconRef.current || event.relatedTarget !== expandIconRef.current,\n });\n\n const rootSlot = slot.always(props.root, {\n defaultProps: {\n 'aria-owns': !inlinePopup && open ? listbox?.id : undefined,\n ...rootNativeProps,\n },\n elementType: 'div',\n });\n rootSlot.ref = useMergedRefs(rootSlot.ref, comboboxTargetRef);\n rootSlot.onBlur = mergeCallbacks(rootSlot.onBlur, event => {\n if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) {\n if (event.target !== event.currentTarget.querySelector('input')) {\n comboboxInternalState.setOpen(event as unknown as ComboboxOpenEvents, false);\n }\n comboboxInternalState.setHasFocus(false);\n }\n });\n\n const showClearIcon = selectedOptions.length > 0 && !disabled && clearable && !multiselect;\n const state: BaseComboboxState = {\n components: { root: 'div', input: 'input', expandIcon: 'span', listbox: Listbox, clearIcon: 'span' },\n root: rootSlot,\n input: triggerSlot,\n listbox: open || hasFocus ? listbox : undefined,\n clearIcon: slot.optional(props.clearIcon, {\n defaultProps: {\n 'aria-hidden': 'true',\n },\n elementType: 'span',\n renderByDefault: true,\n }),\n expandIcon: useComboboxExpandIconSlot(props.expandIcon, {\n disabled,\n hideFromTabOrder: showClearIcon,\n open,\n 'aria-label': props['aria-label'],\n 'aria-labelledby': props['aria-labelledby'],\n triggerLabelledBy: triggerSlot['aria-labelledby'],\n }),\n showClearIcon,\n activeDescendantController,\n ...baseState,\n };\n\n const { targetDocument } = useFluent();\n\n useOnClickOutside({\n element: targetDocument,\n callback: event => setOpen(event as unknown as ComboboxOpenEvents, false),\n refs: [triggerRef, comboboxPopupRef, comboboxTargetRef],\n disabled: !open,\n });\n\n /* handle open/close + focus change when clicking expandIcon */\n const { onMouseDown: onIconMouseDown } = state.expandIcon || {};\n\n const onExpandIconMouseDown = useEventCallback(\n // eslint-disable-next-line react-hooks/refs\n mergeCallbacks(onIconMouseDown, (event: React.MouseEvent<HTMLSpanElement>) => {\n event.preventDefault();\n if (!state.disabled) {\n state.setOpen(event, !state.open);\n }\n triggerRef.current?.focus();\n }),\n );\n\n const onExpandIconClick = useEventCallback(\n // eslint-disable-next-line react-hooks/refs\n mergeCallbacks(state.expandIcon?.onClick, (event: React.MouseEvent<HTMLSpanElement>) => {\n // Pointer clicks already toggle on mousedown; click-only activation has detail 0.\n if (event.detail === 0) {\n event.preventDefault();\n if (!state.disabled) {\n state.setOpen(event, !state.open);\n }\n triggerRef.current?.focus();\n }\n }),\n );\n\n const onExpandIconKeyDown = useEventCallback(\n // eslint-disable-next-line react-hooks/refs\n mergeCallbacks(state.expandIcon?.onKeyDown, event => {\n if (state.open && event.key === 'Escape') {\n event.preventDefault();\n event.stopPropagation();\n state.setOpen(event, false);\n triggerRef.current?.focus();\n return;\n }\n\n if (!state.disabled && (event.key === 'Enter' || event.key === ' ')) {\n event.preventDefault();\n state.setOpen(event, !state.open);\n triggerRef.current?.focus();\n }\n }),\n );\n const expandIconSlotRef = useMergedRefs(state.expandIcon?.ref, expandIconRef);\n\n if (state.expandIcon) {\n state.expandIcon.ref = expandIconSlotRef;\n state.expandIcon.onMouseDown = onExpandIconMouseDown;\n state.expandIcon.onClick = onExpandIconClick;\n state.expandIcon.onKeyDown = onExpandIconKeyDown;\n }\n\n const onClearIconMouseDown = useEventCallback(\n mergeCallbacks(state.clearIcon?.onMouseDown, (ev: React.MouseEvent<HTMLSpanElement>) => {\n ev.preventDefault();\n }),\n );\n const onClearIconClick = useEventCallback(\n mergeCallbacks(state.clearIcon?.onClick, (ev: React.MouseEvent<HTMLSpanElement>) => {\n clearSelection(ev);\n }),\n );\n\n if (state.clearIcon) {\n state.clearIcon.onMouseDown = onClearIconMouseDown;\n state.clearIcon.onClick = onClearIconClick;\n }\n\n // Heads up! We don't support \"clearable\" in multiselect mode, so we should never display a slot\n if (multiselect) {\n state.clearIcon = undefined;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- \"process.env\" does not change in runtime\n React.useEffect(() => {\n if (clearable && multiselect) {\n // eslint-disable-next-line no-console\n console.error(`[@fluentui/react-combobox] \"clearable\" prop is not supported in multiselect mode.`);\n }\n }, [clearable, multiselect]);\n }\n\n return state;\n};\n\n/**\n * Create the state required to render Combobox.\n *\n * The returned state can be modified with hooks such as useComboboxStyles_unstable,\n * before being passed to renderCombobox_unstable.\n *\n * @param props - props from this instance of Combobox\n * @param ref - reference to root HTMLElement of Combobox\n */\nexport const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLInputElement>): ComboboxState => {\n const fieldContext = useFieldContext_unstable();\n const { appearance = 'outline', size = fieldContext?.size ?? 'medium', ...baseProps } = props;\n const baseState = useComboboxBase_unstable(baseProps, ref);\n\n if (baseState.clearIcon) {\n baseState.clearIcon.children ??= <DismissIcon />;\n }\n\n if (baseState.expandIcon) {\n baseState.expandIcon.children ??= <ChevronDownIcon />;\n }\n\n return {\n ...baseState,\n appearance,\n size,\n input: {\n ...useTabsterEscapeIgnore(baseState.input, baseState.open),\n ...baseState.input,\n },\n };\n};\n"],"names":["React","useActiveDescendant","useFieldContext_unstable","useFieldControlProps_unstable","ChevronDownRegular","ChevronDownIcon","DismissRegular","DismissIcon","getPartitionedNativeProps","mergeCallbacks","useEventCallback","useMergedRefs","slot","useOnClickOutside","useFluent_unstable","useFluent","useComboboxBaseState","useComboboxPositioning","Listbox","useListboxSlot","useInputTriggerSlot","isComboboxOptionElement","useTabsterEscapeIgnore","useComboboxExpandIconSlot","useComboboxBase_unstable","props","ref","state","supportsLabelFor","supportsRequired","listboxRef","activeDescendantListboxRef","activeParentRef","controller","activeDescendantController","matchOption","comboboxInternalState","editable","appearance","_appearance","size","_size","baseState","clearable","clearSelection","disabled","multiselect","open","selectedOptions","setOpen","value","hasFocus","comboboxPopupRef","comboboxTargetRef","disableAutoFocus","freeform","inlinePopup","expandIconRef","useRef","primary","triggerNativeProps","root","rootNativeProps","primarySlotTagName","excludedPropNames","triggerRef","listbox","defaultProps","children","triggerSlot","input","type","id","undefined","shouldCloseOnBlur","event","current","relatedTarget","rootSlot","always","elementType","onBlur","currentTarget","contains","target","querySelector","setHasFocus","showClearIcon","length","components","expandIcon","clearIcon","optional","renderByDefault","hideFromTabOrder","triggerLabelledBy","targetDocument","element","callback","refs","onMouseDown","onIconMouseDown","onExpandIconMouseDown","preventDefault","focus","onExpandIconClick","onClick","detail","onExpandIconKeyDown","onKeyDown","key","stopPropagation","expandIconSlotRef","onClearIconMouseDown","ev","onClearIconClick","process","env","NODE_ENV","useEffect","console","error","useCombobox_unstable","fieldContext","baseProps"],"mappings":"AAAA;;;;;;;;;;;;IAqCawB,wBAAAA;;;wBA0MAkG;eAAAA;;;;iEA7OU,QAAQ;2BACK,uBAAuB;4BACa,wBAAwB;4BACX,wBAAwB;gCAQtG,4BAA4B;qCACa,kCAAkC;sCAC7C,sCAAmC;wCACjC,wCAAqC;yBACpD,wBAAqB;gCAQd,gCAA6B;qCACxB,2BAAwB;yCACpB,yCAAsC;wCACvC,wCAAqC;2CAClC,iCAA8B;AAQjE,iCAAiC,CACtCjG,OACAC;QAsHiBC,mBAcAA,oBAgBuBA,oBAUvBA,kBAKAA;IAjKjB,+CAA+C;IAC/CF,QAAQtB,6CAAAA,EAA8BsB,OAAO;QAAEG,kBAAkB;QAAMC,kBAAkB;IAAK;IAC9F,MAAM,EACJC,YAAYC,0BAA0B,EACtCC,eAAe,EACfC,YAAYC,0BAA0B,EACvC,OAAGjC,8BAAAA,EAAsD;QACxDkC,aAAad,gDAAAA;IACf;IACA,MAAMe,4BAAwBpB,0CAAAA,EAAqB;QAAE,GAAGS,KAAK;QAAEY,UAAU;QAAMH;IAA2B;IAC1G,MAAM,EAAEI,YAAYC,WAAW,EAAEC,MAAMC,KAAK,EAAE,GAAGC,WAAW,GAAGN;IAE/D,MAAM,EAAEO,SAAS,EAAEC,cAAc,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,IAAI,EAAEC,eAAe,EAAEC,OAAO,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GACzGT;IACF,MAAM,CAACU,kBA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eAAAA,KAAAA,IAAAA,aAArB1B,sBAAqB0B,QAAAA,GAAAA,WAAAA,GAAa,OAAA,aAAA,CAAC/D,8BAAAA,EAAAA;IACrC;IAEA,OAAO;QACL,GAAGqC,SAAS;QACZJ;QACAE;QACA8B,OAAO;YACL,OAAGhD,8CAAAA,EAAuBoB,UAAU4B,KAAK,EAAE5B,UAAUK,IAAI,CAAC;YAC1D,GAAGL,UAAU4B,KAAK;QACpB;IACF;AACF,EAAE"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useComboboxExpandIconSlot", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useComboboxExpandIconSlot;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _reactutilities = require("@fluentui/react-utilities");
|
|
12
|
+
function useComboboxExpandIconSlot(expandIconFromProps, options) {
|
|
13
|
+
const defaultExpandIconId = (0, _reactutilities.useId)('combobox-chevron-');
|
|
14
|
+
const { disabled, hideFromTabOrder, open, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, triggerLabelledBy } = options;
|
|
15
|
+
const expandIcon = _reactutilities.slot.optional(expandIconFromProps, {
|
|
16
|
+
renderByDefault: true,
|
|
17
|
+
defaultProps: {
|
|
18
|
+
'aria-disabled': disabled ? 'true' : undefined,
|
|
19
|
+
'aria-expanded': open,
|
|
20
|
+
role: 'button',
|
|
21
|
+
tabIndex: disabled ? -1 : 0
|
|
22
|
+
},
|
|
23
|
+
elementType: 'span'
|
|
24
|
+
});
|
|
25
|
+
if (!expandIcon) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
if (disabled || hideFromTabOrder) {
|
|
29
|
+
expandIcon.tabIndex = -1;
|
|
30
|
+
}
|
|
31
|
+
const hasExpandLabel = expandIcon['aria-label'] || expandIcon['aria-labelledby'];
|
|
32
|
+
if (!hasExpandLabel) {
|
|
33
|
+
if (triggerLabelledBy || ariaLabelledBy) {
|
|
34
|
+
var _expandIcon_id;
|
|
35
|
+
const expandIconId = (_expandIcon_id = expandIcon.id) !== null && _expandIcon_id !== void 0 ? _expandIcon_id : defaultExpandIconId;
|
|
36
|
+
expandIcon.id = expandIconId;
|
|
37
|
+
expandIcon['aria-labelledby'] = `${expandIcon.id} ${triggerLabelledBy !== null && triggerLabelledBy !== void 0 ? triggerLabelledBy : ariaLabelledBy}`.trim();
|
|
38
|
+
expandIcon['aria-label'] = 'Open';
|
|
39
|
+
} else if (ariaLabel) {
|
|
40
|
+
expandIcon['aria-label'] = `Open ${ariaLabel}`;
|
|
41
|
+
} else {
|
|
42
|
+
expandIcon['aria-label'] = 'Open';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return expandIcon;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Combobox/useComboboxExpandIconSlot.ts"],"sourcesContent":["import { slot, useId } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\n\ntype UseComboboxExpandIconSlotOptions = {\n /** Whether the combobox trigger is disabled. */\n disabled?: boolean;\n /** Whether the expand icon is visually hidden by the clear icon. */\n hideFromTabOrder?: boolean;\n /** Whether the listbox is currently open. */\n open: boolean;\n /** `aria-label` passed to the combobox. */\n 'aria-label'?: string;\n /** `aria-labelledby` passed to the combobox. */\n 'aria-labelledby'?: string;\n /** `aria-labelledby` of the resolved input trigger, used to build the labelling chain. */\n triggerLabelledBy?: string;\n};\n\n/**\n * Creates the `expandIcon` slot of a combobox: button semantics plus the default accessible name.\n *\n * @internal\n */\nexport function useComboboxExpandIconSlot(\n expandIconFromProps: Slot<'span'> | undefined | null,\n options: UseComboboxExpandIconSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'span'>>> | undefined {\n const defaultExpandIconId = useId('combobox-chevron-');\n const {\n disabled,\n hideFromTabOrder,\n open,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n triggerLabelledBy,\n } = options;\n const expandIcon = slot.optional(expandIconFromProps, {\n renderByDefault: true,\n defaultProps: {\n 'aria-disabled': disabled ? 'true' : undefined,\n 'aria-expanded': open,\n role: 'button',\n tabIndex: disabled ? -1 : 0,\n },\n elementType: 'span',\n });\n\n if (!expandIcon) {\n return undefined;\n }\n\n if (disabled || hideFromTabOrder) {\n expandIcon.tabIndex = -1;\n }\n\n const hasExpandLabel = expandIcon['aria-label'] || expandIcon['aria-labelledby'];\n\n if (!hasExpandLabel) {\n if (triggerLabelledBy || ariaLabelledBy) {\n const expandIconId = expandIcon.id ?? defaultExpandIconId;\n expandIcon.id = expandIconId;\n expandIcon['aria-labelledby'] = `${expandIcon.id} ${triggerLabelledBy ?? ariaLabelledBy}`.trim();\n expandIcon['aria-label'] = 'Open';\n } else if (ariaLabel) {\n expandIcon['aria-label'] = `Open ${ariaLabel}`;\n } else {\n expandIcon['aria-label'] = 'Open';\n }\n }\n\n return expandIcon;\n}\n"],"names":["slot","useId","useComboboxExpandIconSlot","expandIconFromProps","options","defaultExpandIconId","disabled","hideFromTabOrder","open","ariaLabel","ariaLabelledBy","triggerLabelledBy","expandIcon","optional","renderByDefault","defaultProps","undefined","role","tabIndex","elementType","hasExpandLabel","expandIconId","id","trim"],"mappings":";;;;+BAuBgBE;;;;;;gCAvBY,4BAA4B;AAuBjD,mCACLC,mBAAoD,EACpDC,OAAyC;IAEzC,MAAMC,0BAAsBJ,qBAAAA,EAAM;IAClC,MAAM,EACJK,QAAQ,EACRC,gBAAgB,EAChBC,IAAI,EACJ,cAAcC,SAAS,EACvB,mBAAmBC,cAAc,EACjCC,iBAAiB,EAClB,GAAGP;IACJ,MAAMQ,aAAaZ,oBAAAA,CAAKa,QAAQ,CAACV,qBAAqB;QACpDW,iBAAiB;QACjBC,cAAc;YACZ,iBAAiBT,WAAW,SAASU;YACrC,iBAAiBR;YACjBS,MAAM;YACNC,UAAUZ,WAAW,CAAC,IAAI;QAC5B;QACAa,aAAa;IACf;IAEA,IAAI,CAACP,YAAY;QACf,OAAOI;IACT;IAEA,IAAIV,YAAYC,kBAAkB;QAChCK,WAAWM,QAAQ,GAAG,CAAC;IACzB;IAEA,MAAME,iBAAiBR,UAAU,CAAC,aAAa,IAAIA,UAAU,CAAC,kBAAkB;IAEhF,IAAI,CAACQ,gBAAgB;QACnB,IAAIT,qBAAqBD,gBAAgB;gBAClBE;YAArB,MAAMS,eAAeT,CAAAA,iBAAAA,WAAWU,EAAAA,AAAE,MAAA,QAAbV,mBAAAA,KAAAA,IAAAA,iBAAiBP;YACtCO,WAAWU,EAAE,GAAGD;YAChBT,UAAU,CAAC,kBAAkB,GAAG,GAAGA,WAAWU,EAAE,CAAC,CAAC,EAAEX,sBAAAA,QAAAA,sBAAAA,KAAAA,IAAAA,oBAAqBD,gBAAgB,CAACa,IAAI;YAC9FX,UAAU,CAAC,aAAa,GAAG;QAC7B,OAAO,IAAIH,WAAW;YACpBG,UAAU,CAAC,aAAa,GAAG,CAAC,KAAK,EAAEH,WAAW;QAChD,OAAO;YACLG,UAAU,CAAC,aAAa,GAAG;QAC7B;IACF;IAEA,OAAOA;AACT"}
|
|
@@ -16,7 +16,7 @@ const _keyboardkeys = require("@fluentui/keyboard-keys");
|
|
|
16
16
|
const _useTriggerSlot = require("../../utils/useTriggerSlot.cjs");
|
|
17
17
|
const _dropdownKeyActions = require("../../utils/dropdownKeyActions.cjs");
|
|
18
18
|
function useInputTriggerSlot(triggerFromProps, ref, options) {
|
|
19
|
-
const { state: { open, value, selectOption, setValue, multiselect, selectedOptions, clearSelection, getOptionById, setOpen }, freeform, defaultProps, activeDescendantController } = options;
|
|
19
|
+
const { state: { open, value, selectOption, setValue, multiselect, selectedOptions, clearSelection, getOptionById, setOpen }, freeform, defaultProps, activeDescendantController, shouldCloseOnBlur } = options;
|
|
20
20
|
const onBlur = (event)=>{
|
|
21
21
|
// handle selection and updating value if freeform is false
|
|
22
22
|
if (!open && !freeform) {
|
|
@@ -63,7 +63,8 @@ function useInputTriggerSlot(triggerFromProps, ref, options) {
|
|
|
63
63
|
state: options.state,
|
|
64
64
|
defaultProps,
|
|
65
65
|
elementType: 'input',
|
|
66
|
-
activeDescendantController
|
|
66
|
+
activeDescendantController,
|
|
67
|
+
shouldCloseOnBlur
|
|
67
68
|
});
|
|
68
69
|
// eslint-disable-next-line react-hooks/immutability
|
|
69
70
|
trigger.onChange = (0, _reactutilities.mergeCallbacks)(trigger.onChange, onChange);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Combobox/useInputTriggerSlot.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { mergeCallbacks, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport type { ComboboxProps } from '../Combobox/Combobox.types';\nimport type { UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { useTriggerSlot } from '../../utils/useTriggerSlot';\nimport type { ComboboxBaseState } from '../../utils/ComboboxBase.types';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UsedComboboxState = UseTriggerSlotState &\n Pick<ComboboxBaseState, 'value' | 'setValue' | 'selectedOptions' | 'clearSelection' | 'getOptionById'>;\n\ntype UseInputTriggerSlotOptions = {\n state: UsedComboboxState;\n freeform: boolean | undefined;\n defaultProps?: Partial<ComboboxProps>;\n activeDescendantController: ActiveDescendantImperativeRef;\n};\n\n/**\n * useInputTriggerSlot returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n *\n * @internal\n */\nexport function useInputTriggerSlot(\n triggerFromProps: NonNullable<Slot<'input'>>,\n ref: React.Ref<HTMLInputElement>,\n options: UseInputTriggerSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'input'>>> {\n const {\n state: {\n open,\n value,\n selectOption,\n setValue,\n multiselect,\n selectedOptions,\n clearSelection,\n getOptionById,\n setOpen,\n },\n freeform,\n defaultProps,\n activeDescendantController,\n } = options;\n\n const onBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n // handle selection and updating value if freeform is false\n if (!open && !freeform) {\n const activeOptionId = activeDescendantController.active();\n const activeOption = activeOptionId ? getOptionById(activeOptionId) : null;\n // select matching option, if the value fully matches\n if (value && activeOption && value.trim().toLowerCase() === activeOption?.text.toLowerCase()) {\n selectOption(event, activeOption);\n }\n\n // reset typed value when the input loses focus while collapsed, unless freeform is true\n setValue(undefined);\n }\n };\n\n const getOptionFromInput = (inputValue: string): OptionValue | undefined => {\n const searchString = inputValue?.trim().toLowerCase();\n\n if (!searchString || searchString.length === 0) {\n activeDescendantController.blur();\n return;\n }\n\n const matcher = (optionText: string) => optionText.toLowerCase().indexOf(searchString) === 0;\n const match = activeDescendantController.find(id => {\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n });\n\n if (!match) {\n activeDescendantController.blur();\n return undefined;\n }\n\n return getOptionById(match);\n };\n\n // update value and active option based on input\n const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = event.target.value;\n // update uncontrolled value\n setValue(inputValue);\n\n // handle updating active option based on input\n const matchingOption = getOptionFromInput(inputValue);\n\n // clear selection for single-select if the input value no longer matches the selection\n if (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || !matchingOption)) {\n clearSelection(event);\n }\n };\n\n const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'input',\n activeDescendantController,\n });\n\n // eslint-disable-next-line react-hooks/immutability\n trigger.onChange = mergeCallbacks(trigger.onChange, onChange);\n // eslint-disable-next-line react-hooks/immutability\n trigger.onBlur = mergeCallbacks(trigger.onBlur, onBlur);\n\n // NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set\n // To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows\n // ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888\n const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);\n // save the typing vs. navigating options state, as the space key should behave differently in each case\n // we do not want to update the combobox when this changes, just save the value between renders\n const isTyping = React.useRef(false);\n\n /**\n * Freeform combobox should not select\n */\n const defaultOnKeyDown = trigger.onKeyDown;\n const onKeyDown = useEventCallback((event: React.KeyboardEvent<HTMLInputElement>) => {\n if (!open && getDropdownActionFromKey(event) === 'Type') {\n setOpen(event, true);\n }\n\n // clear activedescendant when moving the text insertion cursor\n if (event.key === ArrowLeft || event.key === ArrowRight) {\n setHideActiveDescendant(true);\n } else {\n setHideActiveDescendant(false);\n }\n\n // update typing state to true if the user is typing\n const action = getDropdownActionFromKey(event, { open, multiselect });\n if (action === 'Type') {\n isTyping.current = true;\n }\n // otherwise, update the typing state to false if opening or navigating dropdown options\n // other actions, like closing the dropdown, should not impact typing state.\n else if (\n (action === 'Open' && event.key !== ' ') ||\n action === 'Next' ||\n action === 'Previous' ||\n action === 'First' ||\n action === 'Last' ||\n action === 'PageUp' ||\n action === 'PageDown'\n ) {\n isTyping.current = false;\n }\n\n // allow space to insert a character if freeform & the last action was typing, or if the popup is closed\n if ((isTyping.current || !open) && event.key === ' ') {\n triggerFromProps?.onKeyDown?.(event);\n return;\n }\n\n defaultOnKeyDown?.(event);\n });\n\n // eslint-disable-next-line react-hooks/immutability\n trigger.onKeyDown = onKeyDown;\n\n if (hideActiveDescendant) {\n // eslint-disable-next-line react-hooks/immutability\n trigger['aria-activedescendant'] = undefined;\n }\n\n return trigger;\n}\n"],"names":["React","mergeCallbacks","useEventCallback","ArrowLeft","ArrowRight","useTriggerSlot","getDropdownActionFromKey","useInputTriggerSlot","triggerFromProps","ref","options","state","open","value","selectOption","setValue","multiselect","selectedOptions","clearSelection","getOptionById","setOpen","freeform","defaultProps","activeDescendantController","onBlur","event","activeOptionId","active","activeOption","trim","toLowerCase","text","undefined","getOptionFromInput","inputValue","searchString","length","blur","matcher","optionText","indexOf","match","find","id","option","onChange","target","matchingOption","trigger","elementType","hideActiveDescendant","setHideActiveDescendant","useState","isTyping","useRef","defaultOnKeyDown","onKeyDown","key","action","current"],"mappings":"AAAA;;;;;+BA+BgBO;;;;;;;iEA7BO,QAAQ;gCAEkB,4BAA4B;8BAEvC,0BAA0B;gCAGjC,gCAA6B;oCAGnB,oCAAiC;AAmBnE,6BACLC,gBAA4C,EAC5CC,GAAgC,EAChCC,OAAmC;IAEnC,MAAM,EACJC,OAAO,EACLC,IAAI,EACJC,KAAK,EACLC,YAAY,EACZC,QAAQ,EACRC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,aAAa,EACbC,OAAO,EACR,EACDC,QAAQ,EACRC,YAAY,EACZC,0BAA0B,EAC3B,GAAGb;IAEJ,MAAMc,SAAS,CAACC;QACd,2DAA2D;QAC3D,IAAI,CAACb,QAAQ,CAACS,UAAU;YACtB,MAAMK,iBAAiBH,2BAA2BI,MAAM;YACxD,MAAMC,eAAeF,iBAAiBP,cAAcO,kBAAkB;YACtE,qDAAqD;YACrD,IAAIb,SAASe,gBAAgBf,MAAMgB,IAAI,GAAGC,WAAW,QAAOF,iBAAAA,QAAAA,iBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,aAAcG,IAAI,CAACD,WAAW,EAAA,GAAI;gBAC5FhB,aAAaW,OAAOG;YACtB;YAEA,wFAAwF;YACxFb,SAASiB;QACX;IACF;IAEA,MAAMC,qBAAqB,CAACC;QAC1B,MAAMC,eAAeD,eAAAA,QAAAA,eAAAA,KAAAA,IAAAA,KAAAA,IAAAA,WAAYL,IAAI,GAAGC,WAAW;QAEnD,IAAI,CAACK,gBAAgBA,aAAaC,MAAM,KAAK,GAAG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,CAACuB;QAClC,IAAI,CAACb,YAAQN,4CAAAA,EAAyBmB,WAAW,QAAQ;YACvDL,QAAQK,OAAO;QACjB;QAEA,+DAA+D;QAC/D,IAAIA,MAAMgC,GAAG,KAAKtD,uBAAAA,IAAasB,MAAMgC,GAAG,KAAKrD,wBAAAA,EAAY;YACvD+C,wBAAwB;QAC1B,OAAO;YACLA,wBAAwB;QAC1B;QAEA,oDAAoD;QACpD,MAAMO,aAASpD,4CAAAA,EAAyBmB,OAAO;YAAEb;YAAMI;QAAY;QACnE,IAAI0C,WAAW,QAAQ;YACrBL,SAASM,OAAO,GAAG;QACrB,OAGK,IACFD,WAAW,UAAUjC,MAAMgC,GAAG,KAAK,OACpCC,WAAW,UACXA,WAAW,cACXA,WAAW,WACXA,WAAW,UACXA,WAAW,YACXA,WAAW,YACX;YACAL,SAASM,OAAO,GAAG;QACrB;QAEA,wGAAwG;QACxG,IAAKN,CAAAA,SAASM,OAAO,IAAI,CAAC/C,IAAAA,CAAG,IAAMa,MAAMgC,GAAG,KAAK,KAAK;gBACpDjD;YAAAA,qBAAAA,QAAAA,qBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,CAAAA,8BAAAA,iBAAkBgD,SAAAA,AAAS,MAAA,QAA3BhD,gCAAAA,KAAAA,IAAAA,KAAAA,IAAAA,4BAAAA,IAAAA,CAAAA,kBAA8BiB;YAC9B;QACF;QAEA8B,qBAAAA,QAAAA,qBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,iBAAmB9B;IACrB;IAEA,oDAAoD;IACpDuB,QAAQQ,SAAS,GAAGA;IAEpB,IAAIN,sBAAsB;QACxB,oDAAoD;QACpDF,OAAO,CAAC,wBAAwB,GAAGhB;IACrC;IAEA,OAAOgB;AACT"}
|
|
1
|
+
{"version":3,"sources":["../src/components/Combobox/useInputTriggerSlot.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { mergeCallbacks, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport type { ComboboxProps } from '../Combobox/Combobox.types';\nimport type { UseTriggerSlotOptions, UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { useTriggerSlot } from '../../utils/useTriggerSlot';\nimport type { ComboboxBaseState } from '../../utils/ComboboxBase.types';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UsedComboboxState = UseTriggerSlotState &\n Pick<ComboboxBaseState, 'value' | 'setValue' | 'selectedOptions' | 'clearSelection' | 'getOptionById'>;\n\ntype UseInputTriggerSlotOptions = {\n state: UsedComboboxState;\n freeform: boolean | undefined;\n defaultProps?: Partial<ComboboxProps>;\n activeDescendantController: ActiveDescendantImperativeRef;\n shouldCloseOnBlur?: UseTriggerSlotOptions['shouldCloseOnBlur'];\n};\n\n/**\n * useInputTriggerSlot returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n *\n * @internal\n */\nexport function useInputTriggerSlot(\n triggerFromProps: NonNullable<Slot<'input'>>,\n ref: React.Ref<HTMLInputElement>,\n options: UseInputTriggerSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'input'>>> {\n const {\n state: {\n open,\n value,\n selectOption,\n setValue,\n multiselect,\n selectedOptions,\n clearSelection,\n getOptionById,\n setOpen,\n },\n freeform,\n defaultProps,\n activeDescendantController,\n shouldCloseOnBlur,\n } = options;\n\n const onBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n // handle selection and updating value if freeform is false\n if (!open && !freeform) {\n const activeOptionId = activeDescendantController.active();\n const activeOption = activeOptionId ? getOptionById(activeOptionId) : null;\n // select matching option, if the value fully matches\n if (value && activeOption && value.trim().toLowerCase() === activeOption?.text.toLowerCase()) {\n selectOption(event, activeOption);\n }\n\n // reset typed value when the input loses focus while collapsed, unless freeform is true\n setValue(undefined);\n }\n };\n\n const getOptionFromInput = (inputValue: string): OptionValue | undefined => {\n const searchString = inputValue?.trim().toLowerCase();\n\n if (!searchString || searchString.length === 0) {\n activeDescendantController.blur();\n return;\n }\n\n const matcher = (optionText: string) => optionText.toLowerCase().indexOf(searchString) === 0;\n const match = activeDescendantController.find(id => {\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n });\n\n if (!match) {\n activeDescendantController.blur();\n return undefined;\n }\n\n return getOptionById(match);\n };\n\n // update value and active option based on input\n const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = event.target.value;\n // update uncontrolled value\n setValue(inputValue);\n\n // handle updating active option based on input\n const matchingOption = getOptionFromInput(inputValue);\n\n // clear selection for single-select if the input value no longer matches the selection\n if (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || !matchingOption)) {\n clearSelection(event);\n }\n };\n\n const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'input',\n activeDescendantController,\n shouldCloseOnBlur,\n });\n\n // eslint-disable-next-line react-hooks/immutability\n trigger.onChange = mergeCallbacks(trigger.onChange, onChange);\n // eslint-disable-next-line react-hooks/immutability\n trigger.onBlur = mergeCallbacks(trigger.onBlur, onBlur);\n\n // NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set\n // To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows\n // ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888\n const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);\n // save the typing vs. navigating options state, as the space key should behave differently in each case\n // we do not want to update the combobox when this changes, just save the value between renders\n const isTyping = React.useRef(false);\n\n /**\n * Freeform combobox should not select\n */\n const defaultOnKeyDown = trigger.onKeyDown;\n const onKeyDown = useEventCallback((event: React.KeyboardEvent<HTMLInputElement>) => {\n if (!open && getDropdownActionFromKey(event) === 'Type') {\n setOpen(event, true);\n }\n\n // clear activedescendant when moving the text insertion cursor\n if (event.key === ArrowLeft || event.key === ArrowRight) {\n setHideActiveDescendant(true);\n } else {\n setHideActiveDescendant(false);\n }\n\n // update typing state to true if the user is typing\n const action = getDropdownActionFromKey(event, { open, multiselect });\n if (action === 'Type') {\n isTyping.current = true;\n }\n // otherwise, update the typing state to false if opening or navigating dropdown options\n // other actions, like closing the dropdown, should not impact typing state.\n else if (\n (action === 'Open' && event.key !== ' ') ||\n action === 'Next' ||\n action === 'Previous' ||\n action === 'First' ||\n action === 'Last' ||\n action === 'PageUp' ||\n action === 'PageDown'\n ) {\n isTyping.current = false;\n }\n\n // allow space to insert a character if freeform & the last action was typing, or if the popup is closed\n if ((isTyping.current || !open) && event.key === ' ') {\n triggerFromProps?.onKeyDown?.(event);\n return;\n }\n\n defaultOnKeyDown?.(event);\n });\n\n // eslint-disable-next-line react-hooks/immutability\n trigger.onKeyDown = onKeyDown;\n\n if (hideActiveDescendant) {\n // eslint-disable-next-line react-hooks/immutability\n trigger['aria-activedescendant'] = undefined;\n }\n\n return trigger;\n}\n"],"names":["React","mergeCallbacks","useEventCallback","ArrowLeft","ArrowRight","useTriggerSlot","getDropdownActionFromKey","useInputTriggerSlot","triggerFromProps","ref","options","state","open","value","selectOption","setValue","multiselect","selectedOptions","clearSelection","getOptionById","setOpen","freeform","defaultProps","activeDescendantController","shouldCloseOnBlur","onBlur","event","activeOptionId","active","activeOption","trim","toLowerCase","text","undefined","getOptionFromInput","inputValue","searchString","length","blur","matcher","optionText","indexOf","match","find","id","option","onChange","target","matchingOption","trigger","elementType","hideActiveDescendant","setHideActiveDescendant","useState","isTyping","useRef","defaultOnKeyDown","onKeyDown","key","action","current"],"mappings":"AAAA;;;;;+BAgCgBO;;;;;;;iEA9BO,QAAQ;gCAEkB,4BAA4B;8BAEvC,0BAA0B;gCAGjC,gCAA6B;oCAGnB,oCAAiC;AAoBnE,6BACLC,gBAA4C,EAC5CC,GAAgC,E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AAG,KAAK,OACpCC,WAAW,UACXA,WAAW,cACXA,WAAW,WACXA,WAAW,UACXA,WAAW,YACXA,WAAW,YACX;YACAL,SAASM,OAAO,GAAG;QACrB;QAEA,wGAAwG;QACxG,IAAKN,CAAAA,SAASM,OAAO,IAAI,CAAChD,IAAAA,CAAG,IAAMc,MAAMgC,GAAG,KAAK,KAAK;gBACpDlD;YAAAA,qBAAAA,QAAAA,qBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,CAAAA,8BAAAA,iBAAkBiD,SAAAA,AAAS,MAAA,QAA3BjD,gCAAAA,KAAAA,IAAAA,KAAAA,IAAAA,4BAAAA,IAAAA,CAAAA,kBAA8BkB;YAC9B;QACF;QAEA8B,qBAAAA,QAAAA,qBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,iBAAmB9B;IACrB;IAEA,oDAAoD;IACpDuB,QAAQQ,SAAS,GAAGA;IAEpB,IAAIN,sBAAsB;QACxB,oDAAoD;QACpDF,OAAO,CAAC,wBAAwB,GAAGhB;IACrC;IAEA,OAAOgB;AACT"}
|
package/lib-commonjs/index.cjs
CHANGED
|
@@ -76,6 +76,9 @@ _export(exports, {
|
|
|
76
76
|
useComboboxContextValues: function() {
|
|
77
77
|
return _useComboboxContextValues.useComboboxContextValues;
|
|
78
78
|
},
|
|
79
|
+
useComboboxExpandIconSlot: function() {
|
|
80
|
+
return _useComboboxExpandIconSlot.useComboboxExpandIconSlot;
|
|
81
|
+
},
|
|
79
82
|
useComboboxFilter: function() {
|
|
80
83
|
return _useComboboxFilter.useComboboxFilter;
|
|
81
84
|
},
|
|
@@ -141,5 +144,6 @@ const _useComboboxFilter = require("./hooks/useComboboxFilter.cjs");
|
|
|
141
144
|
const _useComboboxBaseState = require("./utils/useComboboxBaseState.cjs");
|
|
142
145
|
const _useButtonTriggerSlot = require("./components/Dropdown/useButtonTriggerSlot.cjs");
|
|
143
146
|
const _useInputTriggerSlot = require("./components/Combobox/useInputTriggerSlot.cjs");
|
|
147
|
+
const _useComboboxExpandIconSlot = require("./components/Combobox/useComboboxExpandIconSlot.cjs");
|
|
144
148
|
const _useListboxSlot = require("./utils/useListboxSlot.cjs");
|
|
145
149
|
const _isComboboxOptionElement = require("./utils/isComboboxOptionElement.cjs");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport { ComboboxProvider } from './contexts/ComboboxContext';\nexport type { ComboboxContextValue } from './contexts/ComboboxContext';\nexport { ListboxProvider, useListboxContext_unstable } from './contexts/ListboxContext';\nexport type { ListboxContextValue } from './contexts/ListboxContext';\nexport { useComboboxContextValues } from './contexts/useComboboxContextValues';\nexport { useListboxContextValues } from './contexts/useListboxContextValues';\nexport {\n Listbox,\n listboxClassNames,\n renderListbox_unstable,\n useListboxStyles_unstable,\n useListbox_unstable,\n} from './Listbox';\nexport type { ListboxContextValues, ListboxProps, ListboxSlots, ListboxState } from './Listbox';\nexport {\n Option,\n optionClassNames,\n renderOption_unstable,\n useOptionStyles_unstable,\n useOption_unstable,\n useOptionBase_unstable,\n} from './Option';\nexport type { OptionProps, OptionSlots, OptionState } from './Option';\nexport {\n Combobox,\n comboboxClassNames,\n renderCombobox_unstable,\n useComboboxStyles_unstable,\n useComboboxBase_unstable,\n useCombobox_unstable,\n} from './Combobox';\nexport type {\n BaseComboboxProps,\n BaseComboboxState,\n ComboboxContextValues,\n ComboboxOpenChangeData,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxSlots,\n ComboboxState,\n} from './Combobox';\nexport {\n Dropdown,\n dropdownClassNames,\n renderDropdown_unstable,\n useDropdownStyles_unstable,\n useDropdownBase_unstable,\n useDropdown_unstable,\n} from './Dropdown';\nexport type {\n DropdownBaseHookProps,\n DropdownBaseHookState,\n DropdownContextValues,\n DropdownOpenChangeData,\n DropdownOpenEvents,\n DropdownProps,\n DropdownSlots,\n DropdownState,\n} from './Dropdown';\nexport {\n OptionGroup,\n optionGroupClassNames,\n renderOptionGroup_unstable,\n useOptionGroupStyles_unstable,\n useOptionGroup_unstable,\n} from './OptionGroup';\nexport type { OptionGroupProps, OptionGroupSlots, OptionGroupState } from './OptionGroup';\nexport type { OptionOnSelectData, SelectionEvents } from './Selection';\n\nexport { useComboboxFilter } from './hooks/useComboboxFilter';\n\n// internals splitting the combobox logic into state hook and slot hooks\nexport { useComboboxBaseState } from './utils/useComboboxBaseState';\nexport { useButtonTriggerSlot } from './components/Dropdown/useButtonTriggerSlot';\nexport { useInputTriggerSlot } from './components/Combobox/useInputTriggerSlot';\nexport { useListboxSlot } from './utils/useListboxSlot';\nexport type { ComboboxBaseState, ComboboxBaseProps } from './utils/ComboboxBase.types';\nexport { isComboboxOptionElement } from './utils/isComboboxOptionElement';\n"],"names":["ComboboxProvider","ListboxProvider","useListboxContext_unstable","useComboboxContextValues","useListboxContextValues","Listbox","listboxClassNames","renderListbox_unstable","useListboxStyles_unstable","useListbox_unstable","Option","optionClassNames","renderOption_unstable","useOptionStyles_unstable","useOption_unstable","useOptionBase_unstable","Combobox","comboboxClassNames","renderCombobox_unstable","useComboboxStyles_unstable","useComboboxBase_unstable","useCombobox_unstable","Dropdown","dropdownClassNames","renderDropdown_unstable","useDropdownStyles_unstable","useDropdownBase_unstable","useDropdown_unstable","OptionGroup","optionGroupClassNames","renderOptionGroup_unstable","useOptionGroupStyles_unstable","useOptionGroup_unstable","useComboboxFilter","useComboboxBaseState","useButtonTriggerSlot","useInputTriggerSlot","useListboxSlot","isComboboxOptionElement"],"mappings":"AAAA,4DAA4D
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport { ComboboxProvider } from './contexts/ComboboxContext';\nexport type { ComboboxContextValue } from './contexts/ComboboxContext';\nexport { ListboxProvider, useListboxContext_unstable } from './contexts/ListboxContext';\nexport type { ListboxContextValue } from './contexts/ListboxContext';\nexport { useComboboxContextValues } from './contexts/useComboboxContextValues';\nexport { useListboxContextValues } from './contexts/useListboxContextValues';\nexport {\n Listbox,\n listboxClassNames,\n renderListbox_unstable,\n useListboxStyles_unstable,\n useListbox_unstable,\n} from './Listbox';\nexport type { ListboxContextValues, ListboxProps, ListboxSlots, ListboxState } from './Listbox';\nexport {\n Option,\n optionClassNames,\n renderOption_unstable,\n useOptionStyles_unstable,\n useOption_unstable,\n useOptionBase_unstable,\n} from './Option';\nexport type { OptionProps, OptionSlots, OptionState } from './Option';\nexport {\n Combobox,\n comboboxClassNames,\n renderCombobox_unstable,\n useComboboxStyles_unstable,\n useComboboxBase_unstable,\n useCombobox_unstable,\n} from './Combobox';\nexport type {\n BaseComboboxProps,\n BaseComboboxState,\n ComboboxContextValues,\n ComboboxOpenChangeData,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxSlots,\n ComboboxState,\n} from './Combobox';\nexport {\n Dropdown,\n dropdownClassNames,\n renderDropdown_unstable,\n useDropdownStyles_unstable,\n useDropdownBase_unstable,\n useDropdown_unstable,\n} from './Dropdown';\nexport type {\n DropdownBaseHookProps,\n DropdownBaseHookState,\n DropdownContextValues,\n DropdownOpenChangeData,\n DropdownOpenEvents,\n DropdownProps,\n DropdownSlots,\n DropdownState,\n} from './Dropdown';\nexport {\n OptionGroup,\n optionGroupClassNames,\n renderOptionGroup_unstable,\n useOptionGroupStyles_unstable,\n useOptionGroup_unstable,\n} from './OptionGroup';\nexport type { OptionGroupProps, OptionGroupSlots, OptionGroupState } from './OptionGroup';\nexport type { OptionOnSelectData, SelectionEvents } from './Selection';\n\nexport { useComboboxFilter } from './hooks/useComboboxFilter';\n\n// internals splitting the combobox logic into state hook and slot hooks\nexport { useComboboxBaseState } from './utils/useComboboxBaseState';\nexport { useButtonTriggerSlot } from './components/Dropdown/useButtonTriggerSlot';\nexport { useInputTriggerSlot } from './components/Combobox/useInputTriggerSlot';\nexport { useComboboxExpandIconSlot } from './components/Combobox/useComboboxExpandIconSlot';\nexport { useListboxSlot } from './utils/useListboxSlot';\nexport type { ComboboxBaseState, ComboboxBaseProps } from './utils/ComboboxBase.types';\nexport { isComboboxOptionElement } from './utils/isComboboxOptionElement';\n"],"names":["ComboboxProvider","ListboxProvider","useListboxContext_unstable","useComboboxContextValues","useListboxContextValues","Listbox","listboxClassNames","renderListbox_unstable","useListboxStyles_unstable","useListbox_unstable","Option","optionClassNames","renderOption_unstable","useOptionStyles_unstable","useOption_unstable","useOptionBase_unstable","Combobox","comboboxClassNames","renderCombobox_unstable","useComboboxStyles_unstable","useComboboxBase_unstable","useCombobox_unstable","Dropdown","dropdownClassNames","renderDropdown_unstable","useDropdownStyles_unstable","useDropdownBase_unstable","useDropdown_unstable","OptionGroup","optionGroupClassNames","renderOptionGroup_unstable","useOptionGroupStyles_unstable","useOptionGroup_unstable","useComboboxFilter","useComboboxBaseState","useButtonTriggerSlot","useInputTriggerSlot","useComboboxExpandIconSlot","useListboxSlot","isComboboxOptionElement"],"mappings":"AAAA,4DAA4D;;;;;;;;;;;;IAyB1DgB;iCAAQ;;IAxBDhB;gDAAgB;;;eA0CvBsB,kBAAQ;;;eAnCRjB,gBAAO;;;eALAJ,+BAAe;;;eAatBS,cAAM;;IA6CNkB,WAAW;;;;eAnCXX,4BAAkB;;IAkBlBM,kBAAkB;;;IAmCXgB;+DAAuB;;IAtE9BjC,iBAAiB;;;oBAQD;eAAhBK;;;eA6CAkB,kCAAqB;;;eAnCrBX,iCAAuB;;IAkBvBM,uBAAuB;;;0BAnCD;eAAtBjB;;IAqDAuB;sDAA0B;;;eA7C1BlB,6BAAqB;;IAwDduB;yDAAoB;;IADpBD,oBAAoB;;;;eA5C3Bd,kCAAwB;;;eAxBjBjB,kDAAwB;;;eAuExBkC,oDAAyB;;IANzBJ;mDAAiB;;;eA1CxBd,oCAA0B;;wBAEN;eAApBE;;IAiBAK,wBAAwB;;;;eADxBD,oCAA0B;;;eAE1BE,8BAAoB;;;eA2BbS,wCAAmB;;;eArEnBhC,gDAAuB;;;eAHNF,0CAA0B;;;eA0E3CoC,8BAAc;;;eAlErB9B,kCAAyB;;;eACzBC,4BAAmB;;;eASnBM,8BAAsB;;;eA2CtBgB,0CAA6B;;;eAC7BC,oCAAuB;;;eA9CvBnB,gCAAwB;;;eACxBC,0BAAkB;;;iCAnBa,gCAA6B;gCAEF,+BAA4B;0CAE/C,yCAAsC;yCACvC,wCAAqC;yBAOtE,eAAY;wBASZ,cAAW;0BASX,gBAAa;0BAkBb,gBAAa;6BAiBb,mBAAgB;mCAIW,+BAA4B;sCAGzB,kCAA+B;sCAC/B,gDAA6C;qCAC9C,+CAA4C;2CACtC,qDAAkD;gCAC7D,4BAAyB;yCAEhB,qCAAkC"}
|
|
@@ -105,7 +105,7 @@ const useComboboxBaseState = (props)=>{
|
|
|
105
105
|
initialState: false
|
|
106
106
|
});
|
|
107
107
|
const setOpen = _react.useCallback((event, newState)=>{
|
|
108
|
-
if (disabled) {
|
|
108
|
+
if (disabled || newState === open) {
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
111
|
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
|
|
@@ -118,11 +118,12 @@ const useComboboxBaseState = (props)=>{
|
|
|
118
118
|
setOpenState(newState);
|
|
119
119
|
});
|
|
120
120
|
}, [
|
|
121
|
+
disabled,
|
|
122
|
+
freeform,
|
|
121
123
|
onOpenChange,
|
|
124
|
+
open,
|
|
122
125
|
setOpenState,
|
|
123
|
-
setValue
|
|
124
|
-
freeform,
|
|
125
|
-
disabled
|
|
126
|
+
setValue
|
|
126
127
|
]);
|
|
127
128
|
// update active option based on change in open state
|
|
128
129
|
_react.useEffect(()=>{
|