@fluentui/react-combobox 9.0.0-beta.9 → 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 +848 -1
- package/CHANGELOG.md +248 -2
- package/README.md +1 -3
- package/dist/index.d.ts +62 -11
- 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 +10 -6
- package/lib/components/Combobox/renderCombobox.js.map +1 -1
- package/lib/components/Combobox/useCombobox.js +107 -70
- package/lib/components/Combobox/useCombobox.js.map +1 -1
- package/lib/components/Combobox/useComboboxStyles.js +246 -185
- 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 +10 -6
- package/lib/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdown.js +25 -36
- package/lib/components/Dropdown/useDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdownStyles.js +236 -176
- 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 +15 -17
- 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 +46 -39
- package/lib/components/Option/useOption.js.map +1 -1
- package/lib/components/Option/useOptionStyles.js +101 -79
- 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 +9 -11
- package/lib/contexts/ComboboxContext.js.map +1 -1
- package/lib/contexts/ListboxContext.js +7 -9
- package/lib/contexts/ListboxContext.js.map +1 -1
- package/lib/contexts/useComboboxContextValues.js.map +1 -1
- package/lib/contexts/useListboxContextValues.js +2 -2
- 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 +12 -33
- package/lib/utils/dropdownKeyActions.js.map +1 -1
- package/lib/utils/internalTokens.js.map +1 -1
- package/lib/utils/useComboboxBaseState.js +29 -30
- package/lib/utils/useComboboxBaseState.js.map +1 -1
- package/lib/utils/useComboboxPopup.js +6 -4
- 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 +9 -12
- package/lib/utils/useSelection.js.map +1 -1
- package/lib/utils/useTriggerListboxSlots.js +34 -40
- 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 +10 -12
- package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useCombobox.js +106 -78
- package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useComboboxStyles.js +245 -189
- 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 +10 -12
- package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdown.js +25 -47
- package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdownStyles.js +235 -180
- 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 +14 -25
- 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 +45 -45
- package/lib-commonjs/components/Option/useOption.js.map +1 -1
- package/lib-commonjs/components/Option/useOptionStyles.js +101 -83
- 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 +10 -14
- package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
- package/lib-commonjs/contexts/ListboxContext.js +8 -12
- package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
- package/lib-commonjs/contexts/useComboboxContextValues.js +0 -2
- package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
- package/lib-commonjs/contexts/useListboxContextValues.js +2 -6
- 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 +12 -37
- package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
- package/lib-commonjs/utils/internalTokens.js.map +1 -1
- package/lib-commonjs/utils/useComboboxBaseState.js +29 -36
- package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
- package/lib-commonjs/utils/useComboboxPopup.js +6 -8
- 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 +9 -15
- package/lib-commonjs/utils/useSelection.js.map +1 -1
- package/lib-commonjs/utils/useTriggerListboxSlots.js +33 -44
- package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
- package/package.json +23 -22
- package/Spec-migration.md +0 -13
- package/Spec.md +0 -520
package/lib/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
export { ComboboxProvider } from './contexts/ComboboxContext';
|
|
2
|
+
export { ListboxProvider } from './contexts/ListboxContext';
|
|
3
|
+
export { useComboboxContextValues } from './contexts/useComboboxContextValues';
|
|
4
|
+
export { useListboxContextValues } from './contexts/useListboxContextValues';
|
|
1
5
|
export { Listbox, listboxClassNames, renderListbox_unstable, useListboxStyles_unstable, useListbox_unstable } from './Listbox';
|
|
2
6
|
export { Option, optionClassNames, renderOption_unstable, useOptionStyles_unstable, useOption_unstable } from './Option';
|
|
3
7
|
export { Combobox, comboboxClassNames, renderCombobox_unstable, useComboboxStyles_unstable, useCombobox_unstable } from './Combobox';
|
|
4
8
|
export { Dropdown, dropdownClassNames, renderDropdown_unstable, useDropdownStyles_unstable, useDropdown_unstable } from './Dropdown';
|
|
5
9
|
export { OptionGroup, optionGroupClassNames, renderOptionGroup_unstable, useOptionGroupStyles_unstable, useOptionGroup_unstable } from './OptionGroup';
|
|
10
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
11
|
+
export { ComboboxField as ComboboxField_unstable, comboboxFieldClassNames } from './ComboboxField';
|
|
6
12
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"AAAA,SAASA,gBAAgB,QAAQ,4BAA4B;AAE7D,SAASC,eAAe,QAAQ,2BAA2B;AAE3D,SAASC,wBAAwB,QAAQ,qCAAqC;AAC9E,SAASC,uBAAuB,QAAQ,oCAAoC;AAC5E,SACEC,OAAO,EACPC,iBAAiB,EACjBC,sBAAsB,EACtBC,yBAAyB,EACzBC,mBAAmB,QACd,WAAW;AAElB,SACEC,MAAM,EACNC,gBAAgB,EAChBC,qBAAqB,EACrBC,wBAAwB,EACxBC,kBAAkB,QACb,UAAU;AAEjB,SACEC,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,oBAAoB,QACf,YAAY;AASnB,SACEC,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,oBAAoB,QACf,YAAY;AASnB,SACEC,WAAW,EACXC,qBAAqB,EACrBC,0BAA0B,EAC1BC,6BAA6B,EAC7BC,uBAAuB,QAClB,eAAe;AAGtB;AACA,SAASC,aAAa,IAAIC,sBAAsB,EAAEC,uBAAuB,QAAQ,iBAAiB","names":["ComboboxProvider","ListboxProvider","useComboboxContextValues","useListboxContextValues","Listbox","listboxClassNames","renderListbox_unstable","useListboxStyles_unstable","useListbox_unstable","Option","optionClassNames","renderOption_unstable","useOptionStyles_unstable","useOption_unstable","Combobox","comboboxClassNames","renderCombobox_unstable","useComboboxStyles_unstable","useCombobox_unstable","Dropdown","dropdownClassNames","renderDropdown_unstable","useDropdownStyles_unstable","useDropdown_unstable","OptionGroup","optionGroupClassNames","renderOptionGroup_unstable","useOptionGroupStyles_unstable","useOptionGroup_unstable","ComboboxField","ComboboxField_unstable","comboboxFieldClassNames"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/index.ts"],"sourcesContent":["export { ComboboxProvider } from './contexts/ComboboxContext';\nexport type { ComboboxContextValue } from './contexts/ComboboxContext';\nexport { ListboxProvider } from './contexts/ListboxContext';\nexport type { ListboxContextValue } from './contexts/ListboxContext';\nexport { useComboboxContextValues } from './contexts/useComboboxContextValues';\nexport { useListboxContextValues } from './contexts/useListboxContextValues';\nexport {\n Listbox,\n listboxClassNames,\n renderListbox_unstable,\n useListboxStyles_unstable,\n useListbox_unstable,\n} from './Listbox';\nexport type { ListboxContextValues, ListboxProps, ListboxSlots, ListboxState } from './Listbox';\nexport {\n Option,\n optionClassNames,\n renderOption_unstable,\n useOptionStyles_unstable,\n useOption_unstable,\n} from './Option';\nexport type { OptionProps, OptionSlots, OptionState } from './Option';\nexport {\n Combobox,\n comboboxClassNames,\n renderCombobox_unstable,\n useComboboxStyles_unstable,\n useCombobox_unstable,\n} from './Combobox';\nexport type {\n ComboboxContextValues,\n ComboboxOpenChangeData,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxSlots,\n ComboboxState,\n} from './Combobox';\nexport {\n Dropdown,\n dropdownClassNames,\n renderDropdown_unstable,\n useDropdownStyles_unstable,\n useDropdown_unstable,\n} from './Dropdown';\nexport type {\n DropdownContextValues,\n DropdownOpenChangeData,\n DropdownOpenEvents,\n DropdownProps,\n DropdownSlots,\n DropdownState,\n} from './Dropdown';\nexport {\n OptionGroup,\n optionGroupClassNames,\n renderOptionGroup_unstable,\n useOptionGroupStyles_unstable,\n useOptionGroup_unstable,\n} from './OptionGroup';\nexport type { OptionGroupProps, OptionGroupSlots, OptionGroupState } from './OptionGroup';\n\n// eslint-disable-next-line deprecation/deprecation\nexport { ComboboxField as ComboboxField_unstable, comboboxFieldClassNames } from './ComboboxField';\n// eslint-disable-next-line deprecation/deprecation\nexport type { ComboboxFieldProps as ComboboxFieldProps_unstable } from './ComboboxField';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComboboxBase.types.js","sourceRoot":"../src/","sources":["utils/ComboboxBase.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { PositioningShorthand } from '@fluentui/react-positioning';\nimport type { ComboboxContextValue } from '../contexts/ComboboxContext';\nimport type { OptionValue, OptionCollectionState } from '../utils/OptionCollection.types';\nimport {
|
|
1
|
+
{"version":3,"file":"ComboboxBase.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/ComboboxBase.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { PositioningShorthand } from '@fluentui/react-positioning';\nimport type { ComboboxContextValue } from '../contexts/ComboboxContext';\nimport type { OptionValue, OptionCollectionState } from '../utils/OptionCollection.types';\nimport { SelectionProps, SelectionState } from '../utils/Selection.types';\n\n/**\n * ComboboxBase Props\n * Shared types between Combobox and Dropdown components\n */\nexport type ComboboxBaseProps = SelectionProps & {\n /**\n * Controls the colors and borders of the combobox trigger.\n * @default 'outline'\n */\n appearance?: 'filled-darker' | 'filled-lighter' | 'outline' | 'underline';\n\n /**\n * The default open state when open is uncontrolled\n */\n defaultOpen?: boolean;\n\n /**\n * The default value displayed in the trigger input or button when the combobox's value is uncontrolled\n */\n defaultValue?: string;\n\n /**\n * Render the combobox's popup inline in the DOM.\n * This has accessibility benefits, particularly for touch screen readers.\n */\n inlinePopup?: boolean;\n\n /**\n * Callback when the open/closed state of the dropdown changes\n */\n onOpenChange?: (e: ComboboxBaseOpenEvents, data: ComboboxBaseOpenChangeData) => void;\n\n /**\n * Sets the open/closed state of the dropdown.\n * Use together with onOpenChange to fully control the dropdown's visibility\n */\n open?: boolean;\n\n /**\n * If set, the placeholder will show when no value is selected\n */\n placeholder?: string;\n\n /**\n * Configure the positioning of the combobox dropdown\n *\n * @defaultvalue below\n */\n positioning?: PositioningShorthand;\n\n /**\n * Controls the size of the combobox faceplate\n * @default 'medium'\n */\n size?: 'small' | 'medium' | 'large';\n\n /**\n * The value displayed by the Combobox.\n * Use this with `onOptionSelect` to directly control the displayed value string\n */\n value?: string;\n};\n\n/**\n * State used in rendering Combobox\n */\nexport type ComboboxBaseState = Required<Pick<ComboboxBaseProps, 'appearance' | 'open' | 'inlinePopup' | 'size'>> &\n Pick<ComboboxBaseProps, 'placeholder' | 'value' | 'multiselect'> &\n OptionCollectionState &\n SelectionState & {\n /* Option data for the currently highlighted option (not the selected option) */\n activeOption?: OptionValue;\n\n // Whether the keyboard focus outline style should be visible\n focusVisible: boolean;\n\n // whether the combobox/dropdown currently has focus\n hasFocus: boolean;\n\n /* Whether the next blur event should be ignored, and the combobox/dropdown will not close.*/\n ignoreNextBlur: React.MutableRefObject<boolean>;\n\n setActiveOption(option?: OptionValue): void;\n\n setFocusVisible(focusVisible: boolean): void;\n\n setHasFocus(hasFocus: boolean): void;\n\n setOpen(event: ComboboxBaseOpenEvents, newState: boolean): void;\n\n setValue(newValue: string | undefined): void;\n };\n\n/**\n * Data for the Combobox onOpenChange event.\n */\nexport type ComboboxBaseOpenChangeData = {\n open: boolean;\n};\n\n/* Possible event types for onOpen */\nexport type ComboboxBaseOpenEvents =\n | React.MouseEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.FocusEvent<HTMLElement>;\n\nexport type ComboboxBaseContextValues = {\n combobox: ComboboxContextValue;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OptionCollection.types.js","sourceRoot":"../src/","sources":["utils/OptionCollection.types.ts"],"names":[],"mappings":"","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 value string of the option. */\n value: string;\n};\n\nexport type OptionCollectionState = {\n /** The total number of options in the collection. */\n getCount: () => number;\n\n /** Returns the index of an option by key. */\n getIndexOfId(id: string): number;\n\n /** Returns the option data for the nth option. */\n getOptionAtIndex(index: number): OptionValue | undefined;\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. */\n
|
|
1
|
+
{"version":3,"file":"OptionCollection.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/OptionCollection.types.ts"],"names":[],"mappings":"","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 /** The total number of options in the collection. */\n getCount: () => number;\n\n /** Returns the index of an option by key. */\n getIndexOfId(id: string): number;\n\n /** Returns the option data for the nth option. */\n getOptionAtIndex(index: number): OptionValue | undefined;\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 text string. */\n getOptionsMatchingText(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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Selection.types.js","sourceRoot":"../src/","sources":["utils/Selection.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { OptionValue } from './OptionCollection.types';\n\nexport type SelectionProps = {\n /* For an uncontrolled component, sets the initial selection */\n defaultSelectedOptions?: string[];\n\n /**\n * Sets the selection type to multiselect.\n * Set this to true for multiselect, even if fully controlling selection state.\n * This enables styles and accessibility properties to be set.\n * @default false\n */\n multiselect?: boolean;\n\n /* Callback when an option is selected */\n onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void;\n\n /**\n * An array of selected option keys.\n * Use this with `onOptionSelect` to directly control the selected option(s)\n */\n selectedOptions?: string[];\n};\n\
|
|
1
|
+
{"version":3,"file":"Selection.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/Selection.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport { OptionValue } from './OptionCollection.types';\n\nexport type SelectionProps = {\n /* For an uncontrolled component, sets the initial selection */\n defaultSelectedOptions?: string[];\n\n /**\n * Sets the selection type to multiselect.\n * Set this to true for multiselect, even if fully controlling selection state.\n * This enables styles and accessibility properties to be set.\n * @default false\n */\n multiselect?: boolean;\n\n /* Callback when an option is selected */\n onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void;\n\n /**\n * An array of selected option keys.\n * Use this with `onOptionSelect` to directly control the selected option(s)\n */\n selectedOptions?: string[];\n};\n\n/* Values returned by the useSelection hook */\nexport type SelectionState = {\n clearSelection: (event: SelectionEvents) => void;\n selectedOptions: string[];\n selectOption: (event: SelectionEvents, option: OptionValue) => void;\n};\n\n/*\n * Data for the onOptionSelect callback.\n * `optionValue` and `optionText` will be undefined if multiple options are modified at once.\n */\nexport type OptionOnSelectData = {\n optionValue: string | undefined;\n optionText: string | undefined;\n selectedOptions: string[];\n};\n\n/* Possible event types for onOptionSelect */\nexport type SelectionEvents =\n | React.ChangeEvent<HTMLElement>\n | React.KeyboardEvent<HTMLElement>\n | React.MouseEvent<HTMLElement>;\n"]}
|
|
@@ -2,7 +2,6 @@ import * as keys from '@fluentui/keyboard-keys';
|
|
|
2
2
|
/**
|
|
3
3
|
* Converts a keyboard interaction into a defined action
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
export function getDropdownActionFromKey(e, options = {}) {
|
|
7
6
|
const {
|
|
8
7
|
open = true,
|
|
@@ -14,92 +13,72 @@ export function getDropdownActionFromKey(e, options = {}) {
|
|
|
14
13
|
ctrlKey,
|
|
15
14
|
key,
|
|
16
15
|
metaKey
|
|
17
|
-
} = e;
|
|
18
|
-
|
|
16
|
+
} = e;
|
|
17
|
+
// typing action occurs whether open or closed
|
|
19
18
|
if (key.length === 1 && code !== keys.Space && !altKey && !ctrlKey && !metaKey) {
|
|
20
19
|
return 'Type';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
}
|
|
21
|
+
// handle opening the dropdown if closed
|
|
24
22
|
if (!open) {
|
|
25
23
|
if (code === keys.ArrowDown || code === keys.ArrowUp || code === keys.Enter || code === keys.Space) {
|
|
26
24
|
return 'Open';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
}
|
|
26
|
+
// if the dropdown is closed and an action did not match the above, do nothing
|
|
30
27
|
return 'None';
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
}
|
|
29
|
+
// select or close actions
|
|
34
30
|
if (code === keys.ArrowUp && altKey || code === keys.Enter || !multiselect && code === keys.Space) {
|
|
35
31
|
return 'CloseSelect';
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
if (multiselect && code === keys.Space) {
|
|
39
34
|
return 'Select';
|
|
40
35
|
}
|
|
41
|
-
|
|
42
36
|
if (code === keys.Escape) {
|
|
43
37
|
return 'Close';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
}
|
|
39
|
+
// navigation interactions
|
|
47
40
|
if (code === keys.ArrowDown) {
|
|
48
41
|
return 'Next';
|
|
49
42
|
}
|
|
50
|
-
|
|
51
43
|
if (code === keys.ArrowUp) {
|
|
52
44
|
return 'Previous';
|
|
53
45
|
}
|
|
54
|
-
|
|
55
46
|
if (code === keys.Home) {
|
|
56
47
|
return 'First';
|
|
57
48
|
}
|
|
58
|
-
|
|
59
49
|
if (code === keys.End) {
|
|
60
50
|
return 'Last';
|
|
61
51
|
}
|
|
62
|
-
|
|
63
52
|
if (code === keys.PageUp) {
|
|
64
53
|
return 'PageUp';
|
|
65
54
|
}
|
|
66
|
-
|
|
67
55
|
if (code === keys.PageDown) {
|
|
68
56
|
return 'PageDown';
|
|
69
57
|
}
|
|
70
|
-
|
|
71
58
|
if (code === keys.Tab) {
|
|
72
59
|
return 'Tab';
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
}
|
|
61
|
+
// if nothing matched, return none
|
|
76
62
|
return 'None';
|
|
77
63
|
}
|
|
78
64
|
/**
|
|
79
65
|
* Returns the requested option index from an action
|
|
80
66
|
*/
|
|
81
|
-
|
|
82
67
|
export function getIndexFromAction(action, currentIndex, maxIndex) {
|
|
83
68
|
switch (action) {
|
|
84
69
|
case 'Next':
|
|
85
70
|
return Math.min(maxIndex, currentIndex + 1);
|
|
86
71
|
break;
|
|
87
|
-
|
|
88
72
|
case 'Previous':
|
|
89
73
|
return Math.max(0, currentIndex - 1);
|
|
90
|
-
|
|
91
74
|
case 'First':
|
|
92
75
|
return 0;
|
|
93
|
-
|
|
94
76
|
case 'Last':
|
|
95
77
|
return maxIndex;
|
|
96
|
-
|
|
97
78
|
case 'PageDown':
|
|
98
79
|
return Math.min(maxIndex, currentIndex + 10);
|
|
99
|
-
|
|
100
80
|
case 'PageUp':
|
|
101
81
|
return Math.max(0, currentIndex - 10);
|
|
102
|
-
|
|
103
82
|
default:
|
|
104
83
|
return currentIndex;
|
|
105
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,IAAI,MAAM,yBAAyB;AA2B/C;;;AAGA,OAAM,SAAUC,wBAAwB,CACtCC,CAAsC,EACtCC,UAAiC,EAAE;EAEnC,MAAM;IAAEC,IAAI,GAAG,IAAI;IAAEC,WAAW,GAAG;EAAK,CAAE,GAAGF,OAAO;EACpD,MAAMG,IAAI,GAAGJ,CAAC,CAACK,GAAG;EAClB,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEF,GAAG;IAAEG;EAAO,CAAE,GAAGR,CAAC;EAE3C;EACA,IAAIK,GAAG,CAACI,MAAM,KAAK,CAAC,IAAIL,IAAI,KAAKN,IAAI,CAACY,KAAK,IAAI,CAACJ,MAAM,IAAI,CAACC,OAAO,IAAI,CAACC,OAAO,EAAE;IAC9E,OAAO,MAAM;;EAGf;EACA,IAAI,CAACN,IAAI,EAAE;IACT,IAAIE,IAAI,KAAKN,IAAI,CAACa,SAAS,IAAIP,IAAI,KAAKN,IAAI,CAACc,OAAO,IAAIR,IAAI,KAAKN,IAAI,CAACe,KAAK,IAAIT,IAAI,KAAKN,IAAI,CAACY,KAAK,EAAE;MAClG,OAAO,MAAM;;IAGf;IACA,OAAO,MAAM;;EAGf;EACA,IAAKN,IAAI,KAAKN,IAAI,CAACc,OAAO,IAAIN,MAAM,IAAKF,IAAI,KAAKN,IAAI,CAACe,KAAK,IAAK,CAACV,WAAW,IAAIC,IAAI,KAAKN,IAAI,CAACY,KAAM,EAAE;IACrG,OAAO,aAAa;;EAEtB,IAAIP,WAAW,IAAIC,IAAI,KAAKN,IAAI,CAACY,KAAK,EAAE;IACtC,OAAO,QAAQ;;EAEjB,IAAIN,IAAI,KAAKN,IAAI,CAACgB,MAAM,EAAE;IACxB,OAAO,OAAO;;EAGhB;EACA,IAAIV,IAAI,KAAKN,IAAI,CAACa,SAAS,EAAE;IAC3B,OAAO,MAAM;;EAEf,IAAIP,IAAI,KAAKN,IAAI,CAACc,OAAO,EAAE;IACzB,OAAO,UAAU;;EAEnB,IAAIR,IAAI,KAAKN,IAAI,CAACiB,IAAI,EAAE;IACtB,OAAO,OAAO;;EAEhB,IAAIX,IAAI,KAAKN,IAAI,CAACkB,GAAG,EAAE;IACrB,OAAO,MAAM;;EAEf,IAAIZ,IAAI,KAAKN,IAAI,CAACmB,MAAM,EAAE;IACxB,OAAO,QAAQ;;EAEjB,IAAIb,IAAI,KAAKN,IAAI,CAACoB,QAAQ,EAAE;IAC1B,OAAO,UAAU;;EAEnB,IAAId,IAAI,KAAKN,IAAI,CAACqB,GAAG,EAAE;IACrB,OAAO,KAAK;;EAGd;EACA,OAAO,MAAM;AACf;AAEA;;;AAGA,OAAM,SAAUC,kBAAkB,CAACC,MAAuB,EAAEC,YAAoB,EAAEC,QAAgB;EAChG,QAAQF,MAAM;IACZ,KAAK,MAAM;MACT,OAAOG,IAAI,CAACC,GAAG,CAACF,QAAQ,EAAED,YAAY,GAAG,CAAC,CAAC;MAC3C;IACF,KAAK,UAAU;MACb,OAAOE,IAAI,CAACE,GAAG,CAAC,CAAC,EAAEJ,YAAY,GAAG,CAAC,CAAC;IACtC,KAAK,OAAO;MACV,OAAO,CAAC;IACV,KAAK,MAAM;MACT,OAAOC,QAAQ;IACjB,KAAK,UAAU;MACb,OAAOC,IAAI,CAACC,GAAG,CAACF,QAAQ,EAAED,YAAY,GAAG,EAAE,CAAC;IAC9C,KAAK,QAAQ;MACX,OAAOE,IAAI,CAACE,GAAG,CAAC,CAAC,EAAEJ,YAAY,GAAG,EAAE,CAAC;IACvC;MACE,OAAOA,YAAY;EAAC;AAE1B","names":["keys","getDropdownActionFromKey","e","options","open","multiselect","code","key","altKey","ctrlKey","metaKey","length","Space","ArrowDown","ArrowUp","Enter","Escape","Home","End","PageUp","PageDown","Tab","getIndexFromAction","action","currentIndex","maxIndex","Math","min","max"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/dropdownKeyActions.ts"],"sourcesContent":["import * as keys from '@fluentui/keyboard-keys';\nimport * as React from 'react';\n\n/**\n * enum of actions available in any type of managed dropdown control\n * e.g. combobox, select, datepicker, menu\n */\nexport type DropdownActions =\n | 'Close'\n | 'CloseSelect'\n | 'First'\n | 'Last'\n | 'Next'\n | 'None'\n | 'Open'\n | 'PageDown'\n | 'PageUp'\n | 'Previous'\n | 'Select'\n | 'Tab'\n | 'Type';\n\nexport interface DropdownActionOptions {\n open?: boolean;\n multiselect?: boolean;\n}\n\n/**\n * Converts a keyboard interaction into a defined action\n */\nexport function getDropdownActionFromKey(\n e: KeyboardEvent | React.KeyboardEvent,\n options: DropdownActionOptions = {},\n): DropdownActions {\n const { open = true, multiselect = false } = options;\n const code = e.key;\n const { altKey, ctrlKey, key, metaKey } = e;\n\n // typing action occurs whether open or closed\n if (key.length === 1 && code !== keys.Space && !altKey && !ctrlKey && !metaKey) {\n return 'Type';\n }\n\n // handle opening the dropdown if closed\n if (!open) {\n if (code === keys.ArrowDown || code === keys.ArrowUp || code === keys.Enter || code === keys.Space) {\n return 'Open';\n }\n\n // if the dropdown is closed and an action did not match the above, do nothing\n return 'None';\n }\n\n // select or close actions\n if ((code === keys.ArrowUp && altKey) || code === keys.Enter || (!multiselect && code === keys.Space)) {\n return 'CloseSelect';\n }\n if (multiselect && code === keys.Space) {\n return 'Select';\n }\n if (code === keys.Escape) {\n return 'Close';\n }\n\n // navigation interactions\n if (code === keys.ArrowDown) {\n return 'Next';\n }\n if (code === keys.ArrowUp) {\n return 'Previous';\n }\n if (code === keys.Home) {\n return 'First';\n }\n if (code === keys.End) {\n return 'Last';\n }\n if (code === keys.PageUp) {\n return 'PageUp';\n }\n if (code === keys.PageDown) {\n return 'PageDown';\n }\n if (code === keys.Tab) {\n return 'Tab';\n }\n\n // if nothing matched, return none\n return 'None';\n}\n\n/**\n * Returns the requested option index from an action\n */\nexport function getIndexFromAction(action: DropdownActions, currentIndex: number, maxIndex: number): number {\n switch (action) {\n case 'Next':\n return Math.min(maxIndex, currentIndex + 1);\n break;\n case 'Previous':\n return Math.max(0, currentIndex - 1);\n case 'First':\n return 0;\n case 'Last':\n return maxIndex;\n case 'PageDown':\n return Math.min(maxIndex, currentIndex + 10);\n case 'PageUp':\n return Math.max(0, currentIndex - 10);\n default:\n return currentIndex;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,MAAMA,SAAS,GAAG;EACvBC,KAAK,EAAE,MAAM;EACbC,MAAM,EAAE,MAAM;EACdC,KAAK,EAAE;CACR","names":["iconSizes","small","medium","large"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/internalTokens.ts"],"sourcesContent":["export const iconSizes = {\n small: '16px',\n medium: '20px',\n large: '24px',\n};\n"]}
|
|
@@ -5,10 +5,11 @@ import { useSelection } from '../utils/useSelection';
|
|
|
5
5
|
/**
|
|
6
6
|
* State shared between Combobox and Dropdown components
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
8
|
export const useComboboxBaseState = props => {
|
|
10
9
|
const {
|
|
11
10
|
appearance = 'outline',
|
|
11
|
+
children,
|
|
12
|
+
editable = false,
|
|
12
13
|
inlinePopup = false,
|
|
13
14
|
multiselect,
|
|
14
15
|
onOpenChange,
|
|
@@ -17,20 +18,20 @@ export const useComboboxBaseState = props => {
|
|
|
17
18
|
const optionCollection = useOptionCollection();
|
|
18
19
|
const {
|
|
19
20
|
getOptionAtIndex,
|
|
20
|
-
|
|
21
|
+
getOptionsMatchingText
|
|
21
22
|
} = optionCollection;
|
|
22
|
-
const [activeOption, setActiveOption] = React.useState();
|
|
23
|
+
const [activeOption, setActiveOption] = React.useState();
|
|
24
|
+
// track whether keyboard focus outline should be shown
|
|
23
25
|
// tabster/keyborg doesn't work here, since the actual keyboard focus target doesn't move
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
const [focusVisible, setFocusVisible] = React.useState(false);
|
|
27
|
+
// track focused state to conditionally render collapsed listbox
|
|
27
28
|
const [hasFocus, setHasFocus] = React.useState(false);
|
|
28
29
|
const ignoreNextBlur = React.useRef(false);
|
|
29
30
|
const selectionState = useSelection(props);
|
|
30
31
|
const {
|
|
31
32
|
selectedOptions
|
|
32
|
-
} = selectionState;
|
|
33
|
-
|
|
33
|
+
} = selectionState;
|
|
34
|
+
// calculate value based on props, internal value changes, and selected options
|
|
34
35
|
const isFirstMount = useFirstMount();
|
|
35
36
|
const [controllableValue, setValue] = useControllableState({
|
|
36
37
|
state: props.value,
|
|
@@ -40,52 +41,50 @@ export const useComboboxBaseState = props => {
|
|
|
40
41
|
// don't compute the value if it is defined through props or setValue,
|
|
41
42
|
if (controllableValue !== undefined) {
|
|
42
43
|
return controllableValue;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
}
|
|
45
|
+
// handle defaultValue here, so it is overridden by selection
|
|
46
46
|
if (isFirstMount && props.defaultValue !== undefined) {
|
|
47
47
|
return props.defaultValue;
|
|
48
48
|
}
|
|
49
|
-
|
|
50
49
|
if (multiselect) {
|
|
51
|
-
|
|
50
|
+
// editable inputs should not display multiple selected options in the input as text
|
|
51
|
+
return editable ? '' : selectedOptions.join(', ');
|
|
52
52
|
}
|
|
53
|
-
|
|
54
53
|
return selectedOptions[0];
|
|
55
|
-
}, [controllableValue, isFirstMount, multiselect, props.defaultValue, selectedOptions]);
|
|
56
|
-
|
|
54
|
+
}, [controllableValue, editable, isFirstMount, multiselect, props.defaultValue, selectedOptions]);
|
|
55
|
+
// Handle open state, which is shared with options in context
|
|
57
56
|
const [open, setOpenState] = useControllableState({
|
|
58
57
|
state: props.open,
|
|
59
58
|
defaultState: props.defaultOpen,
|
|
60
59
|
initialState: false
|
|
61
60
|
});
|
|
62
|
-
|
|
63
|
-
const setOpen = (event, newState) => {
|
|
61
|
+
const setOpen = React.useCallback((event, newState) => {
|
|
64
62
|
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
|
|
65
63
|
open: newState
|
|
66
64
|
});
|
|
67
65
|
setOpenState(newState);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
}, [onOpenChange, setOpenState]);
|
|
67
|
+
// update active option based on change in open state or children
|
|
71
68
|
React.useEffect(() => {
|
|
72
69
|
if (open && !activeOption) {
|
|
73
|
-
// if there is a
|
|
74
|
-
if (selectedOptions.length > 0) {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
}
|
|
70
|
+
// if it is single-select and there is a selected option, start at the selected option
|
|
71
|
+
if (!multiselect && selectedOptions.length > 0) {
|
|
72
|
+
const selectedOption = getOptionsMatchingText(v => v === selectedOptions[0]).pop();
|
|
73
|
+
selectedOption && setActiveOption(selectedOption);
|
|
74
|
+
}
|
|
75
|
+
// default to starting at the first option
|
|
78
76
|
else {
|
|
79
77
|
setActiveOption(getOptionAtIndex(0));
|
|
80
78
|
}
|
|
81
79
|
} else if (!open) {
|
|
82
80
|
// reset the active option when closing
|
|
83
81
|
setActiveOption(undefined);
|
|
84
|
-
}
|
|
82
|
+
}
|
|
83
|
+
// this should only be run in response to changes in the open state or children
|
|
85
84
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
}, [open, children]);
|
|
86
|
+
return {
|
|
87
|
+
...optionCollection,
|
|
89
88
|
...selectionState,
|
|
90
89
|
activeOption,
|
|
91
90
|
appearance,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"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","names":["React","useControllableState","useFirstMount","useOptionCollection","useSelection","useComboboxBaseState","props","appearance","children","editable","inlinePopup","multiselect","onOpenChange","size","optionCollection","getOptionAtIndex","getOptionsMatchingText","activeOption","setActiveOption","useState","focusVisible","setFocusVisible","hasFocus","setHasFocus","ignoreNextBlur","useRef","selectionState","selectedOptions","isFirstMount","controllableValue","setValue","state","value","initialState","undefined","useMemo","defaultValue","join","open","setOpenState","defaultState","defaultOpen","setOpen","useCallback","event","newState","useEffect","length","selectedOption","v","pop"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useComboboxBaseState.ts"],"sourcesContent":["import * as React from 'react';\nimport { useControllableState, useFirstMount } from '@fluentui/react-utilities';\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 & { children?: React.ReactNode; editable?: boolean },\n): ComboboxBaseState => {\n const {\n appearance = 'outline',\n children,\n editable = false,\n inlinePopup = false,\n multiselect,\n onOpenChange,\n size = 'medium',\n } = props;\n\n const optionCollection = useOptionCollection();\n const { getOptionAtIndex, getOptionsMatchingText } = optionCollection;\n\n const [activeOption, setActiveOption] = React.useState<OptionValue | undefined>();\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 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 if (multiselect) {\n // editable inputs should not display multiple selected options in the input as text\n return editable ? '' : selectedOptions.join(', ');\n }\n\n return selectedOptions[0];\n }, [controllableValue, editable, isFirstMount, 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 or children\n React.useEffect(() => {\n if (open && !activeOption) {\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 = getOptionsMatchingText(v => v === selectedOptions[0]).pop();\n selectedOption && setActiveOption(selectedOption);\n }\n // default to starting at the first option\n else {\n setActiveOption(getOptionAtIndex(0));\n }\n } else if (!open) {\n // reset the active option when closing\n setActiveOption(undefined);\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, children]);\n\n return {\n ...optionCollection,\n ...selectionState,\n activeOption,\n appearance,\n focusVisible,\n hasFocus,\n ignoreNextBlur,\n inlinePopup,\n open,\n setActiveOption,\n setFocusVisible,\n setHasFocus,\n setOpen,\n setValue,\n size,\n value,\n };\n};\n"]}
|
|
@@ -3,8 +3,8 @@ import { useMergedRefs } from '@fluentui/react-utilities';
|
|
|
3
3
|
export function useComboboxPopup(props, triggerShorthand, listboxShorthand) {
|
|
4
4
|
const {
|
|
5
5
|
positioning
|
|
6
|
-
} = props;
|
|
7
|
-
|
|
6
|
+
} = props;
|
|
7
|
+
// popper options
|
|
8
8
|
const popperOptions = {
|
|
9
9
|
position: 'below',
|
|
10
10
|
align: 'start',
|
|
@@ -19,10 +19,12 @@ export function useComboboxPopup(props, triggerShorthand, listboxShorthand) {
|
|
|
19
19
|
containerRef
|
|
20
20
|
} = usePositioning(popperOptions);
|
|
21
21
|
const listboxRef = useMergedRefs(listboxShorthand === null || listboxShorthand === void 0 ? void 0 : listboxShorthand.ref, containerRef);
|
|
22
|
-
const listbox = listboxShorthand && {
|
|
22
|
+
const listbox = listboxShorthand && {
|
|
23
|
+
...listboxShorthand,
|
|
23
24
|
ref: listboxRef
|
|
24
25
|
};
|
|
25
|
-
return [{
|
|
26
|
+
return [{
|
|
27
|
+
...triggerShorthand,
|
|
26
28
|
ref: useMergedRefs(triggerShorthand === null || triggerShorthand === void 0 ? void 0 : triggerShorthand.ref, targetRef)
|
|
27
29
|
}, listbox];
|
|
28
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"AAAA,SAASA,2BAA2B,EAAEC,cAAc,QAAQ,6BAA6B;AACzF,SAAiCC,aAAa,QAAQ,2BAA2B;AAejF,OAAM,SAAUC,gBAAgB,CAC9BC,KAAwB,EACxBC,gBAAqF,EACrFC,gBAAyD;EAKzD,MAAM;IAAEC;EAAW,CAAE,GAAGH,KAAK;EAE7B;EACA,MAAMI,aAAa,GAAG;IACpBC,QAAQ,EAAE,OAAgB;IAC1BC,KAAK,EAAE,OAAgB;IACvBC,MAAM,EAAE;MAAEC,SAAS,EAAE,CAAC;MAAEC,QAAQ,EAAE;IAAC,CAAE;IACrC,GAAGb,2BAA2B,CAACO,WAAW;GAC3C;EAED,MAAM;IAAEO,SAAS;IAAEC;EAAY,CAAE,GAAGd,cAAc,CAACO,aAAa,CAAC;EAEjE,MAAMQ,UAAU,GAAGd,aAAa,CAACI,gBAAgB,aAAhBA,gBAAgB,uBAAhBA,gBAAgB,CAAEW,GAAG,EAAEF,YAAY,CAAC;EACrE,MAAMG,OAAO,GAAGZ,gBAAgB,IAAI;IAAE,GAAGA,gBAAgB;IAAEW,GAAG,EAAED;EAAU,CAAE;EAE5E,OAAO,CAAC;IAAE,GAAGX,gBAAgB;IAAEY,GAAG,EAAEf,aAAa,CAACG,gBAAgB,aAAhBA,gBAAgB,uBAAhBA,gBAAgB,CAAEY,GAAG,EAAEH,SAAS;EAAC,CAAE,EAAEI,OAAO,CAAC;AACjG","names":["resolvePositioningShorthand","usePositioning","useMergedRefs","useComboboxPopup","props","triggerShorthand","listboxShorthand","positioning","popperOptions","position","align","offset","crossAxis","mainAxis","targetRef","containerRef","listboxRef","ref","listbox"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useComboboxPopup.ts"],"sourcesContent":["import { resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport { ExtractSlotProps, Slot, useMergedRefs } from '@fluentui/react-utilities';\nimport type { ComboboxBaseProps } from './ComboboxBase.types';\nimport { Listbox } from '../components/Listbox/Listbox';\n\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'button'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'button'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'input'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [trigger: ExtractSlotProps<Slot<'input'>>, listbox?: ExtractSlotProps<Slot<typeof Listbox>>];\n\nexport function useComboboxPopup(\n props: ComboboxBaseProps,\n triggerShorthand?: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listboxShorthand?: ExtractSlotProps<Slot<typeof Listbox>>,\n): [\n trigger: ExtractSlotProps<Slot<'input'>> | ExtractSlotProps<Slot<'button'>>,\n listbox?: ExtractSlotProps<Slot<typeof Listbox>>,\n] {\n const { positioning } = props;\n\n // popper options\n const popperOptions = {\n position: 'below' as const,\n align: 'start' as const,\n offset: { crossAxis: 0, mainAxis: 2 },\n ...resolvePositioningShorthand(positioning),\n };\n\n const { targetRef, containerRef } = usePositioning(popperOptions);\n\n const listboxRef = useMergedRefs(listboxShorthand?.ref, containerRef);\n const listbox = listboxShorthand && { ...listboxShorthand, ref: listboxRef };\n\n return [{ ...triggerShorthand, ref: useMergedRefs(triggerShorthand?.ref, targetRef) }, listbox];\n}\n"]}
|
|
@@ -2,73 +2,63 @@ import * as React from 'react';
|
|
|
2
2
|
/**
|
|
3
3
|
* A hook for managing a collection of child Options
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
5
|
export const useOptionCollection = () => {
|
|
7
6
|
const nodes = React.useRef([]);
|
|
8
7
|
const collectionAPI = React.useMemo(() => {
|
|
9
8
|
const getCount = () => nodes.current.length;
|
|
10
|
-
|
|
11
9
|
const getOptionAtIndex = index => {
|
|
12
10
|
var _a;
|
|
13
|
-
|
|
14
11
|
return (_a = nodes.current[index]) === null || _a === void 0 ? void 0 : _a.option;
|
|
15
12
|
};
|
|
16
|
-
|
|
17
13
|
const getIndexOfId = id => nodes.current.findIndex(node => node.option.id === id);
|
|
18
|
-
|
|
19
14
|
const getOptionById = id => {
|
|
20
15
|
const item = nodes.current.find(node => node.option.id === id);
|
|
21
16
|
return item === null || item === void 0 ? void 0 : item.option;
|
|
22
17
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return nodes.current.filter(node => matcher(node.option.value)).map(node => node.option);
|
|
18
|
+
const getOptionsMatchingText = matcher => {
|
|
19
|
+
return nodes.current.filter(node => matcher(node.option.text)).map(node => node.option);
|
|
26
20
|
};
|
|
27
|
-
|
|
28
21
|
return {
|
|
29
22
|
getCount,
|
|
30
23
|
getOptionAtIndex,
|
|
31
24
|
getIndexOfId,
|
|
32
25
|
getOptionById,
|
|
33
|
-
|
|
26
|
+
getOptionsMatchingText
|
|
34
27
|
};
|
|
35
28
|
}, []);
|
|
36
29
|
const registerOption = React.useCallback((option, element) => {
|
|
37
30
|
var _a;
|
|
38
|
-
|
|
39
31
|
const index = nodes.current.findIndex(node => {
|
|
40
32
|
if (!node.element || !element) {
|
|
41
33
|
return false;
|
|
42
34
|
}
|
|
43
|
-
|
|
44
35
|
if (node.option.id === option.id) {
|
|
45
36
|
return true;
|
|
46
|
-
}
|
|
37
|
+
}
|
|
38
|
+
// use the DOM method compareDocumentPosition to order the current node against registered nodes
|
|
47
39
|
// eslint-disable-next-line no-bitwise
|
|
48
|
-
|
|
49
|
-
|
|
50
40
|
return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;
|
|
51
|
-
});
|
|
52
|
-
|
|
41
|
+
});
|
|
42
|
+
// do not register the option if it already exists
|
|
53
43
|
if (((_a = nodes.current[index]) === null || _a === void 0 ? void 0 : _a.option.id) !== option.id) {
|
|
54
44
|
const newItem = {
|
|
55
45
|
element,
|
|
56
46
|
option
|
|
57
|
-
};
|
|
58
|
-
|
|
47
|
+
};
|
|
48
|
+
// If an index is not found we will push the element to the end.
|
|
59
49
|
if (index === -1) {
|
|
60
50
|
nodes.current = [...nodes.current, newItem];
|
|
61
51
|
} else {
|
|
62
52
|
nodes.current.splice(index, 0, newItem);
|
|
63
53
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
}
|
|
55
|
+
// return the unregister function
|
|
67
56
|
return () => {
|
|
68
57
|
nodes.current = nodes.current.filter(node => node.option.id !== option.id);
|
|
69
58
|
};
|
|
70
59
|
}, []);
|
|
71
|
-
return {
|
|
60
|
+
return {
|
|
61
|
+
...collectionAPI,
|
|
72
62
|
options: nodes.current.map(node => node.option),
|
|
73
63
|
registerOption
|
|
74
64
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"mappings":"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","names":["React","useOptionCollection","nodes","useRef","collectionAPI","useMemo","getCount","current","length","getOptionAtIndex","index","option","getIndexOfId","id","findIndex","node","getOptionById","item","find","getOptionsMatchingText","matcher","filter","text","map","registerOption","useCallback","element","compareDocumentPosition","Node","DOCUMENT_POSITION_PRECEDING","newItem","splice","options"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useOptionCollection.ts"],"sourcesContent":["import * as React from 'react';\nimport type { OptionCollectionState, OptionValue } from './OptionCollection.types';\n\n/**\n * A hook for managing a collection of child Options\n */\nexport const useOptionCollection = (): OptionCollectionState => {\n const nodes = React.useRef<{ option: OptionValue; element: HTMLElement }[]>([]);\n\n const collectionAPI = React.useMemo(() => {\n const getCount = () => nodes.current.length;\n const getOptionAtIndex = (index: number) => nodes.current[index]?.option;\n const getIndexOfId = (id: string) => nodes.current.findIndex(node => node.option.id === id);\n const getOptionById = (id: string) => {\n const item = nodes.current.find(node => node.option.id === id);\n return item?.option;\n };\n const getOptionsMatchingText = (matcher: (value: string) => boolean) => {\n return nodes.current.filter(node => matcher(node.option.text)).map(node => node.option);\n };\n\n return {\n getCount,\n getOptionAtIndex,\n getIndexOfId,\n getOptionById,\n getOptionsMatchingText,\n };\n }, []);\n\n const registerOption = React.useCallback((option: OptionValue, element: HTMLElement) => {\n const index = nodes.current.findIndex(node => {\n if (!node.element || !element) {\n return false;\n }\n\n if (node.option.id === option.id) {\n return true;\n }\n\n // use the DOM method compareDocumentPosition to order the current node against registered nodes\n // eslint-disable-next-line no-bitwise\n return node.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING;\n });\n\n // do not register the option if it already exists\n if (nodes.current[index]?.option.id !== option.id) {\n const newItem = {\n element,\n option,\n };\n\n // If an index is not found we will push the element to the end.\n if (index === -1) {\n nodes.current = [...nodes.current, newItem];\n } else {\n nodes.current.splice(index, 0, newItem);\n }\n }\n\n // return the unregister function\n return () => {\n nodes.current = nodes.current.filter(node => node.option.id !== option.id);\n };\n }, []);\n\n return {\n ...collectionAPI,\n options: nodes.current.map(node => node.option),\n registerOption,\n };\n};\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { canUseDOM } from '@fluentui/react-utilities';
|
|
3
|
+
export function useScrollOptionsIntoView(state) {
|
|
4
|
+
const {
|
|
5
|
+
activeOption
|
|
6
|
+
} = state;
|
|
7
|
+
const scrollContainerRef = React.useRef(null);
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
if (scrollContainerRef.current && activeOption && canUseDOM()) {
|
|
10
|
+
const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`);
|
|
11
|
+
if (!activeOptionElement) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const {
|
|
15
|
+
offsetHeight,
|
|
16
|
+
offsetTop
|
|
17
|
+
} = activeOptionElement;
|
|
18
|
+
const {
|
|
19
|
+
offsetHeight: parentOffsetHeight,
|
|
20
|
+
scrollTop
|
|
21
|
+
} = scrollContainerRef.current;
|
|
22
|
+
const isAbove = offsetTop < scrollTop;
|
|
23
|
+
const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;
|
|
24
|
+
// add a small buffer for general visual nicety
|
|
25
|
+
// it looks slightly better if the option has some space from the top/bottom while arrowing
|
|
26
|
+
const buffer = 2;
|
|
27
|
+
if (isAbove) {
|
|
28
|
+
scrollContainerRef.current.scrollTo(0, offsetTop - buffer);
|
|
29
|
+
} else if (isBelow) {
|
|
30
|
+
scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}, [activeOption]);
|
|
34
|
+
return scrollContainerRef;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=useScrollOptionsIntoView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,SAAS,QAAQ,2BAA2B;AAGrD,OAAM,SAAUC,wBAAwB,CAACC,KAAmB;EAC1D,MAAM;IAAEC;EAAY,CAAE,GAAGD,KAAK;EAC9B,MAAME,kBAAkB,GAAGL,KAAK,CAACM,MAAM,CAAiB,IAAI,CAAC;EAE7DN,KAAK,CAACO,SAAS,CAAC,MAAK;IACnB,IAAIF,kBAAkB,CAACG,OAAO,IAAIJ,YAAY,IAAIH,SAAS,EAAE,EAAE;MAC7D,MAAMQ,mBAAmB,GAAGJ,kBAAkB,CAACG,OAAO,CAACE,aAAa,CAAC,IAAIN,YAAY,CAACO,EAAE,EAAE,CAAgB;MAE1G,IAAI,CAACF,mBAAmB,EAAE;QACxB;;MAGF,MAAM;QAAEG,YAAY;QAAEC;MAAS,CAAE,GAAGJ,mBAAmB;MACvD,MAAM;QAAEG,YAAY,EAAEE,kBAAkB;QAAEC;MAAS,CAAE,GAAGV,kBAAkB,CAACG,OAAO;MAElF,MAAMQ,OAAO,GAAGH,SAAS,GAAGE,SAAS;MACrC,MAAME,OAAO,GAAGJ,SAAS,GAAGD,YAAY,GAAGG,SAAS,GAAGD,kBAAkB;MAEzE;MACA;MACA,MAAMI,MAAM,GAAG,CAAC;MAEhB,IAAIF,OAAO,EAAE;QACXX,kBAAkB,CAACG,OAAO,CAACW,QAAQ,CAAC,CAAC,EAAEN,SAAS,GAAGK,MAAM,CAAC;OAC3D,MAAM,IAAID,OAAO,EAAE;QAClBZ,kBAAkB,CAACG,OAAO,CAACW,QAAQ,CAAC,CAAC,EAAEN,SAAS,GAAGC,kBAAkB,GAAGF,YAAY,GAAGM,MAAM,CAAC;;;EAGpG,CAAC,EAAE,CAACd,YAAY,CAAC,CAAC;EAElB,OAAOC,kBAAkB;AAC3B","names":["React","canUseDOM","useScrollOptionsIntoView","state","activeOption","scrollContainerRef","useRef","useEffect","current","activeOptionElement","querySelector","id","offsetHeight","offsetTop","parentOffsetHeight","scrollTop","isAbove","isBelow","buffer","scrollTo"],"sourceRoot":"../src/","sources":["packages/react-components/react-combobox/src/utils/useScrollOptionsIntoView.ts"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '@fluentui/react-utilities';\nimport { ListboxState } from '../Listbox';\n\nexport function useScrollOptionsIntoView(state: ListboxState): React.Ref<HTMLDivElement> {\n const { activeOption } = state;\n const scrollContainerRef = React.useRef<HTMLDivElement>(null);\n\n React.useEffect(() => {\n if (scrollContainerRef.current && activeOption && canUseDOM()) {\n const activeOptionElement = scrollContainerRef.current.querySelector(`#${activeOption.id}`) as HTMLElement;\n\n if (!activeOptionElement) {\n return;\n }\n\n const { offsetHeight, offsetTop } = activeOptionElement;\n const { offsetHeight: parentOffsetHeight, scrollTop } = scrollContainerRef.current;\n\n const isAbove = offsetTop < scrollTop;\n const isBelow = offsetTop + offsetHeight > scrollTop + parentOffsetHeight;\n\n // add a small buffer for general visual nicety\n // it looks slightly better if the option has some space from the top/bottom while arrowing\n const buffer = 2;\n\n if (isAbove) {\n scrollContainerRef.current.scrollTo(0, offsetTop - buffer);\n } else if (isBelow) {\n scrollContainerRef.current.scrollTo(0, offsetTop - parentOffsetHeight + offsetHeight + buffer);\n }\n }\n }, [activeOption]);\n\n return scrollContainerRef;\n}\n"]}
|