@fluentui/react-combobox 9.9.0 → 9.9.2
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 +39 -2
- package/dist/index.d.ts +3 -0
- package/lib/components/Combobox/useInputTriggerSlot.js +2 -1
- package/lib/components/Combobox/useInputTriggerSlot.js.map +1 -1
- package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
- package/lib/components/Dropdown/useButtonTriggerSlot.js +2 -1
- package/lib/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
- package/lib/components/Listbox/Listbox.types.js.map +1 -1
- package/lib/components/OptionGroup/OptionGroup.types.js +3 -1
- package/lib/components/OptionGroup/OptionGroup.types.js.map +1 -1
- package/lib/hooks/useComboboxFilter.js +3 -1
- package/lib/hooks/useComboboxFilter.js.map +1 -1
- package/lib/utils/OptionCollection.types.js.map +1 -1
- package/lib/utils/useComboboxBaseState.js +1 -0
- package/lib/utils/useComboboxBaseState.js.map +1 -1
- package/lib/utils/useListboxSlot.js +1 -0
- package/lib/utils/useListboxSlot.js.map +1 -1
- package/lib-commonjs/components/Combobox/useInputTriggerSlot.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useButtonTriggerSlot.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/OptionGroup.types.js +3 -1
- package/lib-commonjs/components/OptionGroup/OptionGroup.types.js.map +1 -1
- package/lib-commonjs/contexts/ListboxContext.js +3 -3
- package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
- package/lib-commonjs/hooks/useComboboxFilter.js.map +1 -1
- package/lib-commonjs/index.js +48 -48
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
- package/lib-commonjs/utils/useListboxSlot.js.map +1 -1
- package/package.json +12 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,49 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-combobox
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 15 Mar 2024 21:37:57 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.9.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.9.2)
|
|
8
|
+
|
|
9
|
+
Fri, 15 Mar 2024 21:37:57 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.9.1..@fluentui/react-combobox_v9.9.2)
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- Bump @fluentui/react-aria to v9.10.1 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
|
15
|
+
- Bump @fluentui/react-context-selector to v9.1.55 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
|
16
|
+
- Bump @fluentui/react-field to v9.1.57 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
|
17
|
+
- Bump @fluentui/react-jsx-runtime to v9.0.33 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
|
18
|
+
- Bump @fluentui/react-portal to v9.4.17 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
|
19
|
+
- Bump @fluentui/react-positioning to v9.14.1 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
|
20
|
+
- Bump @fluentui/react-shared-contexts to v9.15.1 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
|
21
|
+
- Bump @fluentui/react-tabster to v9.19.4 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
|
22
|
+
- Bump @fluentui/react-theme to v9.1.18 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
|
23
|
+
- Bump @fluentui/react-utilities to v9.18.4 ([PR #30740](https://github.com/microsoft/fluentui/pull/30740) by beachball)
|
|
24
|
+
|
|
25
|
+
## [9.9.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.9.1)
|
|
26
|
+
|
|
27
|
+
Thu, 07 Mar 2024 19:33:21 GMT
|
|
28
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.9.0..@fluentui/react-combobox_v9.9.1)
|
|
29
|
+
|
|
30
|
+
### Patches
|
|
31
|
+
|
|
32
|
+
- chore: remove invalid peerDependency on scheduler ([PR #30587](https://github.com/microsoft/fluentui/pull/30587) by olfedias@microsoft.com)
|
|
33
|
+
- Bump @fluentui/react-aria to v9.10.0 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
|
34
|
+
- Bump @fluentui/react-context-selector to v9.1.54 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
|
35
|
+
- Bump @fluentui/react-field to v9.1.56 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
|
36
|
+
- Bump @fluentui/react-jsx-runtime to v9.0.32 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
|
37
|
+
- Bump @fluentui/react-portal to v9.4.16 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
|
38
|
+
- Bump @fluentui/react-positioning to v9.14.0 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
|
39
|
+
- Bump @fluentui/react-shared-contexts to v9.15.0 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
|
40
|
+
- Bump @fluentui/react-tabster to v9.19.3 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
|
41
|
+
- Bump @fluentui/react-theme to v9.1.17 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
|
42
|
+
- Bump @fluentui/react-utilities to v9.18.3 ([PR #30687](https://github.com/microsoft/fluentui/pull/30687) by beachball)
|
|
43
|
+
|
|
7
44
|
## [9.9.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.9.0)
|
|
8
45
|
|
|
9
|
-
Wed, 28 Feb 2024 02:
|
|
46
|
+
Wed, 28 Feb 2024 02:34:17 GMT
|
|
10
47
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.8.0..@fluentui/react-combobox_v9.9.0)
|
|
11
48
|
|
|
12
49
|
### Minor changes
|
package/dist/index.d.ts
CHANGED
|
@@ -459,6 +459,9 @@ export declare const useCombobox_unstable: (props: ComboboxProps, ref: React_2.R
|
|
|
459
459
|
|
|
460
460
|
export declare function useComboboxContextValues(state: ComboboxBaseState & Pick<ComboboxState, 'activeDescendantController'>): ComboboxBaseContextValues;
|
|
461
461
|
|
|
462
|
+
/**
|
|
463
|
+
* @internal
|
|
464
|
+
*/
|
|
462
465
|
export declare function useComboboxFilter<T extends {
|
|
463
466
|
children: React_2.ReactNode;
|
|
464
467
|
value: string;
|
|
@@ -3,7 +3,8 @@ import { mergeCallbacks, useEventCallback } from '@fluentui/react-utilities';
|
|
|
3
3
|
import { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';
|
|
4
4
|
import { useTriggerSlot } from '../../utils/useTriggerSlot';
|
|
5
5
|
import { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
7
8
|
* useInputTriggerSlot returns a tuple of trigger/listbox shorthand,
|
|
8
9
|
* with the semantics and event handlers needed for the Combobox and Dropdown components.
|
|
9
10
|
* The element type of the ref should always match the element type used in the trigger shorthand.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useInputTriggerSlot.ts"],"sourcesContent":["import * 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 { useTriggerSlot, UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { ComboboxProps, ComboboxState } from './Combobox.types';\nimport { OptionValue } from '../../utils/OptionCollection.types';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UsedComboboxState = UseTriggerSlotState &\n Pick<ComboboxState, '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
|
|
1
|
+
{"version":3,"sources":["useInputTriggerSlot.ts"],"sourcesContent":["import * 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 { useTriggerSlot, UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { ComboboxProps, ComboboxState } from './Combobox.types';\nimport { OptionValue } from '../../utils/OptionCollection.types';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UsedComboboxState = UseTriggerSlotState &\n Pick<ComboboxState, '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 * @internal\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 */\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 = (ev: 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(ev, 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 = (ev: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = ev.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(ev);\n }\n };\n\n const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'input',\n activeDescendantController,\n });\n\n trigger.onChange = mergeCallbacks(trigger.onChange, onChange);\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((ev: React.KeyboardEvent<HTMLInputElement>) => {\n if (!open && getDropdownActionFromKey(ev) === 'Type') {\n setOpen(ev, true);\n }\n\n // clear activedescendant when moving the text insertion cursor\n if (ev.key === ArrowLeft || ev.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(ev, { 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' && ev.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) && ev.key === ' ') {\n triggerFromProps?.onKeyDown?.(ev);\n return;\n }\n\n defaultOnKeyDown?.(ev);\n });\n\n trigger.onKeyDown = onKeyDown;\n\n if (hideActiveDescendant) {\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","ev","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","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YAAEb;YAAMI;QAAY;QAChE,IAAI0C,WAAW,QAAQ;YACrBL,SAASM,OAAO,GAAG;QACrB,OAGK,IACH,AAACD,WAAW,UAAUjC,GAAGgC,GAAG,KAAK,OACjCC,WAAW,UACXA,WAAW,cACXA,WAAW,WACXA,WAAW,UACXA,WAAW,YACXA,WAAW,YACX;YACAL,SAASM,OAAO,GAAG;QACrB;QAEA,wGAAwG;QACxG,IAAI,AAACN,CAAAA,SAASM,OAAO,IAAI,CAAC/C,IAAG,KAAMa,GAAGgC,GAAG,KAAK,KAAK;gBACjDjD;YAAAA,6BAAAA,wCAAAA,8BAAAA,iBAAkBgD,SAAS,cAA3BhD,kDAAAA,iCAAAA,kBAA8BiB;YAC9B;QACF;QAEA8B,6BAAAA,uCAAAA,iBAAmB9B;IACrB;IAEAuB,QAAQQ,SAAS,GAAGA;IAEpB,IAAIN,sBAAsB;QACxBF,OAAO,CAAC,wBAAwB,GAAGhB;IACrC;IAEA,OAAOgB;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Dropdown.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport type {\n ComboboxBaseContextValues,\n ComboboxBaseOpenChangeData,\n ComboboxBaseOpenEvents,\n ComboboxBaseProps,\n ComboboxBaseState,\n} from '../../utils/ComboboxBase.types';\nimport { Listbox } from '../Listbox/Listbox';\n\nexport type DropdownSlots = {\n /* The root dropdown slot */\n root: NonNullable<Slot<'div'>>;\n\n /* The dropdown arrow icon */\n expandIcon?: Slot<'span'>;\n\n /* The dropdown clear icon */\n clearButton?: Slot<'button'>;\n\n /* The primary slot, the element with role=\"combobox\" */\n button: NonNullable<Slot<'button'>>;\n\n /* The dropdown listbox slot */\n listbox?: Slot<typeof Listbox>;\n};\n\n/**\n * Dropdown Props\n */\nexport type DropdownProps = ComponentProps<Partial<DropdownSlots>, 'button'> & ComboboxBaseProps;\n\n/**\n * State used in rendering Dropdown\n */\nexport type DropdownState = ComponentState<DropdownSlots> &\n ComboboxBaseState & {\n /* Whether the placeholder is currently displayed */\n placeholderVisible: boolean;\n\n showClearButton?: boolean;\n\n activeDescendantController: ActiveDescendantImperativeRef;\n };\n\n/* Export types defined in ComboboxBase */\nexport type DropdownContextValues = ComboboxBaseContextValues;\nexport type DropdownOpenEvents = ComboboxBaseOpenEvents;\nexport type DropdownOpenChangeData = ComboboxBaseOpenChangeData;\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["Dropdown.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport type {\n ComboboxBaseContextValues,\n ComboboxBaseOpenChangeData,\n ComboboxBaseOpenEvents,\n ComboboxBaseProps,\n ComboboxBaseState,\n} from '../../utils/ComboboxBase.types';\nimport { Listbox } from '../Listbox/Listbox';\n\nexport type DropdownSlots = {\n /* The root dropdown slot */\n root: NonNullable<Slot<'div'>>;\n\n /* The dropdown arrow icon */\n expandIcon?: Slot<'span'>;\n\n /* The dropdown clear icon */\n clearButton?: Slot<'button'>;\n\n /* The primary slot, the element with role=\"combobox\" */\n button: NonNullable<Slot<'button'>>;\n\n /* The dropdown listbox slot */\n listbox?: Slot<typeof Listbox>;\n};\n\n/**\n * Dropdown Props\n */\nexport type DropdownProps = ComponentProps<Partial<DropdownSlots>, 'button'> & ComboboxBaseProps;\n\n/**\n * State used in rendering Dropdown\n */\nexport type DropdownState = ComponentState<DropdownSlots> &\n ComboboxBaseState & {\n /* Whether the placeholder is currently displayed */\n placeholderVisible: boolean;\n\n showClearButton?: boolean;\n\n activeDescendantController: ActiveDescendantImperativeRef;\n };\n\n/* Export types defined in ComboboxBase */\nexport type DropdownContextValues = ComboboxBaseContextValues;\nexport type DropdownOpenEvents = ComboboxBaseOpenEvents;\nexport type DropdownOpenChangeData = ComboboxBaseOpenChangeData;\n"],"names":[],"mappings":"AAiDA,WAAgE"}
|
|
@@ -2,7 +2,8 @@ import * as React from 'react';
|
|
|
2
2
|
import { useTimeout, mergeCallbacks } from '@fluentui/react-utilities';
|
|
3
3
|
import { useTriggerSlot } from '../../utils/useTriggerSlot';
|
|
4
4
|
import { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
6
7
|
* useButtonTriggerSlot returns a tuple of trigger/listbox shorthand,
|
|
7
8
|
* with the semantics and event handlers needed for the Combobox and Dropdown components.
|
|
8
9
|
* The element type of the ref should always match the element type used in the trigger shorthand.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useButtonTriggerSlot.ts"],"sourcesContent":["import * as React from 'react';\nimport { useTimeout, mergeCallbacks } from '@fluentui/react-utilities';\nimport type { Slot, ExtractSlotProps, SlotComponentType } from '@fluentui/react-utilities';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { useTriggerSlot, UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UseButtonTriggerSlotOptions = {\n state: UseTriggerSlotState;\n defaultProps: unknown;\n activeDescendantController: ActiveDescendantImperativeRef;\n};\n\n
|
|
1
|
+
{"version":3,"sources":["useButtonTriggerSlot.ts"],"sourcesContent":["import * as React from 'react';\nimport { useTimeout, mergeCallbacks } from '@fluentui/react-utilities';\nimport type { Slot, ExtractSlotProps, SlotComponentType } from '@fluentui/react-utilities';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { useTriggerSlot, UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UseButtonTriggerSlotOptions = {\n state: UseTriggerSlotState;\n defaultProps: unknown;\n activeDescendantController: ActiveDescendantImperativeRef;\n};\n\n/**\n * @internal\n * useButtonTriggerSlot 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 */\nexport function useButtonTriggerSlot(\n triggerFromProps: NonNullable<Slot<'button'>>,\n ref: React.Ref<HTMLButtonElement>,\n options: UseButtonTriggerSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'button'>>> {\n const {\n state: { open, setOpen, getOptionById },\n defaultProps,\n activeDescendantController,\n } = options;\n\n // jump to matching option based on typing\n const searchString = React.useRef('');\n const [setKeyTimeout, clearKeyTimeout] = useTimeout();\n\n const moveToNextMatchingOption = (\n matcher: (optionText: string) => boolean,\n opt: { startFromNext: boolean } = { startFromNext: false },\n ) => {\n const { startFromNext } = opt;\n const activeOptionId = activeDescendantController.active();\n\n const nextInOrder = activeDescendantController.find(\n id => {\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n },\n { startFrom: startFromNext ? activeDescendantController.next({ passive: true }) : activeOptionId },\n );\n\n if (nextInOrder) {\n return nextInOrder;\n }\n\n // Cycle back to first match\n return activeDescendantController.find(id => {\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n });\n };\n\n const moveToNextMatchingOptionWithSameCharacterHandling = () => {\n if (\n moveToNextMatchingOption(\n optionText => {\n return optionText.toLocaleLowerCase().indexOf(searchString.current) === 0;\n },\n {\n // Slowly pressing the same key will cycle through options\n startFromNext: searchString.current.length === 1,\n },\n )\n ) {\n return;\n }\n\n // if there are no direct matches, check if the search is all the same letter, e.g. \"aaa\"\n if (\n allCharactersSame(searchString.current) &&\n moveToNextMatchingOption(\n optionText => {\n return optionText.toLocaleLowerCase().indexOf(searchString.current[0]) === 0;\n },\n {\n // if the search is all the same letter, cycle through options starting with that letter\n startFromNext: true,\n },\n )\n ) {\n return;\n }\n\n activeDescendantController.blur();\n };\n\n const onTriggerKeyDown = (ev: React.KeyboardEvent<HTMLButtonElement>) => {\n // clear timeout, if it exists\n clearKeyTimeout();\n\n // if the key was a char key, update search string\n if (getDropdownActionFromKey(ev) === 'Type') {\n // update search string\n searchString.current += ev.key.toLowerCase();\n setKeyTimeout(() => {\n searchString.current = '';\n }, 500);\n\n // update state\n !open && setOpen(ev, true);\n moveToNextMatchingOptionWithSameCharacterHandling();\n }\n };\n\n const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'button',\n activeDescendantController,\n });\n trigger.onKeyDown = mergeCallbacks(onTriggerKeyDown, trigger.onKeyDown);\n\n return trigger;\n}\n\n/**\n * @returns - whether every character in the string is the same\n */\nfunction allCharactersSame(str: string) {\n for (let i = 1; i < str.length; i++) {\n if (str[i] !== str[i - 1]) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":["React","useTimeout","mergeCallbacks","useTriggerSlot","getDropdownActionFromKey","useButtonTriggerSlot","triggerFromProps","ref","options","state","open","setOpen","getOptionById","defaultProps","activeDescendantController","searchString","useRef","setKeyTimeout","clearKeyTimeout","moveToNextMatchingOption","matcher","opt","startFromNext","activeOptionId","active","nextInOrder","find","id","option","text","startFrom","next","passive","moveToNextMatchingOptionWithSameCharacterHandling","optionText","toLocaleLowerCase","indexOf","current","length","allCharactersSame","blur","onTriggerKeyDown","ev","key","toLowerCase","trigger","elementType","onKeyDown","str","i"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,UAAU,EAAEC,cAAc,QAAQ,4BAA4B;AAGvE,SAASC,cAAc,QAA6B,6BAA6B;AACjF,SAASC,wBAAwB,QAAQ,iCAAiC;AAQ1E;;;;;CAKC,GACD,OAAO,SAASC,qBACdC,gBAA6C,EAC7CC,GAAiC,EACjCC,OAAoC;IAEpC,MAAM,EACJC,OAAO,EAAEC,IAAI,EAAEC,OAAO,EAAEC,aAAa,EAAE,EACvCC,YAAY,EACZC,0BAA0B,EAC3B,GAAGN;IAEJ,0CAA0C;IAC1C,MAAMO,eAAef,MAAMgB,MAAM,CAAC;IAClC,MAAM,CAACC,eAAeC,gBAAgB,GAAGjB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AAG;YAEH,eAAe;YACf,CAAC3B,QAAQC,QAAQ+B,IAAI;YACrBT;QACF;IACF;IAEA,MAAMY,UAAU1C,eAAeG,kBAAkBC,KAAK;QACpDE,OAAOD,QAAQC,KAAK;QACpBI;QACAiC,aAAa;QACbhC;IACF;IACA+B,QAAQE,SAAS,GAAG7C,eAAeuC,kBAAkBI,QAAQE,SAAS;IAEtE,OAAOF;AACT;AAEA;;CAEC,GACD,SAASN,kBAAkBS,GAAW;IACpC,IAAK,IAAIC,IAAI,GAAGA,IAAID,IAAIV,MAAM,EAAEW,IAAK;QACnC,IAAID,GAAG,CAACC,EAAE,KAAKD,GAAG,CAACC,IAAI,EAAE,EAAE;YACzB,OAAO;QACT;IACF;IAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Listbox.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { ActiveDescendantContextValue, ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { OptionValue, OptionCollectionState } from '../../utils/OptionCollection.types';\nimport { SelectionEvents, SelectionProps, SelectionState } from '../../utils/Selection.types';\nimport type { ListboxContextValue } from '../../contexts/ListboxContext';\n\nexport type ListboxSlots = {\n /* The root slot, a `<div>` with `role=\"listbox\"` */\n root: Slot<'div'>;\n};\n\n/**\n * Listbox Props\n */\nexport type ListboxProps = ComponentProps<ListboxSlots> & SelectionProps;\n\n/**\n * State used in rendering Listbox\n */\nexport type ListboxState = ComponentState<ListboxSlots> &\n OptionCollectionState &\n Pick<SelectionProps, 'multiselect'> &\n SelectionState & {\n /**\n * @deprecated - no longer used internally\n * @see activeDescendantController.active()\n */\n activeOption?: OptionValue;\n\n /**\n * @deprecated - no longer used internally\n */\n focusVisible: boolean;\n\n /**\n * @deprecated - no longer used internally\n * @see activeDescendantController.focus(id)\n */\n setActiveOption(option?: OptionValue): void;\n\n selectOption(event: SelectionEvents, option: OptionValue): void;\n\n activeDescendantController: ActiveDescendantImperativeRef;\n };\n\nexport type ListboxContextValues = {\n listbox: ListboxContextValue;\n activeDescendant: ActiveDescendantContextValue;\n};\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["Listbox.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { ActiveDescendantContextValue, ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { OptionValue, OptionCollectionState } from '../../utils/OptionCollection.types';\nimport { SelectionEvents, SelectionProps, SelectionState } from '../../utils/Selection.types';\nimport type { ListboxContextValue } from '../../contexts/ListboxContext';\n\nexport type ListboxSlots = {\n /* The root slot, a `<div>` with `role=\"listbox\"` */\n root: Slot<'div'>;\n};\n\n/**\n * Listbox Props\n */\nexport type ListboxProps = ComponentProps<ListboxSlots> & SelectionProps;\n\n/**\n * State used in rendering Listbox\n */\nexport type ListboxState = ComponentState<ListboxSlots> &\n OptionCollectionState &\n Pick<SelectionProps, 'multiselect'> &\n SelectionState & {\n /**\n * @deprecated - no longer used internally\n * @see activeDescendantController.active()\n */\n activeOption?: OptionValue;\n\n /**\n * @deprecated - no longer used internally\n */\n focusVisible: boolean;\n\n /**\n * @deprecated - no longer used internally\n * @see activeDescendantController.focus(id)\n */\n setActiveOption(option?: OptionValue): void;\n\n selectOption(event: SelectionEvents, option: OptionValue): void;\n\n activeDescendantController: ActiveDescendantImperativeRef;\n };\n\nexport type ListboxContextValues = {\n listbox: ListboxContextValue;\n activeDescendant: ActiveDescendantContextValue;\n};\n"],"names":[],"mappings":"AA6CA,WAGE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["OptionGroup.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\nexport type OptionGroupSlots = {\n /* The root group wrapper */\n root: NonNullable<Slot<'div'>>;\n\n /*\n * The option group label, displayed as static text before the child options.\n * If not using label, it's recommended to set `aria-label` directly on the OptionGroup instead.\n */\n label?: Slot<'span'>;\n};\n\n/**\n * OptionGroup Props\n */\nexport type OptionGroupProps = ComponentProps<Partial<OptionGroupSlots>>;\n\n/**\n * State used in rendering OptionGroup\n */\nexport type OptionGroupState = ComponentState<OptionGroupSlots>;\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["OptionGroup.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\nexport type OptionGroupSlots = {\n /* The root group wrapper */\n root: NonNullable<Slot<'div'>>;\n\n /*\n * The option group label, displayed as static text before the child options.\n * If not using label, it's recommended to set `aria-label` directly on the OptionGroup instead.\n */\n label?: Slot<'span'>;\n};\n\n/**\n * OptionGroup Props\n */\nexport type OptionGroupProps = ComponentProps<Partial<OptionGroupSlots>>;\n\n/**\n * State used in rendering OptionGroup\n */\nexport type OptionGroupState = ComponentState<OptionGroupSlots>;\n"],"names":[],"mappings":"AAkBA;;CAEC,GACD,WAAgE"}
|
|
@@ -9,7 +9,9 @@ function defaultFilter(optionText, query) {
|
|
|
9
9
|
function defaultToString(option) {
|
|
10
10
|
return typeof option === 'string' ? option : option.value;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/ export function useComboboxFilter(query, options, config) {
|
|
13
15
|
const { filter = defaultFilter, noOptionsMessage = "We couldn't find any matches.", optionToReactKey = defaultToString, optionToText = defaultToString, renderOption = (option)=>{
|
|
14
16
|
if (typeof option === 'string') {
|
|
15
17
|
return /*#__PURE__*/ React.createElement(Option, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useComboboxFilter.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Option } from '../Option';\n\ntype UseComboboxFilterConfig<T extends { children: React.ReactNode; value: string } | string> = {\n /** Provides a custom filter for the option. */\n filter?: (optionText: string, query: string) => boolean;\n\n /** Provides a custom message to display when there are no options. */\n noOptionsMessage?: React.ReactNode;\n\n /** Provides a way to map an option object to a React key. By default, \"value\" is used. */\n optionToReactKey?: (option: T) => string;\n\n /** Provides a way to map an option object to a text used for search. By default, \"value\" is used. */\n optionToText?: (option: T) => string;\n\n /** Provides a custom render for the option. */\n renderOption?: (option: T) => JSX.Element;\n};\n\nfunction defaultFilter(optionText: string, query: string) {\n if (query === '') {\n return true;\n }\n\n return optionText.toLowerCase().includes(query.toLowerCase());\n}\n\nfunction defaultToString(option: string | { value: string }) {\n return typeof option === 'string' ? option : option.value;\n}\n\nexport function useComboboxFilter<T extends { children: React.ReactNode; value: string } | string>(\n query: string,\n options: T[],\n config: UseComboboxFilterConfig<T>,\n) {\n const {\n filter = defaultFilter,\n noOptionsMessage = \"We couldn't find any matches.\",\n optionToReactKey = defaultToString,\n optionToText = defaultToString,\n\n renderOption = (option: T) => {\n if (typeof option === 'string') {\n return <Option key={option}>{option}</Option>;\n }\n\n return (\n <Option {...option} key={optionToReactKey(option)} text={optionToText(option)} value={option.value}>\n {option.children}\n </Option>\n );\n },\n } = config;\n\n const filteredOptions = React.useMemo(() => {\n const searchValue = query.trim();\n\n return options.filter(option => filter(optionToText(option), searchValue));\n }, [options, optionToText, filter, query]);\n\n if (filteredOptions.length === 0) {\n return [\n <Option aria-disabled=\"true\" key=\"no-results\" text=\"\">\n {noOptionsMessage}\n </Option>,\n ];\n }\n\n return filteredOptions.map(option => renderOption(option));\n}\n"],"names":["React","Option","defaultFilter","optionText","query","toLowerCase","includes","defaultToString","option","value","useComboboxFilter","options","config","filter","noOptionsMessage","optionToReactKey","optionToText","renderOption","key","text","children","filteredOptions","useMemo","searchValue","trim","length","aria-disabled","map"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,MAAM,QAAQ,YAAY;AAmBnC,SAASC,cAAcC,UAAkB,EAAEC,KAAa;IACtD,IAAIA,UAAU,IAAI;QAChB,OAAO;IACT;IAEA,OAAOD,WAAWE,WAAW,GAAGC,QAAQ,CAACF,MAAMC,WAAW;AAC5D;AAEA,SAASE,gBAAgBC,MAAkC;IACzD,OAAO,OAAOA,WAAW,WAAWA,SAASA,OAAOC,KAAK;AAC3D;AAEA,OAAO,SAASC,kBACdN,KAAa,EACbO,OAAY,EACZC,MAAkC;IAElC,MAAM,EACJC,SAASX,aAAa,EACtBY,mBAAmB,+BAA+B,EAClDC,mBAAmBR,eAAe,EAClCS,eAAeT,eAAe,EAE9BU,eAAe,CAACT;QACd,IAAI,OAAOA,WAAW,UAAU;YAC9B,qBAAO,oBAACP;gBAAOiB,KAAKV;eAASA;QAC/B;QAEA,qBACE,oBAACP;YAAQ,GAAGO,MAAM;YAAEU,KAAKH,iBAAiBP;YAASW,MAAMH,aAAaR;YAASC,OAAOD,OAAOC,KAAK;WAC/FD,OAAOY,QAAQ;IAGtB,CAAC,EACF,GAAGR;IAEJ,MAAMS,kBAAkBrB,MAAMsB,OAAO,CAAC;QACpC,MAAMC,cAAcnB,MAAMoB,IAAI;QAE9B,OAAOb,QAAQE,MAAM,CAACL,CAAAA,SAAUK,OAAOG,aAAaR,SAASe;IAC/D,GAAG;QAACZ;QAASK;QAAcH;QAAQT;KAAM;IAEzC,IAAIiB,gBAAgBI,MAAM,KAAK,GAAG;QAChC,OAAO;0BACL,oBAACxB;gBAAOyB,iBAAc;gBAAOR,KAAI;gBAAaC,MAAK;eAChDL;SAEJ;IACH;IAEA,OAAOO,gBAAgBM,GAAG,CAACnB,CAAAA,SAAUS,aAAaT;AACpD"}
|
|
1
|
+
{"version":3,"sources":["useComboboxFilter.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Option } from '../Option';\n\ntype UseComboboxFilterConfig<T extends { children: React.ReactNode; value: string } | string> = {\n /** Provides a custom filter for the option. */\n filter?: (optionText: string, query: string) => boolean;\n\n /** Provides a custom message to display when there are no options. */\n noOptionsMessage?: React.ReactNode;\n\n /** Provides a way to map an option object to a React key. By default, \"value\" is used. */\n optionToReactKey?: (option: T) => string;\n\n /** Provides a way to map an option object to a text used for search. By default, \"value\" is used. */\n optionToText?: (option: T) => string;\n\n /** Provides a custom render for the option. */\n renderOption?: (option: T) => JSX.Element;\n};\n\nfunction defaultFilter(optionText: string, query: string) {\n if (query === '') {\n return true;\n }\n\n return optionText.toLowerCase().includes(query.toLowerCase());\n}\n\nfunction defaultToString(option: string | { value: string }) {\n return typeof option === 'string' ? option : option.value;\n}\n\n/**\n * @internal\n */\nexport function useComboboxFilter<T extends { children: React.ReactNode; value: string } | string>(\n query: string,\n options: T[],\n config: UseComboboxFilterConfig<T>,\n) {\n const {\n filter = defaultFilter,\n noOptionsMessage = \"We couldn't find any matches.\",\n optionToReactKey = defaultToString,\n optionToText = defaultToString,\n\n renderOption = (option: T) => {\n if (typeof option === 'string') {\n return <Option key={option}>{option}</Option>;\n }\n\n return (\n <Option {...option} key={optionToReactKey(option)} text={optionToText(option)} value={option.value}>\n {option.children}\n </Option>\n );\n },\n } = config;\n\n const filteredOptions = React.useMemo(() => {\n const searchValue = query.trim();\n\n return options.filter(option => filter(optionToText(option), searchValue));\n }, [options, optionToText, filter, query]);\n\n if (filteredOptions.length === 0) {\n return [\n <Option aria-disabled=\"true\" key=\"no-results\" text=\"\">\n {noOptionsMessage}\n </Option>,\n ];\n }\n\n return filteredOptions.map(option => renderOption(option));\n}\n"],"names":["React","Option","defaultFilter","optionText","query","toLowerCase","includes","defaultToString","option","value","useComboboxFilter","options","config","filter","noOptionsMessage","optionToReactKey","optionToText","renderOption","key","text","children","filteredOptions","useMemo","searchValue","trim","length","aria-disabled","map"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,MAAM,QAAQ,YAAY;AAmBnC,SAASC,cAAcC,UAAkB,EAAEC,KAAa;IACtD,IAAIA,UAAU,IAAI;QAChB,OAAO;IACT;IAEA,OAAOD,WAAWE,WAAW,GAAGC,QAAQ,CAACF,MAAMC,WAAW;AAC5D;AAEA,SAASE,gBAAgBC,MAAkC;IACzD,OAAO,OAAOA,WAAW,WAAWA,SAASA,OAAOC,KAAK;AAC3D;AAEA;;CAEC,GACD,OAAO,SAASC,kBACdN,KAAa,EACbO,OAAY,EACZC,MAAkC;IAElC,MAAM,EACJC,SAASX,aAAa,EACtBY,mBAAmB,+BAA+B,EAClDC,mBAAmBR,eAAe,EAClCS,eAAeT,eAAe,EAE9BU,eAAe,CAACT;QACd,IAAI,OAAOA,WAAW,UAAU;YAC9B,qBAAO,oBAACP;gBAAOiB,KAAKV;eAASA;QAC/B;QAEA,qBACE,oBAACP;YAAQ,GAAGO,MAAM;YAAEU,KAAKH,iBAAiBP;YAASW,MAAMH,aAAaR;YAASC,OAAOD,OAAOC,KAAK;WAC/FD,OAAOY,QAAQ;IAGtB,CAAC,EACF,GAAGR;IAEJ,MAAMS,kBAAkBrB,MAAMsB,OAAO,CAAC;QACpC,MAAMC,cAAcnB,MAAMoB,IAAI;QAE9B,OAAOb,QAAQE,MAAM,CAACL,CAAAA,SAAUK,OAAOG,aAAaR,SAASe;IAC/D,GAAG;QAACZ;QAASK;QAAcH;QAAQT;KAAM;IAEzC,IAAIiB,gBAAgBI,MAAM,KAAK,GAAG;QAChC,OAAO;0BACL,oBAACxB;gBAAOyB,iBAAc;gBAAOR,KAAI;gBAAaC,MAAK;eAChDL;SAEJ;IACH;IAEA,OAAOO,gBAAgBM,GAAG,CAACnB,CAAAA,SAAUS,aAAaT;AACpD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["OptionCollection.types.ts"],"sourcesContent":["export type OptionValue = {\n /** The disabled state of the option. */\n disabled?: boolean;\n\n /** The `id` attribute of the option. */\n id: string;\n\n /** The `text` string for the option. */\n text: string;\n\n /** The value string of the option. */\n value: string;\n};\n\nexport type OptionCollectionState = {\n /**\n * @deprecated - no longer used internally\n */\n getIndexOfId(id: string): number;\n\n /**\n * @deprecated - no longer used internally\n */\n getOptionAtIndex(index: number): OptionValue | undefined;\n\n /**\n * @deprecated - no longer used internally\n */\n getOptionsMatchingText(matcher: (text: string) => boolean): OptionValue[];\n\n /** The total number of options in the collection. */\n getCount: () => number;\n\n /** Returns the option data by key. */\n getOptionById(id: string): OptionValue | undefined;\n\n /** Returns an array of options filtered by a value matching function against the option's value string. */\n getOptionsMatchingValue(matcher: (value: string) => boolean): OptionValue[];\n\n /** The unordered option data. */\n options: OptionValue[];\n\n /* A function that child options call to register their values. Returns a function to unregister the option. */\n registerOption: (option: OptionValue, element: HTMLElement) => () => void;\n};\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["OptionCollection.types.ts"],"sourcesContent":["export type OptionValue = {\n /** The disabled state of the option. */\n disabled?: boolean;\n\n /** The `id` attribute of the option. */\n id: string;\n\n /** The `text` string for the option. */\n text: string;\n\n /** The value string of the option. */\n value: string;\n};\n\nexport type OptionCollectionState = {\n /**\n * @deprecated - no longer used internally\n */\n getIndexOfId(id: string): number;\n\n /**\n * @deprecated - no longer used internally\n */\n getOptionAtIndex(index: number): OptionValue | undefined;\n\n /**\n * @deprecated - no longer used internally\n */\n getOptionsMatchingText(matcher: (text: string) => boolean): OptionValue[];\n\n /** The total number of options in the collection. */\n getCount: () => number;\n\n /** Returns the option data by key. */\n getOptionById(id: string): OptionValue | undefined;\n\n /** Returns an array of options filtered by a value matching function against the option's value string. */\n getOptionsMatchingValue(matcher: (value: string) => boolean): OptionValue[];\n\n /** The unordered option data. */\n options: OptionValue[];\n\n /* A function that child options call to register their values. Returns a function to unregister the option. */\n registerOption: (option: OptionValue, element: HTMLElement) => () => void;\n};\n"],"names":[],"mappings":"AAcA,WA8BE"}
|
|
@@ -3,6 +3,7 @@ import { useControllableState, useEventCallback, useFirstMount } from '@fluentui
|
|
|
3
3
|
import { useOptionCollection } from '../utils/useOptionCollection';
|
|
4
4
|
import { useSelection } from '../utils/useSelection';
|
|
5
5
|
/**
|
|
6
|
+
* @internal
|
|
6
7
|
* State shared between Combobox and Dropdown components
|
|
7
8
|
*/ export const useComboboxBaseState = (props)=>{
|
|
8
9
|
const { appearance = 'outline', children, clearable = false, editable = false, inlinePopup = false, mountNode = undefined, multiselect, onOpenChange, size = 'medium', activeDescendantController } = props;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useComboboxBaseState.ts"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState, useEventCallback, useFirstMount } from '@fluentui/react-utilities';\nimport { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { useOptionCollection } from '../utils/useOptionCollection';\nimport { OptionValue } from '../utils/OptionCollection.types';\nimport { useSelection } from '../utils/useSelection';\nimport type { ComboboxBaseProps, ComboboxBaseOpenEvents, ComboboxBaseState } from './ComboboxBase.types';\n\n/**\n * State shared between Combobox and Dropdown components\n */\nexport const useComboboxBaseState = (\n props: ComboboxBaseProps & {\n children?: React.ReactNode;\n editable?: boolean;\n activeDescendantController: ActiveDescendantImperativeRef;\n },\n): ComboboxBaseState => {\n const {\n appearance = 'outline',\n children,\n clearable = false,\n editable = false,\n inlinePopup = false,\n mountNode = undefined,\n multiselect,\n onOpenChange,\n size = 'medium',\n activeDescendantController,\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 const selectionState = useSelection(props);\n const { selectedOptions } = selectionState;\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 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, props.defaultValue, 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 onOpenChange?.(event, { open: newState });\n setOpenState(newState);\n },\n [onOpenChange, setOpenState],\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 or children\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) {\n if (!activeDescendantController.active()) {\n activeDescendantController.first();\n }\n }\n // this should only be run in response to changes in the open state or children\n }, [open, children, activeDescendantController]);\n\n return {\n ...optionCollection,\n ...selectionState,\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 };\n};\n"],"names":["React","useControllableState","useEventCallback","useFirstMount","useOptionCollection","useSelection","useComboboxBaseState","props","appearance","children","clearable","editable","inlinePopup","mountNode","undefined","multiselect","onOpenChange","size","activeDescendantController","optionCollection","getOptionsMatchingValue","getOptionById","getActiveOption","useCallback","activeOptionId","active","UNSAFE_activeOption","UNSAFE_setActiveOption","option","nextOption","activeOption","focus","id","blur","focusVisible","setFocusVisible","useState","hasFocus","setHasFocus","ignoreNextBlur","useRef","selectionState","selectedOptions","isFirstMount","controllableValue","setValue","state","value","initialState","useMemo","defaultValue","selectedOptionsText","optionValue","includes","map","text","join","open","setOpenState","defaultState","defaultOpen","setOpen","event","newState","useEffect","length","selectedOption","v","pop","first","setActiveOption","onOptionClick","e"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,oBAAoB,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAElG,SAASC,mBAAmB,QAAQ,+BAA+B;AAEnE,SAASC,YAAY,QAAQ,wBAAwB;AAGrD;;CAEC,GACD,OAAO,MAAMC,uBAAuB,CAClCC;IAMA,MAAM,EACJC,aAAa,SAAS,EACtBC,QAAQ,EACRC,YAAY,KAAK,EACj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YACLd,2BAA2Be,IAAI;QACjC;IACA,+EAA+E;IAC/E,uDAAuD;IACzD,GAAG;QAACwB;QAAMvC;KAA2B;IAErC,+FAA+F;IAC/FlB,MAAMgE,SAAS,CAAC;QACd,IAAIP,MAAM;YACR,IAAI,CAACvC,2BAA2BO,MAAM,IAAI;gBACxCP,2BAA2BmD,KAAK;YAClC;QACF;IACA,+EAA+E;IACjF,GAAG;QAACZ;QAAMhD;QAAUS;KAA2B;IAE/C,OAAO;QACL,GAAGC,gBAAgB;QACnB,GAAGsB,cAAc;QACjBX,cAAcJ;QACdlB;QACAE;QACAwB;QACAK;QACA3B;QACAC;QACA4C;QACApB;QACAiC,iBAAiB3C;QACjBQ;QACAG;QACAuB;QACAhB;QACA5B;QACA8B;QACAhC;QACAwD,eAAerE,iBAAiB,CAACsE;YAC/B,IAAI,CAACzD,aAAa;gBAChB8C,QAAQW,GAAG;YACb;QACF;IACF;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["useComboboxBaseState.ts"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState, useEventCallback, useFirstMount } from '@fluentui/react-utilities';\nimport { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { useOptionCollection } from '../utils/useOptionCollection';\nimport { OptionValue } from '../utils/OptionCollection.types';\nimport { useSelection } from '../utils/useSelection';\nimport type { ComboboxBaseProps, ComboboxBaseOpenEvents, ComboboxBaseState } from './ComboboxBase.types';\n\n/**\n * @internal\n * State shared between Combobox and Dropdown components\n */\nexport const useComboboxBaseState = (\n props: ComboboxBaseProps & {\n children?: React.ReactNode;\n editable?: boolean;\n activeDescendantController: ActiveDescendantImperativeRef;\n },\n): ComboboxBaseState => {\n const {\n appearance = 'outline',\n children,\n clearable = false,\n editable = false,\n inlinePopup = false,\n mountNode = undefined,\n multiselect,\n onOpenChange,\n size = 'medium',\n activeDescendantController,\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 const selectionState = useSelection(props);\n const { selectedOptions } = selectionState;\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 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, props.defaultValue, 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 onOpenChange?.(event, { open: newState });\n setOpenState(newState);\n },\n [onOpenChange, setOpenState],\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 or children\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) {\n if (!activeDescendantController.active()) {\n activeDescendantController.first();\n }\n }\n // this should only be run in response to changes in the open state or children\n }, [open, children, activeDescendantController]);\n\n return {\n ...optionCollection,\n ...selectionState,\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 };\n};\n"],"names":["React","useControllableState","useEventCallback","useFirstMount","useOptionCollection","useSelection","useComboboxBaseState","props","appearance","children","clearable","editable","inlinePopup","mountNode","undefined","multiselect","onOpenChange","size","activeDescendantController","optionCollection","getOptionsMatchingValue","getOptionById","getActiveOption","useCallback","activeOptionId","active","UNSAFE_activeOption","UNSAFE_setActiveOption","option","nextOption","activeOption","focus","id","blur","focusVisible","setFocusVisible","useState","hasFocus","setHasFocus","ignoreNextBlur","useRef","selectionState","selectedOptions","isFirstMount","controllableValue","setValue","state","value","initialState","useMemo","defaultValue","selectedOptionsText","optionValue","includes","map","text","join","open","setOpenState","defaultState","defaultOpen","setOpen","event","newState","useEffect","length","selectedOption","v","pop","first","setActiveOption","onOptionClick","e"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,oBAAoB,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAElG,SAASC,mBAAmB,QAAQ,+BAA+B;AAEnE,SAASC,YAAY,QAAQ,wBAAwB;AAGrD;;;CAGC,GACD,OAAO,MAAMC,uBAAuB,CAClCC;IAMA,MAAM,EACJC,aAAa,SAAS,EACtBC,QAAQ,EACRC,YAAY,KAAK,EACjBC,WAAW,KAAK,EAChBC,cAAc,KAAK,EACnBC,YAAYC,SAAS,EACrBC,WAAW,EACXC,YAAY,EACZC,OAAO,QAAQ,EACfC,0BAA0B,EAC3B,GAAGX;IAEJ,MAAMY,mBAAmBf;IACzB,MAAM,EAAEgB,uBAAuB,EAAE,GAAGD;IAEpC,MAAM,EAAEE,aAAa,EAAE,GAAGF;IAC1B,MAAMG,kBAAkBtB,MAAMuB,WAAW,CAAC;QACxC,MAAMC,iBAAiBN,2BAA2BO,MAAM;QACxD,OAAOD,iBAAiBH,cAAcG,kBAAkBV;IAC1D,GAAG;QAACI;QAA4BG;KAAc;IAE9C,+DAA+D;IAC/D,gEAAgE;IAChE,MAAMK,sBAAsBJ;IAC5B,gEAAgE;IAChE,MAAMK,yBAAyB3B,MAAMuB,WAAW,CAC9C,CAACK;QACC,IAAIC,aAAsCf;QAC1C,IAAI,OAAOc,WAAW,YAAY;YAChC,MAAME,eAAeR;YACrBO,aAAaD,OAAOE;QACtB;QAEA,IAAID,YAAY;YACdX,2BAA2Ba,KAAK,CAACF,WAAWG,EAAE;QAChD,OAAO;YACLd,2BAA2Be,IA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cAAc;IAChB;IAEA,MAAMa,UAAU7D,MAAMuB,WAAW,CAC/B,CAACuC,OAA+BC;QAC9B/C,yBAAAA,mCAAAA,aAAe8C,OAAO;YAAEL,MAAMM;QAAS;QACvCL,aAAaK;IACf,GACA;QAAC/C;QAAc0C;KAAa;IAG9B,qDAAqD;IACrD1D,MAAMgE,SAAS,CAAC;QACd,IAAIP,MAAM;YACR,sFAAsF;YACtF,IAAI,CAAC1C,eAAe2B,gBAAgBuB,MAAM,GAAG,GAAG;gBAC9C,MAAMC,iBAAiB9C,wBAAwB+C,CAAAA,IAAKA,MAAMzB,eAAe,CAAC,EAAE,EAAE0B,GAAG;gBACjF,IAAIF,2BAAAA,qCAAAA,eAAgBlC,EAAE,EAAE;oBACtBd,2BAA2Ba,KAAK,CAACmC,eAAelC,EAAE;gBACpD;YACF;QACF,OAAO;YACLd,2BAA2Be,IAAI;QACjC;IACA,+EAA+E;IAC/E,uDAAuD;IACzD,GAAG;QAACwB;QAAMvC;KAA2B;IAErC,+FAA+F;IAC/FlB,MAAMgE,SAAS,CAAC;QACd,IAAIP,MAAM;YACR,IAAI,CAACvC,2BAA2BO,MAAM,IAAI;gBACxCP,2BAA2BmD,KAAK;YAClC;QACF;IACA,+EAA+E;IACjF,GAAG;QAACZ;QAAMhD;QAAUS;KAA2B;IAE/C,OAAO;QACL,GAAGC,gBAAgB;QACnB,GAAGsB,cAAc;QACjBX,cAAcJ;QACdlB;QACAE;QACAwB;QACAK;QACA3B;QACAC;QACA4C;QACApB;QACAiC,iBAAiB3C;QACjBQ;QACAG;QACAuB;QACAhB;QACA5B;QACA8B;QACAhC;QACAwD,eAAerE,iBAAiB,CAACsE;YAC/B,IAAI,CAACzD,aAAa;gBAChB8C,QAAQW,GAAG;YACb;QACF;IACF;AACF,EAAE"}
|
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { mergeCallbacks, useId, useEventCallback, slot, isResolvedShorthand, useMergedRefs } from '@fluentui/react-utilities';
|
|
3
3
|
import { Listbox } from '../Listbox';
|
|
4
4
|
/**
|
|
5
|
+
* @internal
|
|
5
6
|
* @returns listbox slot with desired behaviour and props
|
|
6
7
|
*/ export function useListboxSlot(listboxSlotFromProp, ref, options) {
|
|
7
8
|
const { state: { multiselect }, triggerRef, defaultProps } = options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useListboxSlot.ts"],"sourcesContent":["import * as React from 'react';\nimport {\n mergeCallbacks,\n useId,\n useEventCallback,\n slot,\n isResolvedShorthand,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\nimport type { ComboboxBaseState } from './ComboboxBase.types';\nimport { Listbox } from '../Listbox';\nimport { ListboxProps } from '../Listbox';\n\nexport type UseListboxSlotState = Pick<ComboboxBaseState, 'multiselect'>;\n\ntype UseListboxSlotOptions = {\n state: UseListboxSlotState;\n triggerRef: React.RefObject<HTMLInputElement> | React.RefObject<HTMLButtonElement>;\n defaultProps?: Partial<ListboxProps>;\n};\n\n/**\n * @returns listbox slot with desired behaviour and props\n */\nexport function useListboxSlot(\n listboxSlotFromProp: Slot<typeof Listbox> | undefined,\n ref: React.Ref<HTMLDivElement>,\n options: UseListboxSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<typeof Listbox>>> | undefined {\n const {\n state: { multiselect },\n triggerRef,\n defaultProps,\n } = options;\n\n const listboxId = useId(\n 'fluent-listbox',\n isResolvedShorthand(listboxSlotFromProp) ? listboxSlotFromProp.id : undefined,\n );\n\n const listboxSlot = slot.optional(listboxSlotFromProp, {\n renderByDefault: true,\n elementType: Listbox,\n defaultProps: {\n id: listboxId,\n multiselect,\n tabIndex: undefined,\n ...defaultProps,\n },\n });\n\n /**\n * Clicking on the listbox should never blur the trigger\n * in a combobox\n */\n const onMouseDown = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n event.preventDefault();\n }, listboxSlot?.onMouseDown),\n );\n\n const onClick = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n event.preventDefault();\n triggerRef.current?.focus();\n }, listboxSlot?.onClick),\n );\n\n const listboxRef = useMergedRefs(listboxSlot?.ref, ref);\n if (listboxSlot) {\n listboxSlot.ref = listboxRef;\n listboxSlot.onMouseDown = onMouseDown;\n listboxSlot.onClick = onClick;\n }\n\n return listboxSlot;\n}\n"],"names":["React","mergeCallbacks","useId","useEventCallback","slot","isResolvedShorthand","useMergedRefs","Listbox","useListboxSlot","listboxSlotFromProp","ref","options","state","multiselect","triggerRef","defaultProps","listboxId","id","undefined","listboxSlot","optional","renderByDefault","elementType","tabIndex","onMouseDown","event","preventDefault","onClick","current","focus","listboxRef"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SACEC,cAAc,EACdC,KAAK,EACLC,gBAAgB,EAChBC,IAAI,EACJC,mBAAmB,EACnBC,aAAa,QACR,4BAA4B;AAGnC,SAASC,OAAO,QAAQ,aAAa;AAWrC
|
|
1
|
+
{"version":3,"sources":["useListboxSlot.ts"],"sourcesContent":["import * as React from 'react';\nimport {\n mergeCallbacks,\n useId,\n useEventCallback,\n slot,\n isResolvedShorthand,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\nimport type { ComboboxBaseState } from './ComboboxBase.types';\nimport { Listbox } from '../Listbox';\nimport { ListboxProps } from '../Listbox';\n\nexport type UseListboxSlotState = Pick<ComboboxBaseState, 'multiselect'>;\n\ntype UseListboxSlotOptions = {\n state: UseListboxSlotState;\n triggerRef: React.RefObject<HTMLInputElement> | React.RefObject<HTMLButtonElement>;\n defaultProps?: Partial<ListboxProps>;\n};\n\n/**\n * @internal\n * @returns listbox slot with desired behaviour and props\n */\nexport function useListboxSlot(\n listboxSlotFromProp: Slot<typeof Listbox> | undefined,\n ref: React.Ref<HTMLDivElement>,\n options: UseListboxSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<typeof Listbox>>> | undefined {\n const {\n state: { multiselect },\n triggerRef,\n defaultProps,\n } = options;\n\n const listboxId = useId(\n 'fluent-listbox',\n isResolvedShorthand(listboxSlotFromProp) ? listboxSlotFromProp.id : undefined,\n );\n\n const listboxSlot = slot.optional(listboxSlotFromProp, {\n renderByDefault: true,\n elementType: Listbox,\n defaultProps: {\n id: listboxId,\n multiselect,\n tabIndex: undefined,\n ...defaultProps,\n },\n });\n\n /**\n * Clicking on the listbox should never blur the trigger\n * in a combobox\n */\n const onMouseDown = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n event.preventDefault();\n }, listboxSlot?.onMouseDown),\n );\n\n const onClick = useEventCallback(\n mergeCallbacks((event: React.MouseEvent<HTMLDivElement>) => {\n event.preventDefault();\n triggerRef.current?.focus();\n }, listboxSlot?.onClick),\n );\n\n const listboxRef = useMergedRefs(listboxSlot?.ref, ref);\n if (listboxSlot) {\n listboxSlot.ref = listboxRef;\n listboxSlot.onMouseDown = onMouseDown;\n listboxSlot.onClick = onClick;\n }\n\n return listboxSlot;\n}\n"],"names":["React","mergeCallbacks","useId","useEventCallback","slot","isResolvedShorthand","useMergedRefs","Listbox","useListboxSlot","listboxSlotFromProp","ref","options","state","multiselect","triggerRef","defaultProps","listboxId","id","undefined","listboxSlot","optional","renderByDefault","elementType","tabIndex","onMouseDown","event","preventDefault","onClick","current","focus","listboxRef"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SACEC,cAAc,EACdC,KAAK,EACLC,gBAAgB,EAChBC,IAAI,EACJC,mBAAmB,EACnBC,aAAa,QACR,4BAA4B;AAGnC,SAASC,OAAO,QAAQ,aAAa;AAWrC;;;CAGC,GACD,OAAO,SAASC,eACdC,mBAAqD,EACrDC,GAA8B,EAC9BC,OAA8B;IAE9B,MAAM,EACJC,OAAO,EAAEC,WAAW,EAAE,EACtBC,UAAU,EACVC,YAAY,EACb,GAAGJ;IAEJ,MAAMK,YAAYd,MAChB,kBACAG,oBAAoBI,uBAAuBA,oBAAoBQ,EAAE,GAAGC;IAGtE,MAAMC,cAAcf,KAAKgB,QAAQ,CAACX,qBAAqB;QACrDY,iBAAiB;QACjBC,aAAaf;QACbQ,cAAc;YACZE,IAAID;YACJH;YACAU,UAAUL;YACV,GAAGH,YAAY;QACjB;IACF;IAEA;;;GAGC,GACD,MAAMS,cAAcrB,iBAClBF,eAAe,CAACwB;QACdA,MAAMC,cAAc;IACtB,GAAGP,wBAAAA,kCAAAA,YAAaK,WAAW;IAG7B,MAAMG,UAAUxB,iBACdF,eAAe,CAACwB;YAEdX;QADAW,MAAMC,cAAc;SACpBZ,sBAAAA,WAAWc,OAAO,cAAlBd,0CAAAA,oBAAoBe,KAAK;IAC3B,GAAGV,wBAAAA,kCAAAA,YAAaQ,OAAO;IAGzB,MAAMG,aAAaxB,cAAca,wBAAAA,kCAAAA,YAAaT,GAAG,EAAEA;IACnD,IAAIS,aAAa;QACfA,YAAYT,GAAG,GAAGoB;QAClBX,YAAYK,WAAW,GAAGA;QAC1BL,YAAYQ,OAAO,GAAGA;IACxB;IAEA,OAAOR;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useInputTriggerSlot.js"],"sourcesContent":["import * as React from 'react';\nimport { mergeCallbacks, useEventCallback } from '@fluentui/react-utilities';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport { useTriggerSlot } from '../../utils/useTriggerSlot';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n
|
|
1
|
+
{"version":3,"sources":["useInputTriggerSlot.js"],"sourcesContent":["import * as React from 'react';\nimport { mergeCallbacks, useEventCallback } from '@fluentui/react-utilities';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport { useTriggerSlot } from '../../utils/useTriggerSlot';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n/**\n * @internal\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 */ export function useInputTriggerSlot(triggerFromProps, ref, options) {\n const { state: { open, value, selectOption, setValue, multiselect, selectedOptions, clearSelection, getOptionById, setOpen }, freeform, defaultProps, activeDescendantController } = options;\n const onBlur = (ev)=>{\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 === null || activeOption === void 0 ? void 0 : activeOption.text.toLowerCase())) {\n selectOption(ev, activeOption);\n }\n // reset typed value when the input loses focus while collapsed, unless freeform is true\n setValue(undefined);\n }\n };\n const getOptionFromInput = (inputValue)=>{\n const searchString = inputValue === null || inputValue === void 0 ? void 0 : inputValue.trim().toLowerCase();\n if (!searchString || searchString.length === 0) {\n activeDescendantController.blur();\n return;\n }\n const matcher = (optionText)=>optionText.toLowerCase().indexOf(searchString) === 0;\n const match = activeDescendantController.find((id)=>{\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n });\n if (!match) {\n activeDescendantController.blur();\n return undefined;\n }\n return getOptionById(match);\n };\n // update value and active option based on input\n const onChange = (ev)=>{\n const inputValue = ev.target.value;\n // update uncontrolled value\n setValue(inputValue);\n // handle updating active option based on input\n const matchingOption = getOptionFromInput(inputValue);\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(ev);\n }\n };\n const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'input',\n activeDescendantController\n });\n trigger.onChange = mergeCallbacks(trigger.onChange, onChange);\n trigger.onBlur = mergeCallbacks(trigger.onBlur, onBlur);\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 * Freeform combobox should not select\n */ const defaultOnKeyDown = trigger.onKeyDown;\n const onKeyDown = useEventCallback((ev)=>{\n if (!open && getDropdownActionFromKey(ev) === 'Type') {\n setOpen(ev, true);\n }\n // clear activedescendant when moving the text insertion cursor\n if (ev.key === ArrowLeft || ev.key === ArrowRight) {\n setHideActiveDescendant(true);\n } else {\n setHideActiveDescendant(false);\n }\n // update typing state to true if the user is typing\n const action = getDropdownActionFromKey(ev, {\n open,\n multiselect\n });\n if (action === 'Type') {\n isTyping.current = true;\n } else if (action === 'Open' && ev.key !== ' ' || action === 'Next' || action === 'Previous' || action === 'First' || action === 'Last' || action === 'PageUp' || action === 'PageDown') {\n isTyping.current = false;\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) && ev.key === ' ') {\n var _triggerFromProps_onKeyDown;\n triggerFromProps === null || triggerFromProps === void 0 ? void 0 : (_triggerFromProps_onKeyDown = triggerFromProps.onKeyDown) === null || _triggerFromProps_onKeyDown === void 0 ? void 0 : _triggerFromProps_onKeyDown.call(triggerFromProps, ev);\n return;\n }\n defaultOnKeyDown === null || defaultOnKeyDown === void 0 ? void 0 : defaultOnKeyDown(ev);\n });\n trigger.onKeyDown = onKeyDown;\n if (hideActiveDescendant) {\n trigger['aria-activedescendant'] = undefined;\n }\n return trigger;\n}\n"],"names":["useInputTriggerSlot","triggerFromProps","ref","options","state","open","value","selectOption","setValue","multiselect","selectedOptions","clearSelection","getOptionById","setOpen","freeform","defaultProps","activeDescendantController","onBlur","ev","activeOptionId","active","activeOption","trim","toLowerCase","text","undefined","getOptionFromInput","inputValue","searchString","length","blur","matcher","optionText","indexOf","match","find","id","option","onChange","target","matchingOption","trigger","useTriggerSlot","elementType","mergeCallbacks","hideActiveDescendant","setHideActiveDescendant","React","useState","isTyping","useRef","defaultOnKeyDown","onKeyDown","useEventCallback","getDropdownActionFromKey","key","ArrowLeft","ArrowRight","action","current","_triggerFromProps_onKeyDown","call"],"mappings":";;;;+BAUoBA;;;eAAAA;;;;iEAVG;gCAC0B;8BACX;gCACP;oCACU;AAM9B,SAASA,oBAAoBC,gBAAgB,EAAEC,GAAG,EAAEC,OAAO;IAClE,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAEC,KAAK,EAAEC,YAAY,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,eAAe,EAAEC,cAAc,EAAEC,aAAa,EAAEC,OAAO,EAAE,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,0BAA0B,EAAE,GAAGb;IACrL,MAAMc,SAAS,CAACC;QACZ,2DAA2D;QAC3D,IAAI,CAACb,QAAQ,CAACS,UAAU;YACpB,MAAMK,iBAAiBH,2BAA2BI,MAAM;YACxD,MAAMC,eAAeF,iBAAiBP,cAAcO,kBAAkB;YACtE,qDAAqD;YACrD,IAAIb,SAASe,gBAAgBf,MAAMgB,IAAI,GAAGC,WAAW,OAAQF,CAAAA,iBAAiB,QAAQA,iBAAiB,KAAK,IAAI,KAAK,IAAIA,aAAaG,IAAI,CAACD,WAAW,EAAC,GAAI;gBACvJhB,aAAaW,IAAIG;YACrB;YACA,wFAAwF;YACxFb,SAASiB;QACb;IACJ;IACA,MAAMC,qBAAqB,CAACC;QACxB,MAAMC,eAAeD,eAAe,QAAQA,eAAe,KAAK,IAAI,KAAK,IAAIA,WAAWL,IAAI,GAAGC,WAAW;QAC1G,IAAI,CAACK,gBAAgBA,aAAaC,MAAM,KAAK,GAAG;YAC5Cb,2BAA2Bc,IAAI;YAC/B;QACJ;QACA,MAAMC,UAAU,CAACC,aAAaA,WAAWT,WAAW,GAAGU,OAAO,CAACL,kBAAkB;QACjF,MAAMM,QAAQlB,2BAA2BmB,IAAI,C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U,EAAE;YAC/CX,wBAAwB;QAC5B,OAAO;YACHA,wBAAwB;QAC5B;QACA,oDAAoD;QACpD,MAAMY,SAASJ,IAAAA,4CAAwB,EAACpC,IAAI;YACxCb;YACAI;QACJ;QACA,IAAIiD,WAAW,QAAQ;YACnBT,SAASU,OAAO,GAAG;QACvB,OAAO,IAAID,WAAW,UAAUxC,GAAGqC,GAAG,KAAK,OAAOG,WAAW,UAAUA,WAAW,cAAcA,WAAW,WAAWA,WAAW,UAAUA,WAAW,YAAYA,WAAW,YAAY;YACrLT,SAASU,OAAO,GAAG;QACvB;QACA,wGAAwG;QACxG,IAAI,AAACV,CAAAA,SAASU,OAAO,IAAI,CAACtD,IAAG,KAAMa,GAAGqC,GAAG,KAAK,KAAK;YAC/C,IAAIK;YACJ3D,qBAAqB,QAAQA,qBAAqB,KAAK,IAAI,KAAK,IAAI,AAAC2D,CAAAA,8BAA8B3D,iBAAiBmD,SAAS,AAAD,MAAO,QAAQQ,gCAAgC,KAAK,IAAI,KAAK,IAAIA,4BAA4BC,IAAI,CAAC5D,kBAAkBiB;YAChP;QACJ;QACAiC,qBAAqB,QAAQA,qBAAqB,KAAK,IAAI,KAAK,IAAIA,iBAAiBjC;IACzF;IACAuB,QAAQW,SAAS,GAAGA;IACpB,IAAIP,sBAAsB;QACtBJ,OAAO,CAAC,wBAAwB,GAAGhB;IACvC;IACA,OAAOgB;AACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useButtonTriggerSlot.js"],"sourcesContent":["import * as React from 'react';\nimport { useTimeout, mergeCallbacks } from '@fluentui/react-utilities';\nimport { useTriggerSlot } from '../../utils/useTriggerSlot';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n
|
|
1
|
+
{"version":3,"sources":["useButtonTriggerSlot.js"],"sourcesContent":["import * as React from 'react';\nimport { useTimeout, mergeCallbacks } from '@fluentui/react-utilities';\nimport { useTriggerSlot } from '../../utils/useTriggerSlot';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n/**\n * @internal\n * useButtonTriggerSlot 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 */ export function useButtonTriggerSlot(triggerFromProps, ref, options) {\n const { state: { open, setOpen, getOptionById }, defaultProps, activeDescendantController } = options;\n // jump to matching option based on typing\n const searchString = React.useRef('');\n const [setKeyTimeout, clearKeyTimeout] = useTimeout();\n const moveToNextMatchingOption = (matcher, opt = {\n startFromNext: false\n })=>{\n const { startFromNext } = opt;\n const activeOptionId = activeDescendantController.active();\n const nextInOrder = activeDescendantController.find((id)=>{\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n }, {\n startFrom: startFromNext ? activeDescendantController.next({\n passive: true\n }) : activeOptionId\n });\n if (nextInOrder) {\n return nextInOrder;\n }\n // Cycle back to first match\n return activeDescendantController.find((id)=>{\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n });\n };\n const moveToNextMatchingOptionWithSameCharacterHandling = ()=>{\n if (moveToNextMatchingOption((optionText)=>{\n return optionText.toLocaleLowerCase().indexOf(searchString.current) === 0;\n }, {\n // Slowly pressing the same key will cycle through options\n startFromNext: searchString.current.length === 1\n })) {\n return;\n }\n // if there are no direct matches, check if the search is all the same letter, e.g. \"aaa\"\n if (allCharactersSame(searchString.current) && moveToNextMatchingOption((optionText)=>{\n return optionText.toLocaleLowerCase().indexOf(searchString.current[0]) === 0;\n }, {\n // if the search is all the same letter, cycle through options starting with that letter\n startFromNext: true\n })) {\n return;\n }\n activeDescendantController.blur();\n };\n const onTriggerKeyDown = (ev)=>{\n // clear timeout, if it exists\n clearKeyTimeout();\n // if the key was a char key, update search string\n if (getDropdownActionFromKey(ev) === 'Type') {\n // update search string\n searchString.current += ev.key.toLowerCase();\n setKeyTimeout(()=>{\n searchString.current = '';\n }, 500);\n // update state\n !open && setOpen(ev, true);\n moveToNextMatchingOptionWithSameCharacterHandling();\n }\n };\n const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'button',\n activeDescendantController\n });\n trigger.onKeyDown = mergeCallbacks(onTriggerKeyDown, trigger.onKeyDown);\n return trigger;\n}\n/**\n * @returns - whether every character in the string is the same\n */ function allCharactersSame(str) {\n for(let i = 1; i < str.length; i++){\n if (str[i] !== str[i - 1]) {\n return false;\n }\n }\n return true;\n}\n"],"names":["useButtonTriggerSlot","triggerFromProps","ref","options","state","open","setOpen","getOptionById","defaultProps","activeDescendantController","searchString","React","useRef","setKeyTimeout","clearKeyTimeout","useTimeout","moveToNextMatchingOption","matcher","opt","startFromNext","activeOptionId","active","nextInOrder","find","id","option","text","startFrom","next","passive","moveToNextMatchingOptionWithSameCharacterHandling","optionText","toLocaleLowerCase","indexOf","current","length","allCharactersSame","blur","onTriggerKeyDown","ev","getDropdownActionFromKey","key","toLowerCase","trigger","useTriggerSlot","elementType","onKeyDown","mergeCallbacks","str","i"],"mappings":";;;;+BASoBA;;;eAAAA;;;;iEATG;gCACoB;gCACZ;oCACU;AAM9B,SAASA,qBAAqBC,gBAAgB,EAAEC,GAAG,EAAEC,OAAO;IACnE,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAEC,OAAO,EAAEC,aAAa,EAAE,EAAEC,YAAY,EAAEC,0BAA0B,EAAE,GAAGN;IAC9F,0CAA0C;IAC1C,MAAMO,eAAeC,OAAMC,MAAM,CAAC;IAClC,MAAM,CAACC,eAAeC,gBAAgB,GAAGC,IAAAA,0BAAU;IACnD,MAAMC,2BAA2B,CAACC,SAASC,MAAM;QAC7CC,eAAe;IACnB,CAAC;QACG,MAAM,EAAEA,aAAa,EAAE,GAAGD;QAC1B,MAAME,iBAAiBX,2BAA2BY,MAAM;QACxD,MAAMC,cAAcb,2BAA2Bc,IAAI,CAAC,CAACC;YACjD,MAAMC,SAASlB,cAAciB;YAC7B,OAAO,CAAC,CAACC,UAAUR,QAAQQ,OAAOC,IAAI;QAC1C,GAAG;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;AACA;;CAEC,GAAG,SAASP,kBAAkBY,GAAG;IAC9B,IAAI,IAAIC,IAAI,GAAGA,IAAID,IAAIb,MAAM,EAAEc,IAAI;QAC/B,IAAID,GAAG,CAACC,EAAE,KAAKD,GAAG,CAACC,IAAI,EAAE,EAAE;YACvB,OAAO;QACX;IACJ;IACA,OAAO;AACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":["OptionGroup.types.js"],"sourcesContent":["/**\n * State used in rendering OptionGroup\n */ export { };\n"],"names":[],"mappings":"AAAA;;CAEC"}
|
|
@@ -12,11 +12,11 @@ _export(exports, {
|
|
|
12
12
|
ListboxContext: function() {
|
|
13
13
|
return ListboxContext;
|
|
14
14
|
},
|
|
15
|
-
useListboxContext_unstable: function() {
|
|
16
|
-
return useListboxContext_unstable;
|
|
17
|
-
},
|
|
18
15
|
ListboxProvider: function() {
|
|
19
16
|
return ListboxProvider;
|
|
17
|
+
},
|
|
18
|
+
useListboxContext_unstable: function() {
|
|
19
|
+
return useListboxContext_unstable;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["ListboxContext.js"],"sourcesContent":["import * as React from 'react';\nimport { createContext, useContextSelector } from '@fluentui/react-context-selector';\nconst listboxContextDefaultValue = {\n activeOption: undefined,\n focusVisible: false,\n multiselect: false,\n registerOption () {\n return ()=>undefined;\n },\n selectedOptions: [],\n onOptionClick () {\n // noop\n },\n selectOption () {\n // noop\n },\n setActiveOption () {\n // noop\n }\n};\nexport const ListboxContext = createContext(undefined);\nexport const useListboxContext_unstable = (selector)=>useContextSelector(ListboxContext, (ctx = listboxContextDefaultValue)=>selector(ctx));\nexport const ListboxProvider = ListboxContext.Provider;\n"],"names":["ListboxContext","
|
|
1
|
+
{"version":3,"sources":["ListboxContext.js"],"sourcesContent":["import * as React from 'react';\nimport { createContext, useContextSelector } from '@fluentui/react-context-selector';\nconst listboxContextDefaultValue = {\n activeOption: undefined,\n focusVisible: false,\n multiselect: false,\n registerOption () {\n return ()=>undefined;\n },\n selectedOptions: [],\n onOptionClick () {\n // noop\n },\n selectOption () {\n // noop\n },\n setActiveOption () {\n // noop\n }\n};\nexport const ListboxContext = createContext(undefined);\nexport const useListboxContext_unstable = (selector)=>useContextSelector(ListboxContext, (ctx = listboxContextDefaultValue)=>selector(ctx));\nexport const ListboxProvider = ListboxContext.Provider;\n"],"names":["ListboxContext","ListboxProvider","useListboxContext_unstable","listboxContextDefaultValue","activeOption","undefined","focusVisible","multiselect","registerOption","selectedOptions","onOptionClick","selectOption","setActiveOption","createContext","selector","useContextSelector","ctx","Provider"],"mappings":";;;;;;;;;;;IAoBaA,cAAc;eAAdA;;IAEAC,eAAe;eAAfA;;IADAC,0BAA0B;eAA1BA;;;;iEArBU;sCAC2B;AAClD,MAAMC,6BAA6B;IAC/BC,cAAcC;IACdC,cAAc;IACdC,aAAa;IACbC;QACI,OAAO,IAAIH;IACf;IACAI,iBAAiB,EAAE;IACnBC;IACA,OAAO;IACP;IACAC;IACA,OAAO;IACP;IACAC;IACA,OAAO;IACP;AACJ;AACO,MAAMZ,iBAAiBa,IAAAA,mCAAa,EAACR;AACrC,MAAMH,6BAA6B,CAACY,WAAWC,IAAAA,wCAAkB,EAACf,gBAAgB,CAACgB,MAAMb,0BAA0B,GAAGW,SAASE;AAC/H,MAAMf,kBAAkBD,eAAeiB,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useComboboxFilter.js"],"sourcesContent":["import * as React from 'react';\nimport { Option } from '../Option';\nfunction defaultFilter(optionText, query) {\n if (query === '') {\n return true;\n }\n return optionText.toLowerCase().includes(query.toLowerCase());\n}\nfunction defaultToString(option) {\n return typeof option === 'string' ? option : option.value;\n}\
|
|
1
|
+
{"version":3,"sources":["useComboboxFilter.js"],"sourcesContent":["import * as React from 'react';\nimport { Option } from '../Option';\nfunction defaultFilter(optionText, query) {\n if (query === '') {\n return true;\n }\n return optionText.toLowerCase().includes(query.toLowerCase());\n}\nfunction defaultToString(option) {\n return typeof option === 'string' ? option : option.value;\n}\n/**\n * @internal\n */ export function useComboboxFilter(query, options, config) {\n const { filter = defaultFilter, noOptionsMessage = \"We couldn't find any matches.\", optionToReactKey = defaultToString, optionToText = defaultToString, renderOption = (option)=>{\n if (typeof option === 'string') {\n return /*#__PURE__*/ React.createElement(Option, {\n key: option\n }, option);\n }\n return /*#__PURE__*/ React.createElement(Option, {\n ...option,\n key: optionToReactKey(option),\n text: optionToText(option),\n value: option.value\n }, option.children);\n } } = config;\n const filteredOptions = React.useMemo(()=>{\n const searchValue = query.trim();\n return options.filter((option)=>filter(optionToText(option), searchValue));\n }, [\n options,\n optionToText,\n filter,\n query\n ]);\n if (filteredOptions.length === 0) {\n return [\n /*#__PURE__*/ React.createElement(Option, {\n \"aria-disabled\": \"true\",\n key: \"no-results\",\n text: \"\"\n }, noOptionsMessage)\n ];\n }\n return filteredOptions.map((option)=>renderOption(option));\n}\n"],"names":["useComboboxFilter","defaultFilter","optionText","query","toLowerCase","includes","defaultToString","option","value","options","config","filter","noOptionsMessage","optionToReactKey","optionToText","renderOption","React","createElement","Option","key","text","children","filteredOptions","useMemo","searchValue","trim","length","map"],"mappings":";;;;+BAaoBA;;;eAAAA;;;;iEAbG;wBACA;AACvB,SAASC,cAAcC,UAAU,EAAEC,KAAK;IACpC,IAAIA,UAAU,IAAI;QACd,OAAO;IACX;IACA,OAAOD,WAAWE,WAAW,GAAGC,QAAQ,CAACF,MAAMC,WAAW;AAC9D;AACA,SAASE,gBAAgBC,MAAM;IAC3B,OAAO,OAAOA,WAAW,WAAWA,SAASA,OAAOC,KAAK;AAC7D;AAGW,SAASR,kBAAkBG,KAAK,EAAEM,OAAO,EAAEC,MAAM;IACxD,MAAM,EAAEC,SAASV,aAAa,EAAEW,mBAAmB,+BAA+B,EAAEC,mBAAmBP,eAAe,EAAEQ,eAAeR,eAAe,EAAES,eAAe,CAACR;QACpK,IAAI,OAAOA,WAAW,UAAU;YAC5B,OAAO,WAAW,GAAGS,OAAMC,aAAa,CAACC,cAAM,EAAE;gBAC7CC,KAAKZ;YACT,GAAGA;QACP;QACA,OAAO,WAAW,GAAGS,OAAMC,aAAa,CAACC,cAAM,EAAE;YAC7C,GAAGX,MAAM;YACTY,KAAKN,iBAAiBN;YACtBa,MAAMN,aAAaP;YACnBC,OAAOD,OAAOC,KAAK;QACvB,GAAGD,OAAOc,QAAQ;IACtB,CAAC,EAAE,GAAGX;IACN,MAAMY,kBAAkBN,OAAMO,OAAO,CAAC;QAClC,MAAMC,cAAcrB,MAAMsB,IAAI;QAC9B,OAAOhB,QAAQE,MAAM,CAAC,CAACJ,SAASI,OAAOG,aAAaP,SAASiB;IACjE,GAAG;QACCf;QACAK;QACAH;QACAR;KACH;IACD,IAAImB,gBAAgBI,MAAM,KAAK,GAAG;QAC9B,OAAO;YACH,WAAW,GAAGV,OAAMC,aAAa,CAACC,cAAM,EAAE;gBACtC,iBAAiB;gBACjBC,KAAK;gBACLC,MAAM;YACV,GAAGR;SACN;IACL;IACA,OAAOU,gBAAgBK,GAAG,CAAC,CAACpB,SAASQ,aAAaR;AACtD"}
|
package/lib-commonjs/index.js
CHANGED
|
@@ -10,59 +10,62 @@ function _export(target, all) {
|
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
_export(exports, {
|
|
13
|
+
Combobox: function() {
|
|
14
|
+
return _Combobox.Combobox;
|
|
15
|
+
},
|
|
13
16
|
ComboboxProvider: function() {
|
|
14
17
|
return _ComboboxContext.ComboboxProvider;
|
|
15
18
|
},
|
|
19
|
+
Dropdown: function() {
|
|
20
|
+
return _Dropdown.Dropdown;
|
|
21
|
+
},
|
|
22
|
+
Listbox: function() {
|
|
23
|
+
return _Listbox.Listbox;
|
|
24
|
+
},
|
|
16
25
|
ListboxProvider: function() {
|
|
17
26
|
return _ListboxContext.ListboxProvider;
|
|
18
27
|
},
|
|
19
|
-
|
|
20
|
-
return
|
|
28
|
+
Option: function() {
|
|
29
|
+
return _Option.Option;
|
|
21
30
|
},
|
|
22
|
-
|
|
23
|
-
return
|
|
31
|
+
OptionGroup: function() {
|
|
32
|
+
return _OptionGroup.OptionGroup;
|
|
24
33
|
},
|
|
25
|
-
|
|
26
|
-
return
|
|
34
|
+
comboboxClassNames: function() {
|
|
35
|
+
return _Combobox.comboboxClassNames;
|
|
27
36
|
},
|
|
28
|
-
|
|
29
|
-
return
|
|
37
|
+
dropdownClassNames: function() {
|
|
38
|
+
return _Dropdown.dropdownClassNames;
|
|
30
39
|
},
|
|
31
40
|
listboxClassNames: function() {
|
|
32
41
|
return _Listbox.listboxClassNames;
|
|
33
42
|
},
|
|
34
|
-
|
|
35
|
-
return
|
|
43
|
+
optionClassNames: function() {
|
|
44
|
+
return _Option.optionClassNames;
|
|
36
45
|
},
|
|
37
|
-
|
|
38
|
-
return
|
|
46
|
+
optionGroupClassNames: function() {
|
|
47
|
+
return _OptionGroup.optionGroupClassNames;
|
|
39
48
|
},
|
|
40
|
-
|
|
41
|
-
return
|
|
49
|
+
renderCombobox_unstable: function() {
|
|
50
|
+
return _Combobox.renderCombobox_unstable;
|
|
42
51
|
},
|
|
43
|
-
|
|
44
|
-
return
|
|
52
|
+
renderDropdown_unstable: function() {
|
|
53
|
+
return _Dropdown.renderDropdown_unstable;
|
|
45
54
|
},
|
|
46
|
-
|
|
47
|
-
return
|
|
55
|
+
renderListbox_unstable: function() {
|
|
56
|
+
return _Listbox.renderListbox_unstable;
|
|
57
|
+
},
|
|
58
|
+
renderOptionGroup_unstable: function() {
|
|
59
|
+
return _OptionGroup.renderOptionGroup_unstable;
|
|
48
60
|
},
|
|
49
61
|
renderOption_unstable: function() {
|
|
50
62
|
return _Option.renderOption_unstable;
|
|
51
63
|
},
|
|
52
|
-
|
|
53
|
-
return
|
|
54
|
-
},
|
|
55
|
-
useOption_unstable: function() {
|
|
56
|
-
return _Option.useOption_unstable;
|
|
57
|
-
},
|
|
58
|
-
Combobox: function() {
|
|
59
|
-
return _Combobox.Combobox;
|
|
60
|
-
},
|
|
61
|
-
comboboxClassNames: function() {
|
|
62
|
-
return _Combobox.comboboxClassNames;
|
|
64
|
+
useComboboxContextValues: function() {
|
|
65
|
+
return _useComboboxContextValues.useComboboxContextValues;
|
|
63
66
|
},
|
|
64
|
-
|
|
65
|
-
return
|
|
67
|
+
useComboboxFilter: function() {
|
|
68
|
+
return _useComboboxFilter.useComboboxFilter;
|
|
66
69
|
},
|
|
67
70
|
useComboboxStyles_unstable: function() {
|
|
68
71
|
return _Combobox.useComboboxStyles_unstable;
|
|
@@ -70,29 +73,23 @@ _export(exports, {
|
|
|
70
73
|
useCombobox_unstable: function() {
|
|
71
74
|
return _Combobox.useCombobox_unstable;
|
|
72
75
|
},
|
|
73
|
-
Dropdown: function() {
|
|
74
|
-
return _Dropdown.Dropdown;
|
|
75
|
-
},
|
|
76
|
-
dropdownClassNames: function() {
|
|
77
|
-
return _Dropdown.dropdownClassNames;
|
|
78
|
-
},
|
|
79
|
-
renderDropdown_unstable: function() {
|
|
80
|
-
return _Dropdown.renderDropdown_unstable;
|
|
81
|
-
},
|
|
82
76
|
useDropdownStyles_unstable: function() {
|
|
83
77
|
return _Dropdown.useDropdownStyles_unstable;
|
|
84
78
|
},
|
|
85
79
|
useDropdown_unstable: function() {
|
|
86
80
|
return _Dropdown.useDropdown_unstable;
|
|
87
81
|
},
|
|
88
|
-
|
|
89
|
-
return
|
|
82
|
+
useListboxContextValues: function() {
|
|
83
|
+
return _useListboxContextValues.useListboxContextValues;
|
|
90
84
|
},
|
|
91
|
-
|
|
92
|
-
return
|
|
85
|
+
useListboxContext_unstable: function() {
|
|
86
|
+
return _ListboxContext.useListboxContext_unstable;
|
|
93
87
|
},
|
|
94
|
-
|
|
95
|
-
return
|
|
88
|
+
useListboxStyles_unstable: function() {
|
|
89
|
+
return _Listbox.useListboxStyles_unstable;
|
|
90
|
+
},
|
|
91
|
+
useListbox_unstable: function() {
|
|
92
|
+
return _Listbox.useListbox_unstable;
|
|
96
93
|
},
|
|
97
94
|
useOptionGroupStyles_unstable: function() {
|
|
98
95
|
return _OptionGroup.useOptionGroupStyles_unstable;
|
|
@@ -100,8 +97,11 @@ _export(exports, {
|
|
|
100
97
|
useOptionGroup_unstable: function() {
|
|
101
98
|
return _OptionGroup.useOptionGroup_unstable;
|
|
102
99
|
},
|
|
103
|
-
|
|
104
|
-
return
|
|
100
|
+
useOptionStyles_unstable: function() {
|
|
101
|
+
return _Option.useOptionStyles_unstable;
|
|
102
|
+
},
|
|
103
|
+
useOption_unstable: function() {
|
|
104
|
+
return _Option.useOption_unstable;
|
|
105
105
|
}
|
|
106
106
|
});
|
|
107
107
|
const _ComboboxContext = require("./contexts/ComboboxContext");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.js"],"sourcesContent":["// eslint-disable-next-line deprecation/deprecation\nexport { ComboboxProvider } from './contexts/ComboboxContext';\nexport { ListboxProvider, useListboxContext_unstable } from './contexts/ListboxContext';\nexport { useComboboxContextValues } from './contexts/useComboboxContextValues';\nexport { useListboxContextValues } from './contexts/useListboxContextValues';\nexport { Listbox, listboxClassNames, renderListbox_unstable, useListboxStyles_unstable, useListbox_unstable } from './Listbox';\nexport { Option, optionClassNames, renderOption_unstable, useOptionStyles_unstable, useOption_unstable } from './Option';\nexport { Combobox, comboboxClassNames, renderCombobox_unstable, useComboboxStyles_unstable, useCombobox_unstable } from './Combobox';\nexport { Dropdown, dropdownClassNames, renderDropdown_unstable, useDropdownStyles_unstable, useDropdown_unstable } from './Dropdown';\nexport { OptionGroup, optionGroupClassNames, renderOptionGroup_unstable, useOptionGroupStyles_unstable, useOptionGroup_unstable } from './OptionGroup';\nexport { useComboboxFilter } from './hooks/useComboboxFilter';\n"],"names":["ComboboxProvider","
|
|
1
|
+
{"version":3,"sources":["index.js"],"sourcesContent":["// eslint-disable-next-line deprecation/deprecation\nexport { ComboboxProvider } from './contexts/ComboboxContext';\nexport { ListboxProvider, useListboxContext_unstable } from './contexts/ListboxContext';\nexport { useComboboxContextValues } from './contexts/useComboboxContextValues';\nexport { useListboxContextValues } from './contexts/useListboxContextValues';\nexport { Listbox, listboxClassNames, renderListbox_unstable, useListboxStyles_unstable, useListbox_unstable } from './Listbox';\nexport { Option, optionClassNames, renderOption_unstable, useOptionStyles_unstable, useOption_unstable } from './Option';\nexport { Combobox, comboboxClassNames, renderCombobox_unstable, useComboboxStyles_unstable, useCombobox_unstable } from './Combobox';\nexport { Dropdown, dropdownClassNames, renderDropdown_unstable, useDropdownStyles_unstable, useDropdown_unstable } from './Dropdown';\nexport { OptionGroup, optionGroupClassNames, renderOptionGroup_unstable, useOptionGroupStyles_unstable, useOptionGroup_unstable } from './OptionGroup';\nexport { useComboboxFilter } from './hooks/useComboboxFilter';\n"],"names":["Combobox","ComboboxProvider","Dropdown","Listbox","ListboxProvider","Option","OptionGroup","comboboxClassNames","dropdownClassNames","listboxClassNames","optionClassNames","optionGroupClassNames","renderCombobox_unstable","renderDropdown_unstable","renderListbox_unstable","renderOptionGroup_unstable","renderOption_unstable","useComboboxContextValues","useComboboxFilter","useComboboxStyles_unstable","useCombobox_unstable","useDropdownStyles_unstable","useDropdown_unstable","useListboxContextValues","useListboxContext_unstable","useListboxStyles_unstable","useListbox_unstable","useOptionGroupStyles_unstable","useOptionGroup_unstable","useOptionStyles_unstable","useOption_unstable"],"mappings":"AAAA,mDAAmD;;;;;;;;;;;;IAO1CA,QAAQ;eAARA,kBAAQ;;IANRC,gBAAgB;eAAhBA,iCAAgB;;IAOhBC,QAAQ;eAARA,kBAAQ;;IAHRC,OAAO;eAAPA,gBAAO;;IAHPC,eAAe;eAAfA,+BAAe;;IAIfC,MAAM;eAANA,cAAM;;IAGNC,WAAW;eAAXA,wBAAW;;IAFDC,kBAAkB;eAAlBA,4BAAkB;;IAClBC,kBAAkB;eAAlBA,4BAAkB;;IAHnBC,iBAAiB;eAAjBA,0BAAiB;;IAClBC,gBAAgB;eAAhBA,wBAAgB;;IAGXC,qBAAqB;eAArBA,kCAAqB;;IAFJC,uBAAuB;eAAvBA,iCAAuB;;IACvBC,uBAAuB;eAAvBA,iCAAuB;;IAHzBC,sBAAsB;eAAtBA,+BAAsB;;IAIdC,0BAA0B;eAA1BA,uCAA0B;;IAHpCC,qBAAqB;eAArBA,6BAAqB;;IAH/CC,wBAAwB;eAAxBA,kDAAwB;;IAOxBC,iBAAiB;eAAjBA,oCAAiB;;IAHsCC,0BAA0B;eAA1BA,oCAA0B;;IAAEC,oBAAoB;eAApBA,8BAAoB;;IAChDC,0BAA0B;eAA1BA,oCAA0B;;IAAEC,oBAAoB;eAApBA,8BAAoB;;IAJvGC,uBAAuB;eAAvBA,gDAAuB;;IAFNC,0BAA0B;eAA1BA,0CAA0B;;IAGSC,yBAAyB;eAAzBA,kCAAyB;;IAAEC,mBAAmB;eAAnBA,4BAAmB;;IAIlCC,6BAA6B;eAA7BA,0CAA6B;;IAAEC,uBAAuB;eAAvBA,oCAAuB;;IAHrEC,wBAAwB;eAAxBA,gCAAwB;;IAAEC,kBAAkB;eAAlBA,0BAAkB;;;iCALrE;gCAC2B;0CACnB;yCACD;yBAC2E;wBACL;0BACU;0BACA;6BACe;mCACrG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useComboboxBaseState.js"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState, useEventCallback, useFirstMount } from '@fluentui/react-utilities';\nimport { useOptionCollection } from '../utils/useOptionCollection';\nimport { useSelection } from '../utils/useSelection';\n/**\n * State shared between Combobox and Dropdown components\n */ export const useComboboxBaseState = (props)=>{\n const { appearance = 'outline', children, clearable = false, editable = false, inlinePopup = false, mountNode = undefined, multiselect, onOpenChange, size = 'medium', activeDescendantController } = props;\n const optionCollection = useOptionCollection();\n const { getOptionsMatchingValue } = optionCollection;\n const { getOptionById } = optionCollection;\n const getActiveOption = React.useCallback(()=>{\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [\n activeDescendantController,\n 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((option)=>{\n let nextOption = undefined;\n if (typeof option === 'function') {\n const activeOption = getActiveOption();\n nextOption = option(activeOption);\n }\n if (nextOption) {\n activeDescendantController.focus(nextOption.id);\n } else {\n activeDescendantController.blur();\n }\n }, [\n activeDescendantController,\n getActiveOption\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 // 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 const ignoreNextBlur = React.useRef(false);\n const selectionState = useSelection(props);\n const { selectedOptions } = selectionState;\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 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 // handle defaultValue here, so it is overridden by selection\n if (isFirstMount && props.defaultValue !== undefined) {\n return props.defaultValue;\n }\n const selectedOptionsText = getOptionsMatchingValue((optionValue)=>{\n return selectedOptions.includes(optionValue);\n }).map((option)=>option.text);\n if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptionsText.join(', ');\n }\n return selectedOptionsText[0];\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 }, [\n controllableValue,\n editable,\n getOptionsMatchingValue,\n multiselect,\n props.defaultValue,\n 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 const setOpen = React.useCallback((event, newState)=>{\n onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {\n open: newState\n });\n setOpenState(newState);\n }, [\n onOpenChange,\n setOpenState\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 === null || selectedOption === void 0 ? void 0 : 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 or children\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n open,\n 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) {\n if (!activeDescendantController.active()) {\n activeDescendantController.first();\n }\n }\n // this should only be run in response to changes in the open state or children\n }, [\n open,\n children,\n activeDescendantController\n ]);\n return {\n ...optionCollection,\n ...selectionState,\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)=>{\n if (!multiselect) {\n setOpen(e, false);\n }\n })\n };\n};\n"],"names":["useComboboxBaseState","props","appearance","children","clearable","editable","inlinePopup","mountNode","undefined","multiselect","onOpenChange","size","activeDescendantController","optionCollection","useOptionCollection","getOptionsMatchingValue","getOptionById","getActiveOption","React","useCallback","activeOptionId","active","UNSAFE_activeOption","UNSAFE_setActiveOption","option","nextOption","activeOption","focus","id","blur","focusVisible","setFocusVisible","useState","hasFocus","setHasFocus","ignoreNextBlur","useRef","selectionState","useSelection","selectedOptions","isFirstMount","useFirstMount","controllableValue","setValue","useControllableState","state","value","initialState","useMemo","defaultValue","selectedOptionsText","optionValue","includes","map","text","join","open","setOpenState","defaultState","defaultOpen","setOpen","event","newState","useEffect","length","selectedOption","v","pop","first","setActiveOption","onOptionClick","useEventCallback","e"],"mappings":";;;;+BAMiBA;;;eAAAA;;;;iEANM;gCAC+C;qCAClC;8BACP;AAGlB,MAAMA,uBAAuB,CAACC;IACrC,MAAM,EAAEC,aAAa,SAAS,EAAEC,QAAQ,EAAEC,YAAY,KAAK,EAAEC,WAAW,KAAK,EAAEC,cAAc,KAAK,EAAEC,YAAYC,SAAS,EAAEC,WAAW,EAAEC,YAAY,EAAEC,OAAO,QAAQ,EAAEC,0BAA0B,EAAE,GAAGX;IACtM,MAAMY,mBAAmBC,IAAAA,wCAAmB;IAC5C,MAAM,EAAEC,uBAAuB,EAAE,GAAGF;IACpC,MAAM,EAAEG,aAAa,EAAE,GAAGH;IAC1B,MAAMI,kBAAkBC,OAAMC,WAAW,CAAC;QACtC,MAAMC,iBAAiBR,2BAA2BS,MAAM;QACxD,OAAOD,iBAAiBJ,cAAcI,kBAAkBZ;IAC5D,GAAG;QACCI;QACAI;KACH;IACD,+DAA+D;IAC/D,gEAAgE;IAChE,MAAMM,sBAAsBL;IAC5B,gEAAgE;IAChE,MAAMM,yBAAyBL,OAAMC,WAAW,CAAC,CAACK;QAC9C,IAAIC,aAAajB;QACjB,IAAI,OAAOgB,WAAW,YAAY;YAC9B,MAAME,eAAeT;YACrBQ,aAAaD,OAAOE;QACxB;QACA,IAAID,YAAY;YACZb,2BAA2Be,KAAK,CAACF,WAAWG,EAAE;QAClD,OAAO;YACHhB,2BAA2BiB,IAAI;QACnC;IACJ,GAAG;QACCjB;QACAK;KACH;IACD,uDAAuD;IACvD,yFAAyF;IACzF,MAAM,CAACa,cAAcC,gBAAgB,GAAGb,OAAMc,QAAQ,CAAC;IACvD,g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K,IAAIA,aAAamD,OAAO;YAC5EL,MAAMM;QACV;QACAL,aAAaK;IACjB,GAAG;QACCpD;QACA+C;KACH;IACD,qDAAqD;IACrDvC,OAAM6C,SAAS,CAAC;QACZ,IAAIP,MAAM;YACN,sFAAsF;YACtF,IAAI,CAAC/C,eAAe8B,gBAAgByB,MAAM,GAAG,GAAG;gBAC5C,MAAMC,iBAAiBlD,wBAAwB,CAACmD,IAAIA,MAAM3B,eAAe,CAAC,EAAE,EAAE4B,GAAG;gBACjF,IAAIF,mBAAmB,QAAQA,mBAAmB,KAAK,IAAI,KAAK,IAAIA,eAAerC,EAAE,EAAE;oBACnFhB,2BAA2Be,KAAK,CAACsC,eAAerC,EAAE;gBACtD;YACJ;QACJ,OAAO;YACHhB,2BAA2BiB,IAAI;QACnC;IACJ,+EAA+E;IAC/E,uDAAuD;IACvD,GAAG;QACC2B;QACA5C;KACH;IACD,+FAA+F;IAC/FM,OAAM6C,SAAS,CAAC;QACZ,IAAIP,MAAM;YACN,IAAI,CAAC5C,2BAA2BS,MAAM,IAAI;gBACtCT,2BAA2BwD,KAAK;YACpC;QACJ;IACJ,+EAA+E;IAC/E,GAAG;QACCZ;QACArD;QACAS;KACH;IACD,OAAO;QACH,GAAGC,gBAAgB;QACnB,GAAGwB,cAAc;QACjBX,cAAcJ;QACdpB;QACAE;QACA0B;QACAK;QACA7B;QACAC;QACAiD;QACAvB;QACAoC,iBAAiB9C;QACjBQ;QACAG;QACA0B;QACAjB;QACAhC;QACAmC;QACArC;QACA6D,eAAeC,IAAAA,gCAAgB,EAAC,CAACC;YAC7B,IAAI,CAAC/D,aAAa;gBACdmD,QAAQY,GAAG;YACf;QACJ;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"sources":["useComboboxBaseState.js"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState, useEventCallback, useFirstMount } from '@fluentui/react-utilities';\nimport { useOptionCollection } from '../utils/useOptionCollection';\nimport { useSelection } from '../utils/useSelection';\n/**\n * @internal\n * State shared between Combobox and Dropdown components\n */ export const useComboboxBaseState = (props)=>{\n const { appearance = 'outline', children, clearable = false, editable = false, inlinePopup = false, mountNode = undefined, multiselect, onOpenChange, size = 'medium', activeDescendantController } = props;\n const optionCollection = useOptionCollection();\n const { getOptionsMatchingValue } = optionCollection;\n const { getOptionById } = optionCollection;\n const getActiveOption = React.useCallback(()=>{\n const activeOptionId = activeDescendantController.active();\n return activeOptionId ? getOptionById(activeOptionId) : undefined;\n }, [\n activeDescendantController,\n 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((option)=>{\n let nextOption = undefined;\n if (typeof option === 'function') {\n const activeOption = getActiveOption();\n nextOption = option(activeOption);\n }\n if (nextOption) {\n activeDescendantController.focus(nextOption.id);\n } else {\n activeDescendantController.blur();\n }\n }, [\n activeDescendantController,\n getActiveOption\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 // 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 const ignoreNextBlur = React.useRef(false);\n const selectionState = useSelection(props);\n const { selectedOptions } = selectionState;\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 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 // handle defaultValue here, so it is overridden by selection\n if (isFirstMount && props.defaultValue !== undefined) {\n return props.defaultValue;\n }\n const selectedOptionsText = getOptionsMatchingValue((optionValue)=>{\n return selectedOptions.includes(optionValue);\n }).map((option)=>option.text);\n if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptionsText.join(', ');\n }\n return selectedOptionsText[0];\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 }, [\n controllableValue,\n editable,\n getOptionsMatchingValue,\n multiselect,\n props.defaultValue,\n 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 const setOpen = React.useCallback((event, newState)=>{\n onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {\n open: newState\n });\n setOpenState(newState);\n }, [\n onOpenChange,\n setOpenState\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 === null || selectedOption === void 0 ? void 0 : 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 or children\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n open,\n 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) {\n if (!activeDescendantController.active()) {\n activeDescendantController.first();\n }\n }\n // this should only be run in response to changes in the open state or children\n }, [\n open,\n children,\n activeDescendantController\n ]);\n return {\n ...optionCollection,\n ...selectionState,\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)=>{\n if (!multiselect) {\n setOpen(e, false);\n }\n })\n };\n};\n"],"names":["useComboboxBaseState","props","appearance","children","clearable","editable","inlinePopup","mountNode","undefined","multiselect","onOpenChange","size","activeDescendantController","optionCollection","useOptionCollection","getOptionsMatchingValue","getOptionById","getActiveOption","React","useCallback","activeOptionId","active","UNSAFE_activeOption","UNSAFE_setActiveOption","option","nextOption","activeOption","focus","id","blur","focusVisible","setFocusVisible","useState","hasFocus","setHasFocus","ignoreNextBlur","useRef","selectionState","useSelection","selectedOptions","isFirstMount","useFirstMount","controllableValue","setValue","useControllableState","state","value","initialState","useMemo","defaultValue","selectedOptionsText","optionValue","includes","map","text","join","open","setOpenState","defaultState","defaultOpen","setOpen","event","newState","useEffect","length","selectedOption","v","pop","first","setActiveOption","onOptionClick","useEventCallback","e"],"mappings":";;;;+BAOiBA;;;eAAAA;;;;iEAPM;gCAC+C;qCAClC;8BACP;AAIlB,MAAMA,uBAAuB,CAACC;IACrC,MAAM,EAAEC,aAAa,SAAS,EAAEC,QAAQ,EAAEC,YAAY,KAAK,EAAEC,WAAW,KAAK,EAAEC,cAAc,KAAK,EAAEC,YAAYC,SAAS,EAAEC,WAAW,EAAEC,YAAY,EAAEC,OAAO,QAAQ,EAAEC,0BAA0B,EAAE,GAAGX;IACtM,MAAMY,mBAAmBC,IAAAA,wCAAmB;IAC5C,MAAM,EAAEC,uBAAuB,EAAE,GAAGF;IACpC,MAAM,EAAEG,aAAa,EAAE,GAAGH;IAC1B,MAAMI,kBAAkBC,OAAMC,WAAW,CAAC;QACtC,MAAMC,iBAAiBR,2BAA2BS,MAAM;QACxD,OAAOD,iBAAiBJ,cAAcI,kBAAkBZ;IAC5D,GAAG;QACCI;QACAI;KACH;IACD,+DAA+D;IAC/D,gEAAgE;IAChE,MAAMM,sBAAsBL;IAC5B,gEAAgE;IAChE,MAAMM,yBAAyBL,OAAMC,WAAW,CAAC,CAACK;QAC9C,IAAIC,aAAajB;QACjB,IAAI,OAAOgB,WAAW,YAAY;YAC9B,MAAME,eAAeT;YACrBQ,aAAaD,OAAOE;QACxB;QACA,IAAID,YAAY;YACZb,2B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QACJ;IACJ;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useListboxSlot.js"],"sourcesContent":["import * as React from 'react';\nimport { mergeCallbacks, useId, useEventCallback, slot, isResolvedShorthand, useMergedRefs } from '@fluentui/react-utilities';\nimport { Listbox } from '../Listbox';\n/**\n * @returns listbox slot with desired behaviour and props\n */ export function useListboxSlot(listboxSlotFromProp, ref, options) {\n const { state: { multiselect }, triggerRef, defaultProps } = options;\n const listboxId = useId('fluent-listbox', isResolvedShorthand(listboxSlotFromProp) ? listboxSlotFromProp.id : undefined);\n const listboxSlot = slot.optional(listboxSlotFromProp, {\n renderByDefault: true,\n elementType: Listbox,\n defaultProps: {\n id: listboxId,\n multiselect,\n tabIndex: undefined,\n ...defaultProps\n }\n });\n /**\n * Clicking on the listbox should never blur the trigger\n * in a combobox\n */ const onMouseDown = useEventCallback(mergeCallbacks((event)=>{\n event.preventDefault();\n }, listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.onMouseDown));\n const onClick = useEventCallback(mergeCallbacks((event)=>{\n var _triggerRef_current;\n event.preventDefault();\n (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();\n }, listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.onClick));\n const listboxRef = useMergedRefs(listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.ref, ref);\n if (listboxSlot) {\n listboxSlot.ref = listboxRef;\n listboxSlot.onMouseDown = onMouseDown;\n listboxSlot.onClick = onClick;\n }\n return listboxSlot;\n}\n"],"names":["useListboxSlot","listboxSlotFromProp","ref","options","state","multiselect","triggerRef","defaultProps","listboxId","useId","isResolvedShorthand","id","undefined","listboxSlot","slot","optional","renderByDefault","elementType","Listbox","tabIndex","onMouseDown","useEventCallback","mergeCallbacks","event","preventDefault","onClick","_triggerRef_current","current","focus","listboxRef","useMergedRefs"],"mappings":";;;;+
|
|
1
|
+
{"version":3,"sources":["useListboxSlot.js"],"sourcesContent":["import * as React from 'react';\nimport { mergeCallbacks, useId, useEventCallback, slot, isResolvedShorthand, useMergedRefs } from '@fluentui/react-utilities';\nimport { Listbox } from '../Listbox';\n/**\n * @internal\n * @returns listbox slot with desired behaviour and props\n */ export function useListboxSlot(listboxSlotFromProp, ref, options) {\n const { state: { multiselect }, triggerRef, defaultProps } = options;\n const listboxId = useId('fluent-listbox', isResolvedShorthand(listboxSlotFromProp) ? listboxSlotFromProp.id : undefined);\n const listboxSlot = slot.optional(listboxSlotFromProp, {\n renderByDefault: true,\n elementType: Listbox,\n defaultProps: {\n id: listboxId,\n multiselect,\n tabIndex: undefined,\n ...defaultProps\n }\n });\n /**\n * Clicking on the listbox should never blur the trigger\n * in a combobox\n */ const onMouseDown = useEventCallback(mergeCallbacks((event)=>{\n event.preventDefault();\n }, listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.onMouseDown));\n const onClick = useEventCallback(mergeCallbacks((event)=>{\n var _triggerRef_current;\n event.preventDefault();\n (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();\n }, listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.onClick));\n const listboxRef = useMergedRefs(listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.ref, ref);\n if (listboxSlot) {\n listboxSlot.ref = listboxRef;\n listboxSlot.onMouseDown = onMouseDown;\n listboxSlot.onClick = onClick;\n }\n return listboxSlot;\n}\n"],"names":["useListboxSlot","listboxSlotFromProp","ref","options","state","multiselect","triggerRef","defaultProps","listboxId","useId","isResolvedShorthand","id","undefined","listboxSlot","slot","optional","renderByDefault","elementType","Listbox","tabIndex","onMouseDown","useEventCallback","mergeCallbacks","event","preventDefault","onClick","_triggerRef_current","current","focus","listboxRef","useMergedRefs"],"mappings":";;;;+BAMoBA;;;eAAAA;;;;iEANG;gCAC2E;yBAC1E;AAIb,SAASA,eAAeC,mBAAmB,EAAEC,GAAG,EAAEC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"Fluent UI React Combobox component",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -33,18 +33,18 @@
|
|
|
33
33
|
"@fluentui/scripts-tasks": "*"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@fluentui/react-aria": "^9.
|
|
36
|
+
"@fluentui/react-aria": "^9.10.1",
|
|
37
37
|
"@fluentui/keyboard-keys": "^9.0.7",
|
|
38
|
-
"@fluentui/react-context-selector": "^9.1.
|
|
39
|
-
"@fluentui/react-field": "^9.1.
|
|
38
|
+
"@fluentui/react-context-selector": "^9.1.55",
|
|
39
|
+
"@fluentui/react-field": "^9.1.57",
|
|
40
40
|
"@fluentui/react-icons": "^2.0.224",
|
|
41
|
-
"@fluentui/react-jsx-runtime": "^9.0.
|
|
42
|
-
"@fluentui/react-portal": "^9.4.
|
|
43
|
-
"@fluentui/react-positioning": "^9.
|
|
44
|
-
"@fluentui/react-shared-contexts": "^9.
|
|
45
|
-
"@fluentui/react-tabster": "^9.19.
|
|
46
|
-
"@fluentui/react-theme": "^9.1.
|
|
47
|
-
"@fluentui/react-utilities": "^9.18.
|
|
41
|
+
"@fluentui/react-jsx-runtime": "^9.0.33",
|
|
42
|
+
"@fluentui/react-portal": "^9.4.17",
|
|
43
|
+
"@fluentui/react-positioning": "^9.14.1",
|
|
44
|
+
"@fluentui/react-shared-contexts": "^9.15.1",
|
|
45
|
+
"@fluentui/react-tabster": "^9.19.4",
|
|
46
|
+
"@fluentui/react-theme": "^9.1.18",
|
|
47
|
+
"@fluentui/react-utilities": "^9.18.4",
|
|
48
48
|
"@griffel/react": "^1.5.14",
|
|
49
49
|
"@swc/helpers": "^0.5.1"
|
|
50
50
|
},
|
|
@@ -52,8 +52,7 @@
|
|
|
52
52
|
"@types/react": ">=16.14.0 <19.0.0",
|
|
53
53
|
"@types/react-dom": ">=16.9.0 <19.0.0",
|
|
54
54
|
"react": ">=16.14.0 <19.0.0",
|
|
55
|
-
"react-dom": ">=16.14.0 <19.0.0"
|
|
56
|
-
"scheduler": "^0.19.0 || ^0.20.0"
|
|
55
|
+
"react-dom": ">=16.14.0 <19.0.0"
|
|
57
56
|
},
|
|
58
57
|
"beachball": {
|
|
59
58
|
"disallowedChangeTypes": [
|