@fluentui/react-combobox 9.0.0-beta.8 → 9.0.0
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.json +964 -4
- package/CHANGELOG.md +274 -5
- package/README.md +1 -3
- package/dist/index.d.ts +84 -24
- package/lib/Combobox.js.map +1 -1
- package/lib/ComboboxField.js +2 -0
- package/lib/ComboboxField.js.map +1 -0
- package/lib/Dropdown.js.map +1 -1
- package/lib/Listbox.js.map +1 -1
- package/lib/Option.js.map +1 -1
- package/lib/OptionGroup.js.map +1 -1
- package/lib/components/Combobox/Combobox.js +0 -1
- package/lib/components/Combobox/Combobox.js.map +1 -1
- package/lib/components/Combobox/Combobox.types.js.map +1 -1
- package/lib/components/Combobox/index.js.map +1 -1
- package/lib/components/Combobox/renderCombobox.js +11 -8
- package/lib/components/Combobox/renderCombobox.js.map +1 -1
- package/lib/components/Combobox/useCombobox.js +191 -16
- package/lib/components/Combobox/useCombobox.js.map +1 -1
- package/lib/components/Combobox/useComboboxStyles.js +253 -161
- package/lib/components/Combobox/useComboboxStyles.js.map +1 -1
- package/lib/components/ComboboxField/ComboboxField.js +8 -0
- package/lib/components/ComboboxField/ComboboxField.js.map +1 -0
- package/lib/components/ComboboxField/index.js +2 -0
- package/lib/components/ComboboxField/index.js.map +1 -0
- package/lib/components/Dropdown/Dropdown.js +0 -1
- package/lib/components/Dropdown/Dropdown.js.map +1 -1
- package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
- package/lib/components/Dropdown/index.js.map +1 -1
- package/lib/components/Dropdown/renderDropdown.js +11 -8
- package/lib/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdown.js +90 -9
- package/lib/components/Dropdown/useDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdownStyles.js +237 -155
- package/lib/components/Dropdown/useDropdownStyles.js.map +1 -1
- package/lib/components/Listbox/Listbox.js +0 -1
- package/lib/components/Listbox/Listbox.js.map +1 -1
- package/lib/components/Listbox/Listbox.types.js.map +1 -1
- package/lib/components/Listbox/index.js.map +1 -1
- package/lib/components/Listbox/renderListbox.js +2 -2
- package/lib/components/Listbox/renderListbox.js.map +1 -1
- package/lib/components/Listbox/useListbox.js +35 -29
- package/lib/components/Listbox/useListbox.js.map +1 -1
- package/lib/components/Listbox/useListboxStyles.js +16 -20
- package/lib/components/Listbox/useListboxStyles.js.map +1 -1
- package/lib/components/Option/Option.js +0 -1
- package/lib/components/Option/Option.js.map +1 -1
- package/lib/components/Option/Option.types.js.map +1 -1
- package/lib/components/Option/index.js.map +1 -1
- package/lib/components/Option/renderOption.js +4 -3
- package/lib/components/Option/renderOption.js.map +1 -1
- package/lib/components/Option/useOption.js +61 -46
- package/lib/components/Option/useOption.js.map +1 -1
- package/lib/components/Option/useOptionStyles.js +103 -80
- package/lib/components/Option/useOptionStyles.js.map +1 -1
- package/lib/components/OptionGroup/OptionGroup.js +0 -1
- package/lib/components/OptionGroup/OptionGroup.js.map +1 -1
- package/lib/components/OptionGroup/OptionGroup.types.js.map +1 -1
- package/lib/components/OptionGroup/index.js.map +1 -1
- package/lib/components/OptionGroup/renderOptionGroup.js +4 -3
- package/lib/components/OptionGroup/renderOptionGroup.js.map +1 -1
- package/lib/components/OptionGroup/useOptionGroup.js +0 -1
- package/lib/components/OptionGroup/useOptionGroup.js.map +1 -1
- package/lib/components/OptionGroup/useOptionGroupStyles.js +29 -34
- package/lib/components/OptionGroup/useOptionGroupStyles.js.map +1 -1
- package/lib/contexts/ComboboxContext.js +14 -9
- package/lib/contexts/ComboboxContext.js.map +1 -1
- package/lib/contexts/ListboxContext.js +11 -8
- package/lib/contexts/ListboxContext.js.map +1 -1
- package/lib/contexts/useComboboxContextValues.js +8 -2
- package/lib/contexts/useComboboxContextValues.js.map +1 -1
- package/lib/contexts/useListboxContextValues.js +10 -6
- package/lib/contexts/useListboxContextValues.js.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/ComboboxBase.types.js.map +1 -1
- package/lib/utils/OptionCollection.types.js.map +1 -1
- package/lib/utils/Selection.types.js.map +1 -1
- package/lib/utils/dropdownKeyActions.js +14 -42
- package/lib/utils/dropdownKeyActions.js.map +1 -1
- package/lib/utils/internalTokens.js.map +1 -1
- package/lib/utils/useComboboxBaseState.js +48 -44
- package/lib/utils/useComboboxBaseState.js.map +1 -1
- package/lib/utils/useComboboxPopup.js +10 -6
- package/lib/utils/useComboboxPopup.js.map +1 -1
- package/lib/utils/useOptionCollection.js +13 -23
- package/lib/utils/useOptionCollection.js.map +1 -1
- package/lib/utils/useScrollOptionsIntoView.js +36 -0
- package/lib/utils/useScrollOptionsIntoView.js.map +1 -0
- package/lib/utils/useSelection.js +20 -14
- package/lib/utils/useSelection.js.map +1 -1
- package/lib/utils/useTriggerListboxSlots.js +46 -57
- package/lib/utils/useTriggerListboxSlots.js.map +1 -1
- package/lib-amd/Combobox.js +6 -0
- package/lib-amd/Combobox.js.map +1 -0
- package/lib-amd/ComboboxField.js +6 -0
- package/lib-amd/ComboboxField.js.map +1 -0
- package/lib-amd/Dropdown.js +6 -0
- package/lib-amd/Dropdown.js.map +1 -0
- package/lib-amd/Listbox.js +6 -0
- package/lib-amd/Listbox.js.map +1 -0
- package/lib-amd/Option.js +6 -0
- package/lib-amd/Option.js.map +1 -0
- package/lib-amd/OptionGroup.js +6 -0
- package/lib-amd/OptionGroup.js.map +1 -0
- package/lib-amd/components/Combobox/Combobox.js +16 -0
- package/lib-amd/components/Combobox/Combobox.js.map +1 -0
- package/lib-amd/components/Combobox/Combobox.types.js +5 -0
- package/lib-amd/components/Combobox/Combobox.types.js.map +1 -0
- package/lib-amd/components/Combobox/index.js +10 -0
- package/lib-amd/components/Combobox/index.js.map +1 -0
- package/lib-amd/components/Combobox/renderCombobox.js +20 -0
- package/lib-amd/components/Combobox/renderCombobox.js.map +1 -0
- package/lib-amd/components/Combobox/useCombobox.js +206 -0
- package/lib-amd/components/Combobox/useCombobox.js.map +1 -0
- package/lib-amd/components/Combobox/useComboboxStyles.js +152 -0
- package/lib-amd/components/Combobox/useComboboxStyles.js.map +1 -0
- package/lib-amd/components/ComboboxField/ComboboxField.js +10 -0
- package/lib-amd/components/ComboboxField/ComboboxField.js.map +1 -0
- package/lib-amd/components/ComboboxField/index.js +6 -0
- package/lib-amd/components/ComboboxField/index.js.map +1 -0
- package/lib-amd/components/Dropdown/Dropdown.js +16 -0
- package/lib-amd/components/Dropdown/Dropdown.js.map +1 -0
- package/lib-amd/components/Dropdown/Dropdown.types.js +5 -0
- package/lib-amd/components/Dropdown/Dropdown.types.js.map +1 -0
- package/lib-amd/components/Dropdown/index.js +10 -0
- package/lib-amd/components/Dropdown/index.js.map +1 -0
- package/lib-amd/components/Dropdown/renderDropdown.js +21 -0
- package/lib-amd/components/Dropdown/renderDropdown.js.map +1 -0
- package/lib-amd/components/Dropdown/useDropdown.js +121 -0
- package/lib-amd/components/Dropdown/useDropdown.js.map +1 -0
- package/lib-amd/components/Dropdown/useDropdownStyles.js +127 -0
- package/lib-amd/components/Dropdown/useDropdownStyles.js.map +1 -0
- package/lib-amd/components/Listbox/Listbox.js +16 -0
- package/lib-amd/components/Listbox/Listbox.js.map +1 -0
- package/lib-amd/components/Listbox/Listbox.types.js +5 -0
- package/lib-amd/components/Listbox/Listbox.types.js.map +1 -0
- package/lib-amd/components/Listbox/index.js +10 -0
- package/lib-amd/components/Listbox/index.js.map +1 -0
- package/lib-amd/components/Listbox/renderListbox.js +15 -0
- package/lib-amd/components/Listbox/renderListbox.js.map +1 -0
- package/lib-amd/components/Listbox/useListbox.js +80 -0
- package/lib-amd/components/Listbox/useListbox.js.map +1 -0
- package/lib-amd/components/Listbox/useListboxStyles.js +24 -0
- package/lib-amd/components/Listbox/useListboxStyles.js.map +1 -0
- package/lib-amd/components/Option/Option.js +15 -0
- package/lib-amd/components/Option/Option.js.map +1 -0
- package/lib-amd/components/Option/Option.types.js +5 -0
- package/lib-amd/components/Option/Option.types.js.map +1 -0
- package/lib-amd/components/Option/index.js +10 -0
- package/lib-amd/components/Option/index.js.map +1 -0
- package/lib-amd/components/Option/renderOption.js +16 -0
- package/lib-amd/components/Option/renderOption.js.map +1 -0
- package/lib-amd/components/Option/useOption.js +117 -0
- package/lib-amd/components/Option/useOption.js.map +1 -0
- package/lib-amd/components/Option/useOptionStyles.js +73 -0
- package/lib-amd/components/Option/useOptionStyles.js.map +1 -0
- package/lib-amd/components/OptionGroup/OptionGroup.js +15 -0
- package/lib-amd/components/OptionGroup/OptionGroup.js.map +1 -0
- package/lib-amd/components/OptionGroup/OptionGroup.types.js +5 -0
- package/lib-amd/components/OptionGroup/OptionGroup.types.js.map +1 -0
- package/lib-amd/components/OptionGroup/index.js +10 -0
- package/lib-amd/components/OptionGroup/index.js.map +1 -0
- package/lib-amd/components/OptionGroup/renderOptionGroup.js +16 -0
- package/lib-amd/components/OptionGroup/renderOptionGroup.js.map +1 -0
- package/lib-amd/components/OptionGroup/useOptionGroup.js +33 -0
- package/lib-amd/components/OptionGroup/useOptionGroup.js.map +1 -0
- package/lib-amd/components/OptionGroup/useOptionGroupStyles.js +34 -0
- package/lib-amd/components/OptionGroup/useOptionGroupStyles.js.map +1 -0
- package/lib-amd/contexts/ComboboxContext.js +28 -0
- package/lib-amd/contexts/ComboboxContext.js.map +1 -0
- package/lib-amd/contexts/ListboxContext.js +23 -0
- package/lib-amd/contexts/ListboxContext.js.map +1 -0
- package/lib-amd/contexts/useComboboxContextValues.js +23 -0
- package/lib-amd/contexts/useComboboxContextValues.js.map +1 -0
- package/lib-amd/contexts/useListboxContextValues.js +24 -0
- package/lib-amd/contexts/useListboxContextValues.js.map +1 -0
- package/lib-amd/index.js +37 -0
- package/lib-amd/index.js.map +1 -0
- package/lib-amd/utils/ComboboxBase.types.js +5 -0
- package/lib-amd/utils/ComboboxBase.types.js.map +1 -0
- package/lib-amd/utils/OptionCollection.types.js +5 -0
- package/lib-amd/utils/OptionCollection.types.js.map +1 -0
- package/lib-amd/utils/Selection.types.js +5 -0
- package/lib-amd/utils/Selection.types.js.map +1 -0
- package/lib-amd/utils/dropdownKeyActions.js +85 -0
- package/lib-amd/utils/dropdownKeyActions.js.map +1 -0
- package/lib-amd/utils/internalTokens.js +11 -0
- package/lib-amd/utils/internalTokens.js.map +1 -0
- package/lib-amd/utils/useComboboxBaseState.js +76 -0
- package/lib-amd/utils/useComboboxBaseState.js.map +1 -0
- package/lib-amd/utils/useComboboxPopup.js +16 -0
- package/lib-amd/utils/useComboboxPopup.js.map +1 -0
- package/lib-amd/utils/useOptionCollection.js +65 -0
- package/lib-amd/utils/useOptionCollection.js.map +1 -0
- package/lib-amd/utils/useScrollOptionsIntoView.js +33 -0
- package/lib-amd/utils/useScrollOptionsIntoView.js.map +1 -0
- package/lib-amd/utils/useSelection.js +42 -0
- package/lib-amd/utils/useSelection.js.map +1 -0
- package/lib-amd/utils/useTriggerListboxSlots.js +104 -0
- package/lib-amd/utils/useTriggerListboxSlots.js.map +1 -0
- package/lib-commonjs/Combobox.js +0 -2
- package/lib-commonjs/Combobox.js.map +1 -1
- package/lib-commonjs/ComboboxField.js +8 -0
- package/lib-commonjs/ComboboxField.js.map +1 -0
- package/lib-commonjs/Dropdown.js +0 -2
- package/lib-commonjs/Dropdown.js.map +1 -1
- package/lib-commonjs/Listbox.js +0 -2
- package/lib-commonjs/Listbox.js.map +1 -1
- package/lib-commonjs/Option.js +0 -2
- package/lib-commonjs/Option.js.map +1 -1
- package/lib-commonjs/OptionGroup.js +0 -2
- package/lib-commonjs/OptionGroup.js.map +1 -1
- package/lib-commonjs/components/Combobox/Combobox.js +0 -7
- package/lib-commonjs/components/Combobox/Combobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/Combobox.types.js.map +1 -1
- package/lib-commonjs/components/Combobox/index.js +0 -6
- package/lib-commonjs/components/Combobox/index.js.map +1 -1
- package/lib-commonjs/components/Combobox/renderCombobox.js +11 -14
- package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useCombobox.js +190 -24
- package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useComboboxStyles.js +252 -165
- package/lib-commonjs/components/Combobox/useComboboxStyles.js.map +1 -1
- package/lib-commonjs/components/ComboboxField/ComboboxField.js +14 -0
- package/lib-commonjs/components/ComboboxField/ComboboxField.js.map +1 -0
- package/lib-commonjs/components/ComboboxField/index.js +8 -0
- package/lib-commonjs/components/ComboboxField/index.js.map +1 -0
- package/lib-commonjs/components/Dropdown/Dropdown.js +0 -7
- package/lib-commonjs/components/Dropdown/Dropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/Dropdown.types.js.map +1 -1
- package/lib-commonjs/components/Dropdown/index.js +0 -6
- package/lib-commonjs/components/Dropdown/index.js.map +1 -1
- package/lib-commonjs/components/Dropdown/renderDropdown.js +11 -14
- package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdown.js +89 -17
- package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdownStyles.js +236 -159
- package/lib-commonjs/components/Dropdown/useDropdownStyles.js.map +1 -1
- package/lib-commonjs/components/Listbox/Listbox.js +0 -7
- package/lib-commonjs/components/Listbox/Listbox.js.map +1 -1
- package/lib-commonjs/components/Listbox/Listbox.types.js.map +1 -1
- package/lib-commonjs/components/Listbox/index.js +0 -6
- package/lib-commonjs/components/Listbox/index.js.map +1 -1
- package/lib-commonjs/components/Listbox/renderListbox.js +2 -7
- package/lib-commonjs/components/Listbox/renderListbox.js.map +1 -1
- package/lib-commonjs/components/Listbox/useListbox.js +34 -37
- package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
- package/lib-commonjs/components/Listbox/useListboxStyles.js +16 -24
- package/lib-commonjs/components/Listbox/useListboxStyles.js.map +1 -1
- package/lib-commonjs/components/Option/Option.js +0 -6
- package/lib-commonjs/components/Option/Option.js.map +1 -1
- package/lib-commonjs/components/Option/Option.types.js.map +1 -1
- package/lib-commonjs/components/Option/index.js +0 -6
- package/lib-commonjs/components/Option/index.js.map +1 -1
- package/lib-commonjs/components/Option/renderOption.js +4 -7
- package/lib-commonjs/components/Option/renderOption.js.map +1 -1
- package/lib-commonjs/components/Option/useOption.js +60 -52
- package/lib-commonjs/components/Option/useOption.js.map +1 -1
- package/lib-commonjs/components/Option/useOptionStyles.js +103 -84
- package/lib-commonjs/components/Option/useOptionStyles.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/OptionGroup.js +0 -6
- package/lib-commonjs/components/OptionGroup/OptionGroup.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/OptionGroup.types.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/index.js +0 -6
- package/lib-commonjs/components/OptionGroup/index.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/renderOptionGroup.js +4 -7
- package/lib-commonjs/components/OptionGroup/renderOptionGroup.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/useOptionGroup.js +0 -4
- package/lib-commonjs/components/OptionGroup/useOptionGroup.js.map +1 -1
- package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js +29 -38
- package/lib-commonjs/components/OptionGroup/useOptionGroupStyles.js.map +1 -1
- package/lib-commonjs/contexts/ComboboxContext.js +15 -12
- package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
- package/lib-commonjs/contexts/ListboxContext.js +12 -11
- package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
- package/lib-commonjs/contexts/useComboboxContextValues.js +8 -4
- package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
- package/lib-commonjs/contexts/useListboxContextValues.js +10 -10
- package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
- package/lib-commonjs/index.js +43 -11
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utils/ComboboxBase.types.js.map +1 -1
- package/lib-commonjs/utils/OptionCollection.types.js.map +1 -1
- package/lib-commonjs/utils/Selection.types.js.map +1 -1
- package/lib-commonjs/utils/dropdownKeyActions.js +14 -46
- package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
- package/lib-commonjs/utils/internalTokens.js.map +1 -1
- package/lib-commonjs/utils/useComboboxBaseState.js +48 -50
- package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
- package/lib-commonjs/utils/useComboboxPopup.js +10 -10
- package/lib-commonjs/utils/useComboboxPopup.js.map +1 -1
- package/lib-commonjs/utils/useOptionCollection.js +13 -26
- package/lib-commonjs/utils/useOptionCollection.js.map +1 -1
- package/lib-commonjs/utils/useScrollOptionsIntoView.js +43 -0
- package/lib-commonjs/utils/useScrollOptionsIntoView.js.map +1 -0
- package/lib-commonjs/utils/useSelection.js +20 -17
- package/lib-commonjs/utils/useSelection.js.map +1 -1
- package/lib-commonjs/utils/useTriggerListboxSlots.js +45 -61
- package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
- package/package.json +24 -23
- package/Spec-migration.md +0 -13
- package/Spec.md +0 -520
- package/dist/tsdoc-metadata.json +0 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Combobox.types.js","sourceRoot":"../src/","sources":["components/Combobox/Combobox.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\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 ComboboxSlots = {\n /* The root combobox slot */\n root: NonNullable<Slot<'div'>>;\n\n /* The dropdown arrow icon */\n expandIcon: Slot<'span'>;\n\n /* The primary slot, an input with role=\"combobox\" */\n input: NonNullable<Slot<'input'>>;\n\n /* The dropdown listbox slot */\n listbox
|
|
1
|
+
{"version":3,"file":"Combobox.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Combobox/Combobox.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\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 ComboboxSlots = {\n /* The root combobox slot */\n root: NonNullable<Slot<'div'>>;\n\n /* The dropdown arrow icon */\n expandIcon: Slot<'span'>;\n\n /* The primary slot, an input with role=\"combobox\" */\n input: NonNullable<Slot<'input'>>;\n\n /* The dropdown listbox slot */\n listbox?: Slot<typeof Listbox>;\n};\n\n/**\n * Combobox Props\n */\nexport type ComboboxProps = Omit<ComponentProps<Partial<ComboboxSlots>, 'input'>, 'children' | 'size'> &\n ComboboxBaseProps & {\n /*\n * Whether the ComboBox allows freeform user input, rather than restricting to the provided options.\n */\n freeform?: boolean;\n\n /*\n * The primary slot, `<input>`, does not support children so we need to explicitly include it here.\n */\n children?: React.ReactNode;\n };\n\n/**\n * State used in rendering Combobox\n */\nexport type ComboboxState = ComponentState<ComboboxSlots> & ComboboxBaseState;\n\n/* Export types defined in ComboboxBase */\nexport type ComboboxContextValues = ComboboxBaseContextValues;\nexport type ComboboxOpenChangeData = ComboboxBaseOpenChangeData;\nexport type ComboboxOpenEvents = ComboboxBaseOpenEvents;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Combobox/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC","sourcesContent":["export * from './Combobox';\nexport * from './Combobox.types';\nexport * from './renderCombobox';\nexport * from './useCombobox';\nexport * from './useComboboxStyles';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Combobox/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC","sourcesContent":["export * from './Combobox';\nexport * from './Combobox.types';\nexport * from './renderCombobox';\nexport * from './useCombobox';\nexport * from './useComboboxStyles';\n"]}
|
|
@@ -5,20 +5,23 @@ import { ComboboxContext } from '../../contexts/ComboboxContext';
|
|
|
5
5
|
/**
|
|
6
6
|
* Render the final JSX of Combobox
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
8
|
export const renderCombobox_unstable = (state, contextValues) => {
|
|
10
9
|
const {
|
|
11
10
|
slots,
|
|
12
11
|
slotProps
|
|
13
12
|
} = getSlots(state);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const popup = state.inlinePopup ? listbox : /*#__PURE__*/React.createElement(Portal, null, listbox);
|
|
17
|
-
return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
|
13
|
+
return /*#__PURE__*/React.createElement(slots.root, {
|
|
14
|
+
...slotProps.root
|
|
18
15
|
}, /*#__PURE__*/React.createElement(ComboboxContext.Provider, {
|
|
19
16
|
value: contextValues.combobox
|
|
20
|
-
}, /*#__PURE__*/React.createElement(slots.input, {
|
|
21
|
-
|
|
22
|
-
}),
|
|
17
|
+
}, /*#__PURE__*/React.createElement(slots.input, {
|
|
18
|
+
...slotProps.input
|
|
19
|
+
}), slots.expandIcon && /*#__PURE__*/React.createElement(slots.expandIcon, {
|
|
20
|
+
...slotProps.expandIcon
|
|
21
|
+
}), slots.listbox && (state.inlinePopup ? /*#__PURE__*/React.createElement(slots.listbox, {
|
|
22
|
+
...slotProps.listbox
|
|
23
|
+
}) : /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(slots.listbox, {
|
|
24
|
+
...slotProps.listbox
|
|
25
|
+
})))));
|
|
23
26
|
};
|
|
24
27
|
//# sourceMappingURL=renderCombobox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,MAAM,QAAQ,wBAAwB;AAC/C,SAASC,QAAQ,QAAQ,2BAA2B;AACpD,SAASC,eAAe,QAAQ,gCAAgC;AAGhE;;;AAGA,OAAO,MAAMC,uBAAuB,GAAG,CAACC,KAAoB,EAAEC,aAAoC,KAAI;EACpG,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGN,QAAQ,CAAgBG,KAAK,CAAC;EAE3D,oBACEL,oBAACO,KAAK,CAACE,IAAI;IAAA,GAAKD,SAAS,CAACC;EAAI,gBAC5BT,oBAACG,eAAe,CAACO,QAAQ;IAACC,KAAK,EAAEL,aAAa,CAACM;EAAQ,gBACrDZ,oBAACO,KAAK,CAACM,KAAK;IAAA,GAAKL,SAAS,CAACK;EAAK,EAAI,EACnCN,KAAK,CAACO,UAAU,iBAAId,oBAACO,KAAK,CAACO,UAAU;IAAA,GAAKN,SAAS,CAACM;EAAU,EAAI,EAClEP,KAAK,CAACQ,OAAO,KACXV,KAAK,CAACW,WAAW,gBAChBhB,oBAACO,KAAK,CAACQ,OAAO;IAAA,GAAKP,SAAS,CAACO;EAAO,EAAI,gBAExCf,oBAACC,MAAM,qBACLD,oBAACO,KAAK,CAACQ,OAAO;IAAA,GAAKP,SAAS,CAACO;EAAO,EAAI,CAE3C,CAAC,CACqB,CAChB;AAEjB,CAAC","names":["React","Portal","getSlots","ComboboxContext","renderCombobox_unstable","state","contextValues","slots","slotProps","root","Provider","value","combobox","input","expandIcon","listbox","inlinePopup"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Combobox/renderCombobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Portal } from '@fluentui/react-portal';\nimport { getSlots } from '@fluentui/react-utilities';\nimport { ComboboxContext } from '../../contexts/ComboboxContext';\nimport type { ComboboxContextValues, ComboboxState, ComboboxSlots } from './Combobox.types';\n\n/**\n * Render the final JSX of Combobox\n */\nexport const renderCombobox_unstable = (state: ComboboxState, contextValues: ComboboxContextValues) => {\n const { slots, slotProps } = getSlots<ComboboxSlots>(state);\n\n return (\n <slots.root {...slotProps.root}>\n <ComboboxContext.Provider value={contextValues.combobox}>\n <slots.input {...slotProps.input} />\n {slots.expandIcon && <slots.expandIcon {...slotProps.expandIcon} />}\n {slots.listbox &&\n (state.inlinePopup ? (\n <slots.listbox {...slotProps.listbox} />\n ) : (\n <Portal>\n <slots.listbox {...slotProps.listbox} />\n </Portal>\n ))}\n </ComboboxContext.Provider>\n </slots.root>\n );\n};\n"]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';
|
|
2
3
|
import { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';
|
|
3
|
-
import { getPartitionedNativeProps, resolveShorthand } from '@fluentui/react-utilities';
|
|
4
|
+
import { getPartitionedNativeProps, resolveShorthand, mergeCallbacks, useEventCallback, useId, useMergedRefs } from '@fluentui/react-utilities';
|
|
5
|
+
import { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';
|
|
4
6
|
import { useComboboxBaseState } from '../../utils/useComboboxBaseState';
|
|
5
|
-
import { useTriggerListboxSlots } from '../../utils/useTriggerListboxSlots';
|
|
6
7
|
import { useComboboxPopup } from '../../utils/useComboboxPopup';
|
|
8
|
+
import { useTriggerListboxSlots } from '../../utils/useTriggerListboxSlots';
|
|
7
9
|
import { Listbox } from '../Listbox/Listbox';
|
|
8
10
|
/**
|
|
9
11
|
* Create the state required to render Combobox.
|
|
@@ -14,9 +16,34 @@ import { Listbox } from '../Listbox/Listbox';
|
|
|
14
16
|
* @param props - props from this instance of Combobox
|
|
15
17
|
* @param ref - reference to root HTMLElement of Combobox
|
|
16
18
|
*/
|
|
17
|
-
|
|
18
19
|
export const useCombobox_unstable = (props, ref) => {
|
|
19
|
-
|
|
20
|
+
var _a, _b;
|
|
21
|
+
const baseState = useComboboxBaseState({
|
|
22
|
+
...props,
|
|
23
|
+
editable: true
|
|
24
|
+
});
|
|
25
|
+
const {
|
|
26
|
+
activeOption,
|
|
27
|
+
clearSelection,
|
|
28
|
+
getIndexOfId,
|
|
29
|
+
getOptionsMatchingText,
|
|
30
|
+
hasFocus,
|
|
31
|
+
open,
|
|
32
|
+
selectOption,
|
|
33
|
+
selectedOptions,
|
|
34
|
+
setActiveOption,
|
|
35
|
+
setFocusVisible,
|
|
36
|
+
setOpen,
|
|
37
|
+
setValue,
|
|
38
|
+
value
|
|
39
|
+
} = baseState;
|
|
40
|
+
const {
|
|
41
|
+
disabled,
|
|
42
|
+
freeform,
|
|
43
|
+
inlinePopup,
|
|
44
|
+
multiselect
|
|
45
|
+
} = props;
|
|
46
|
+
const comboId = useId('combobox-');
|
|
20
47
|
const {
|
|
21
48
|
primary: triggerNativeProps,
|
|
22
49
|
root: rootNativeProps
|
|
@@ -25,22 +52,123 @@ export const useCombobox_unstable = (props, ref) => {
|
|
|
25
52
|
primarySlotTagName: 'input',
|
|
26
53
|
excludedPropNames: ['children', 'size']
|
|
27
54
|
});
|
|
28
|
-
const
|
|
55
|
+
const rootRef = React.useRef(null);
|
|
56
|
+
const triggerRef = React.useRef(null);
|
|
57
|
+
// NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set
|
|
58
|
+
// To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows
|
|
59
|
+
// ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888
|
|
60
|
+
const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);
|
|
61
|
+
// calculate listbox width style based on trigger width
|
|
62
|
+
const [popupDimensions, setPopupDimensions] = React.useState();
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
var _a;
|
|
65
|
+
// only recalculate width when opening
|
|
66
|
+
if (open) {
|
|
67
|
+
const width = `${(_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth}px`;
|
|
68
|
+
if (width !== (popupDimensions === null || popupDimensions === void 0 ? void 0 : popupDimensions.width)) {
|
|
69
|
+
setPopupDimensions({
|
|
70
|
+
width
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}, [open, popupDimensions]);
|
|
75
|
+
// set active option and selection based on typing
|
|
76
|
+
const getOptionFromInput = inputValue => {
|
|
77
|
+
var _a;
|
|
78
|
+
const searchString = inputValue === null || inputValue === void 0 ? void 0 : inputValue.trim().toLowerCase();
|
|
79
|
+
if (!searchString || searchString.length === 0) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const matcher = optionText => optionText.toLowerCase().indexOf(searchString) === 0;
|
|
83
|
+
const matches = getOptionsMatchingText(matcher);
|
|
84
|
+
// return first matching option after the current active option, looping back to the top
|
|
85
|
+
if (matches.length > 1 && activeOption) {
|
|
86
|
+
const startIndex = getIndexOfId(activeOption.id);
|
|
87
|
+
const nextMatch = matches.find(option => getIndexOfId(option.id) >= startIndex);
|
|
88
|
+
return nextMatch !== null && nextMatch !== void 0 ? nextMatch : matches[0];
|
|
89
|
+
}
|
|
90
|
+
return (_a = matches[0]) !== null && _a !== void 0 ? _a : undefined;
|
|
91
|
+
};
|
|
92
|
+
/* Handle typed input */
|
|
93
|
+
// reset any typed value when an option is selected
|
|
94
|
+
baseState.selectOption = (ev, option) => {
|
|
95
|
+
setValue(undefined);
|
|
96
|
+
selectOption(ev, option);
|
|
97
|
+
};
|
|
98
|
+
const onTriggerBlur = ev => {
|
|
99
|
+
// handle selection and updating value if freeform is false
|
|
100
|
+
if (!baseState.open && !freeform) {
|
|
101
|
+
// select matching option, if the value fully matches
|
|
102
|
+
if (value && activeOption && value.trim().toLowerCase() === (activeOption === null || activeOption === void 0 ? void 0 : activeOption.value.toLowerCase())) {
|
|
103
|
+
baseState.selectOption(ev, activeOption);
|
|
104
|
+
}
|
|
105
|
+
// reset typed value when the input loses focus while collapsed, unless freeform is true
|
|
106
|
+
setValue(undefined);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
baseState.setOpen = (ev, newState) => {
|
|
110
|
+
if (disabled) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!newState && !freeform) {
|
|
114
|
+
setValue(undefined);
|
|
115
|
+
}
|
|
116
|
+
setOpen(ev, newState);
|
|
117
|
+
};
|
|
118
|
+
// update value and active option based on input
|
|
119
|
+
const onTriggerChange = ev => {
|
|
120
|
+
const inputValue = ev.target.value;
|
|
121
|
+
// update uncontrolled value
|
|
122
|
+
baseState.setValue(inputValue);
|
|
123
|
+
// handle updating active option based on input
|
|
124
|
+
const matchingOption = getOptionFromInput(inputValue);
|
|
125
|
+
setActiveOption(matchingOption);
|
|
126
|
+
setFocusVisible(true);
|
|
127
|
+
// clear selection for single-select if the input value no longer matches the selection
|
|
128
|
+
if (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || selectedOptions[0].indexOf(inputValue) !== 0)) {
|
|
129
|
+
clearSelection(ev);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
// open Combobox when typing
|
|
133
|
+
const onTriggerKeyDown = ev => {
|
|
134
|
+
if (!open && getDropdownActionFromKey(ev) === 'Type') {
|
|
135
|
+
baseState.setOpen(ev, true);
|
|
136
|
+
}
|
|
137
|
+
// clear activedescendant when moving the text insertion cursor
|
|
138
|
+
if (ev.key === ArrowLeft || ev.key === ArrowRight) {
|
|
139
|
+
setHideActiveDescendant(true);
|
|
140
|
+
} else {
|
|
141
|
+
setHideActiveDescendant(false);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
// resolve input and listbox slot props
|
|
145
|
+
let triggerSlot;
|
|
146
|
+
let listboxSlot;
|
|
147
|
+
triggerSlot = resolveShorthand(props.input, {
|
|
29
148
|
required: true,
|
|
30
149
|
defaultProps: {
|
|
31
|
-
|
|
32
|
-
/* Combobox does not yet support allowFreeForm */
|
|
33
|
-
},
|
|
150
|
+
ref: useMergedRefs((_a = props.input) === null || _a === void 0 ? void 0 : _a.ref, triggerRef),
|
|
34
151
|
type: 'text',
|
|
35
|
-
value:
|
|
152
|
+
value: value !== null && value !== void 0 ? value : '',
|
|
36
153
|
...triggerNativeProps
|
|
37
154
|
}
|
|
38
155
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
156
|
+
triggerSlot.onChange = mergeCallbacks(triggerSlot.onChange, onTriggerChange);
|
|
157
|
+
triggerSlot.onBlur = mergeCallbacks(triggerSlot.onBlur, onTriggerBlur);
|
|
158
|
+
triggerSlot.onKeyDown = mergeCallbacks(triggerSlot.onKeyDown, onTriggerKeyDown);
|
|
159
|
+
// only resolve listbox slot if needed
|
|
160
|
+
listboxSlot = open || hasFocus ? resolveShorthand(props.listbox, {
|
|
161
|
+
required: true,
|
|
162
|
+
defaultProps: {
|
|
163
|
+
children: props.children,
|
|
164
|
+
style: popupDimensions
|
|
165
|
+
}
|
|
166
|
+
}) : undefined;
|
|
167
|
+
[triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);
|
|
168
|
+
[triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);
|
|
169
|
+
if (hideActiveDescendant) {
|
|
170
|
+
triggerSlot['aria-activedescendant'] = undefined;
|
|
171
|
+
}
|
|
44
172
|
const state = {
|
|
45
173
|
components: {
|
|
46
174
|
root: 'div',
|
|
@@ -51,7 +179,7 @@ export const useCombobox_unstable = (props, ref) => {
|
|
|
51
179
|
root: resolveShorthand(props.root, {
|
|
52
180
|
required: true,
|
|
53
181
|
defaultProps: {
|
|
54
|
-
|
|
182
|
+
'aria-owns': !inlinePopup ? listboxSlot === null || listboxSlot === void 0 ? void 0 : listboxSlot.id : undefined,
|
|
55
183
|
...rootNativeProps
|
|
56
184
|
}
|
|
57
185
|
}),
|
|
@@ -60,11 +188,58 @@ export const useCombobox_unstable = (props, ref) => {
|
|
|
60
188
|
expandIcon: resolveShorthand(props.expandIcon, {
|
|
61
189
|
required: true,
|
|
62
190
|
defaultProps: {
|
|
63
|
-
|
|
191
|
+
'aria-expanded': open,
|
|
192
|
+
children: /*#__PURE__*/React.createElement(ChevronDownIcon, null),
|
|
193
|
+
role: 'button'
|
|
64
194
|
}
|
|
65
195
|
}),
|
|
66
196
|
...baseState
|
|
67
197
|
};
|
|
198
|
+
state.root.ref = useMergedRefs(state.root.ref, rootRef);
|
|
199
|
+
/* handle open/close + focus change when clicking expandIcon */
|
|
200
|
+
const {
|
|
201
|
+
onMouseDown: onIconMouseDown,
|
|
202
|
+
onClick: onIconClick
|
|
203
|
+
} = state.expandIcon || {};
|
|
204
|
+
const onExpandIconMouseDown = useEventCallback(mergeCallbacks(onIconMouseDown, () => {
|
|
205
|
+
// do not dismiss on blur when closing via clicking the icon
|
|
206
|
+
if (open) {
|
|
207
|
+
baseState.ignoreNextBlur.current = true;
|
|
208
|
+
}
|
|
209
|
+
}));
|
|
210
|
+
const onExpandIconClick = useEventCallback(mergeCallbacks(onIconClick, event => {
|
|
211
|
+
var _a;
|
|
212
|
+
// open and set focus
|
|
213
|
+
state.setOpen(event, !state.open);
|
|
214
|
+
(_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
215
|
+
// set focus visible=false, since this can only be done with the mouse/pointer
|
|
216
|
+
setFocusVisible(false);
|
|
217
|
+
}));
|
|
218
|
+
if (state.expandIcon) {
|
|
219
|
+
state.expandIcon.onMouseDown = onExpandIconMouseDown;
|
|
220
|
+
state.expandIcon.onClick = onExpandIconClick;
|
|
221
|
+
// If there is no explicit aria-label, calculate default accName attribute for expandIcon button,
|
|
222
|
+
// using the following steps:
|
|
223
|
+
// 1. If there is an aria-label, it is "Open [aria-label]"
|
|
224
|
+
// 2. If there is an aria-labelledby, it is "Open [aria-labelledby target]" (using aria-labelledby + ids)
|
|
225
|
+
// 3. If there is no aria-label/ledby attr, it falls back to "Open"
|
|
226
|
+
// We can't fall back to a label/htmlFor name because of https://github.com/w3c/accname/issues/179
|
|
227
|
+
const hasExpandLabel = state.expandIcon['aria-label'] || state.expandIcon['aria-labelledby'];
|
|
228
|
+
const defaultOpenString = 'Open'; // this is english-only since it is the fallback
|
|
229
|
+
if (!hasExpandLabel) {
|
|
230
|
+
if (props['aria-labelledby']) {
|
|
231
|
+
const chevronId = (_b = state.expandIcon.id) !== null && _b !== void 0 ? _b : `${comboId}-chevron`;
|
|
232
|
+
const chevronLabelledBy = `${chevronId} ${state.input['aria-labelledby']}`;
|
|
233
|
+
state.expandIcon['aria-label'] = defaultOpenString;
|
|
234
|
+
state.expandIcon.id = chevronId;
|
|
235
|
+
state.expandIcon['aria-labelledby'] = chevronLabelledBy;
|
|
236
|
+
} else if (props['aria-label']) {
|
|
237
|
+
state.expandIcon['aria-label'] = `${defaultOpenString} ${props['aria-label']}`;
|
|
238
|
+
} else {
|
|
239
|
+
state.expandIcon['aria-label'] = defaultOpenString;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
68
243
|
return state;
|
|
69
244
|
};
|
|
70
245
|
//# sourceMappingURL=useCombobox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/Combobox/useCombobox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,kBAAkB,IAAI,eAA/B,QAAsD,uBAAtD;AACA,SAAS,yBAAT,EAAoC,gBAApC,QAA4D,2BAA5D;AACA,SAAS,oBAAT,QAAqC,kCAArC;AACA,SAAS,sBAAT,QAAuC,oCAAvC;AACA,SAAS,gBAAT,QAAiC,8BAAjC;AACA,SAAS,OAAT,QAAwB,oBAAxB;AAGA;;;;;;;;AAQG;;AACH,OAAO,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AdoB;IAe3B,OAAO,EAAE,WAfkB;IAgB3B,UAAU,EAAE,gBAAgB,CAAC,KAAK,CAAC,UAAP,EAAmB;MAC7C,QAAQ,EAAE,IADmC;MAE7C,YAAY,EAAE;QACZ,QAAQ,eAAE,KAAA,CAAA,aAAA,CAAC,eAAD,EAAgB,IAAhB;MADE;IAF+B,CAAnB,CAhBD;IAsB3B,GAAG;EAtBwB,CAA7B;EAyBA,OAAO,KAAP;AACD,CApDM","sourcesContent":["import * as React from 'react';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport { getPartitionedNativeProps, resolveShorthand } from '@fluentui/react-utilities';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useTriggerListboxSlots } from '../../utils/useTriggerListboxSlots';\nimport { useComboboxPopup } from '../../utils/useComboboxPopup';\nimport { Listbox } from '../Listbox/Listbox';\nimport type { ComboboxProps, ComboboxState } from './Combobox.types';\n\n/**\n * Create the state required to render Combobox.\n *\n * The returned state can be modified with hooks such as useComboboxStyles_unstable,\n * before being passed to renderCombobox_unstable.\n *\n * @param props - props from this instance of Combobox\n * @param ref - reference to root HTMLElement of Combobox\n */\nexport const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLInputElement>): ComboboxState => {\n const baseState = useComboboxBaseState(props);\n\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['children', 'size'],\n });\n\n const triggerShorthand = resolveShorthand(props.input, {\n required: true,\n defaultProps: {\n onChange: () => {\n /* Combobox does not yet support allowFreeForm */\n },\n type: 'text',\n value: baseState.value,\n ...triggerNativeProps,\n },\n });\n\n const listboxShorthand = resolveShorthand(props.listbox, { required: true });\n\n const [triggerWithPopup, listboxWithPopup] = useComboboxPopup(props, triggerShorthand, listboxShorthand);\n const [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerWithPopup, listboxWithPopup);\n\n const state: ComboboxState = {\n components: {\n root: 'div',\n input: 'input',\n expandIcon: 'span',\n listbox: Listbox,\n },\n root: resolveShorthand(props.root, {\n required: true,\n defaultProps: {\n children: props.children,\n ...rootNativeProps,\n },\n }),\n input: triggerSlot,\n listbox: listboxSlot,\n expandIcon: resolveShorthand(props.expandIcon, {\n required: true,\n defaultProps: {\n children: <ChevronDownIcon />,\n },\n }),\n ...baseState,\n };\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,SAAS,EAAEC,UAAU,QAAQ,yBAAyB;AAC/D,SAASC,kBAAkB,IAAIC,eAAe,QAAQ,uBAAuB;AAC7E,SACEC,yBAAyB,EACzBC,gBAAgB,EAChBC,cAAc,EACdC,gBAAgB,EAChBC,KAAK,EACLC,aAAa,QACR,2BAA2B;AAClC,SAASC,wBAAwB,QAAQ,gCAAgC;AACzE,SAASC,oBAAoB,QAAQ,kCAAkC;AACvE,SAASC,gBAAgB,QAAQ,8BAA8B;AAC/D,SAASC,sBAAsB,QAAQ,oCAAoC;AAC3E,SAASC,OAAO,QAAQ,oBAAoB;AAM5C;;;;;;;;;AASA,OAAO,MAAMC,oBAAoB,GAAG,CAACC,KAAoB,EAAEC,GAAgC,KAAmB;;EAC5G,MAAMC,SAAS,GAAGP,oBAAoB,CAAC;IAAE,GAAGK,KAAK;IAAEG,QAAQ,EAAE;EAAI,CAAE,CAAC;EACpE,MAAM;IACJC,YAAY;IACZC,cAAc;IACdC,YAAY;IACZC,sBAAsB;IACtBC,QAAQ;IACRC,IAAI;IACJC,YAAY;IACZC,eAAe;IACfC,eAAe;IACfC,eAAe;IACfC,OAAO;IACPC,QAAQ;IACRC;EAAK,CACN,GAAGd,SAAS;EACb,MAAM;IAAEe,QAAQ;IAAEC,QAAQ;IAAEC,WAAW;IAAEC;EAAW,CAAE,GAAGpB,KAAK;EAC9D,MAAMqB,OAAO,GAAG7B,KAAK,CA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AACE,UAAU,CAAC,iBAAiB,CAAC;IAC5F,MAAMY,iBAAiB,GAAG,MAAM,CAAC,CAAC;IAClC,IAAI,CAACD,cAAc,EAAE;MACnB,IAAIzF,KAAK,CAAC,iBAAiB,CAAC,EAAE;QAC5B,MAAM2F,SAAS,GAAG,WAAK,CAACb,UAAU,CAAC3B,EAAE,mCAAI,GAAG9B,OAAO,UAAU;QAC7D,MAAMuE,iBAAiB,GAAG,GAAGD,SAAS,IAAIf,KAAK,CAACV,KAAK,CAAC,iBAAiB,CAAC,EAAE;QAE1EU,KAAK,CAACE,UAAU,CAAC,YAAY,CAAC,GAAGY,iBAAiB;QAClDd,KAAK,CAACE,UAAU,CAAC3B,EAAE,GAAGwC,SAAS;QAC/Bf,KAAK,CAACE,UAAU,CAAC,iBAAiB,CAAC,GAAGc,iBAAiB;OACxD,MAAM,IAAI5F,KAAK,CAAC,YAAY,CAAC,EAAE;QAC9B4E,KAAK,CAACE,UAAU,CAAC,YAAY,CAAC,GAAG,GAAGY,iBAAiB,IAAI1F,KAAK,CAAC,YAAY,CAAC,EAAE;OAC/E,MAAM;QACL4E,KAAK,CAACE,UAAU,CAAC,YAAY,CAAC,GAAGY,iBAAiB;;;;EAKxD,OAAOd,KAAK;AACd,CAAC","names":["React","ArrowLeft","ArrowRight","ChevronDownRegular","ChevronDownIcon","getPartitionedNativeProps","resolveShorthand","mergeCallbacks","useEventCallback","useId","useMergedRefs","getDropdownActionFromKey","useComboboxBaseState","useComboboxPopup","useTriggerListboxSlots","Listbox","useCombobox_unstable","props","ref","baseState","editable","activeOption","clearSelection","getIndexOfId","getOptionsMatchingText","hasFocus","open","selectOption","selectedOptions","setActiveOption","setFocusVisible","setOpen","setValue","value","disabled","freeform","inlinePopup","multiselect","comboId","primary","triggerNativeProps","root","rootNativeProps","primarySlotTagName","excludedPropNames","rootRef","useRef","triggerRef","hideActiveDescendant","setHideActiveDescendant","useState","popupDimensions","setPopupDimensions","useEffect","width","current","clientWidth","getOptionFromInput","inputValue","searchString","trim","toLowerCase","length","matcher","optionText","indexOf","matches","startIndex","id","nextMatch","find","option","undefined","ev","onTriggerBlur","newState","onTriggerChange","target","matchingOption","onTriggerKeyDown","key","triggerSlot","listboxSlot","input","required","defaultProps","type","onChange","onBlur","onKeyDown","listbox","children","style","state","components","expandIcon","role","onMouseDown","onIconMouseDown","onClick","onIconClick","onExpandIconMouseDown","ignoreNextBlur","onExpandIconClick","event","focus","hasExpandLabel","defaultOpenString","chevronId","chevronLabelledBy"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/components/Combobox/useCombobox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport {\n getPartitionedNativeProps,\n resolveShorthand,\n mergeCallbacks,\n useEventCallback,\n useId,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPopup } from '../../utils/useComboboxPopup';\nimport { useTriggerListboxSlots } from '../../utils/useTriggerListboxSlots';\nimport { Listbox } from '../Listbox/Listbox';\nimport type { Slot } from '@fluentui/react-utilities';\nimport type { SelectionEvents } from '../../utils/Selection.types';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport type { ComboboxProps, ComboboxState } from './Combobox.types';\n\n/**\n * Create the state required to render Combobox.\n *\n * The returned state can be modified with hooks such as useComboboxStyles_unstable,\n * before being passed to renderCombobox_unstable.\n *\n * @param props - props from this instance of Combobox\n * @param ref - reference to root HTMLElement of Combobox\n */\nexport const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLInputElement>): ComboboxState => {\n const baseState = useComboboxBaseState({ ...props, editable: true });\n const {\n activeOption,\n clearSelection,\n getIndexOfId,\n getOptionsMatchingText,\n hasFocus,\n open,\n selectOption,\n selectedOptions,\n setActiveOption,\n setFocusVisible,\n setOpen,\n setValue,\n value,\n } = baseState;\n const { disabled, freeform, inlinePopup, multiselect } = props;\n const comboId = useId('combobox-');\n\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['children', 'size'],\n });\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n const triggerRef = React.useRef<HTMLInputElement>(null);\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\n // calculate listbox width style based on trigger width\n const [popupDimensions, setPopupDimensions] = React.useState<{ width: string }>();\n React.useEffect(() => {\n // only recalculate width when opening\n if (open) {\n const width = `${rootRef.current?.clientWidth}px`;\n if (width !== popupDimensions?.width) {\n setPopupDimensions({ width });\n }\n }\n }, [open, popupDimensions]);\n\n // set active option and selection based on typing\n const getOptionFromInput = (inputValue: string): OptionValue | undefined => {\n const searchString = inputValue?.trim().toLowerCase();\n\n if (!searchString || searchString.length === 0) {\n return;\n }\n\n const matcher = (optionText: string) => optionText.toLowerCase().indexOf(searchString) === 0;\n const matches = getOptionsMatchingText(matcher);\n\n // return first matching option after the current active option, looping back to the top\n if (matches.length > 1 && activeOption) {\n const startIndex = getIndexOfId(activeOption.id);\n const nextMatch = matches.find(option => getIndexOfId(option.id) >= startIndex);\n return nextMatch ?? matches[0];\n }\n\n return matches[0] ?? undefined;\n };\n\n /* Handle typed input */\n\n // reset any typed value when an option is selected\n baseState.selectOption = (ev: SelectionEvents, option: OptionValue) => {\n setValue(undefined);\n selectOption(ev, option);\n };\n\n const onTriggerBlur = (ev: React.FocusEvent<HTMLInputElement>) => {\n // handle selection and updating value if freeform is false\n if (!baseState.open && !freeform) {\n // select matching option, if the value fully matches\n if (value && activeOption && value.trim().toLowerCase() === activeOption?.value.toLowerCase()) {\n baseState.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 baseState.setOpen = (ev, newState: boolean) => {\n if (disabled) {\n return;\n }\n\n if (!newState && !freeform) {\n setValue(undefined);\n }\n\n setOpen(ev, newState);\n };\n\n // update value and active option based on input\n const onTriggerChange = (ev: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = ev.target.value;\n // update uncontrolled value\n baseState.setValue(inputValue);\n\n // handle updating active option based on input\n const matchingOption = getOptionFromInput(inputValue);\n setActiveOption(matchingOption);\n\n setFocusVisible(true);\n\n // clear selection for single-select if the input value no longer matches the selection\n if (\n !multiselect &&\n selectedOptions.length === 1 &&\n (inputValue.length < 1 || selectedOptions[0].indexOf(inputValue) !== 0)\n ) {\n clearSelection(ev);\n }\n };\n\n // open Combobox when typing\n const onTriggerKeyDown = (ev: React.KeyboardEvent<HTMLInputElement>) => {\n if (!open && getDropdownActionFromKey(ev) === 'Type') {\n baseState.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\n // resolve input and listbox slot props\n let triggerSlot: Slot<'input'>;\n let listboxSlot: Slot<typeof Listbox> | undefined;\n\n triggerSlot = resolveShorthand(props.input, {\n required: true,\n defaultProps: {\n ref: useMergedRefs(props.input?.ref, triggerRef),\n type: 'text',\n value: value ?? '',\n ...triggerNativeProps,\n },\n });\n\n triggerSlot.onChange = mergeCallbacks(triggerSlot.onChange, onTriggerChange);\n triggerSlot.onBlur = mergeCallbacks(triggerSlot.onBlur, onTriggerBlur);\n triggerSlot.onKeyDown = mergeCallbacks(triggerSlot.onKeyDown, onTriggerKeyDown);\n\n // only resolve listbox slot if needed\n listboxSlot =\n open || hasFocus\n ? resolveShorthand(props.listbox, {\n required: true,\n defaultProps: {\n children: props.children,\n style: popupDimensions,\n },\n })\n : undefined;\n\n [triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);\n [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);\n\n if (hideActiveDescendant) {\n triggerSlot['aria-activedescendant'] = undefined;\n }\n\n const state: ComboboxState = {\n components: {\n root: 'div',\n input: 'input',\n expandIcon: 'span',\n listbox: Listbox,\n },\n root: resolveShorthand(props.root, {\n required: true,\n defaultProps: {\n 'aria-owns': !inlinePopup ? listboxSlot?.id : undefined,\n ...rootNativeProps,\n },\n }),\n input: triggerSlot,\n listbox: listboxSlot,\n expandIcon: resolveShorthand(props.expandIcon, {\n required: true,\n defaultProps: {\n 'aria-expanded': open,\n children: <ChevronDownIcon />,\n role: 'button',\n },\n }),\n ...baseState,\n };\n\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n\n /* handle open/close + focus change when clicking expandIcon */\n const { onMouseDown: onIconMouseDown, onClick: onIconClick } = state.expandIcon || {};\n const onExpandIconMouseDown = useEventCallback(\n mergeCallbacks(onIconMouseDown, () => {\n // do not dismiss on blur when closing via clicking the icon\n if (open) {\n baseState.ignoreNextBlur.current = true;\n }\n }),\n );\n\n const onExpandIconClick = useEventCallback(\n mergeCallbacks(onIconClick, (event: React.MouseEvent<HTMLSpanElement>) => {\n // open and set focus\n state.setOpen(event, !state.open);\n triggerRef.current?.focus();\n\n // set focus visible=false, since this can only be done with the mouse/pointer\n setFocusVisible(false);\n }),\n );\n\n if (state.expandIcon) {\n state.expandIcon.onMouseDown = onExpandIconMouseDown;\n state.expandIcon.onClick = onExpandIconClick;\n\n // If there is no explicit aria-label, calculate default accName attribute for expandIcon button,\n // using the following steps:\n // 1. If there is an aria-label, it is \"Open [aria-label]\"\n // 2. If there is an aria-labelledby, it is \"Open [aria-labelledby target]\" (using aria-labelledby + ids)\n // 3. If there is no aria-label/ledby attr, it falls back to \"Open\"\n // We can't fall back to a label/htmlFor name because of https://github.com/w3c/accname/issues/179\n const hasExpandLabel = state.expandIcon['aria-label'] || state.expandIcon['aria-labelledby'];\n const defaultOpenString = 'Open'; // this is english-only since it is the fallback\n if (!hasExpandLabel) {\n if (props['aria-labelledby']) {\n const chevronId = state.expandIcon.id ?? `${comboId}-chevron`;\n const chevronLabelledBy = `${chevronId} ${state.input['aria-labelledby']}`;\n\n state.expandIcon['aria-label'] = defaultOpenString;\n state.expandIcon.id = chevronId;\n state.expandIcon['aria-labelledby'] = chevronLabelledBy;\n } else if (props['aria-label']) {\n state.expandIcon['aria-label'] = `${defaultOpenString} ${props['aria-label']}`;\n } else {\n state.expandIcon['aria-label'] = defaultOpenString;\n }\n }\n }\n\n return state;\n};\n"]}
|