@fluentui/react-combobox 9.0.0-beta.8 → 9.0.0-beta.9
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 +117 -4
- package/CHANGELOG.md +28 -5
- package/Spec.md +4 -4
- package/dist/index.d.ts +25 -16
- package/lib/components/Combobox/Combobox.types.js.map +1 -1
- package/lib/components/Combobox/renderCombobox.js +3 -4
- package/lib/components/Combobox/renderCombobox.js.map +1 -1
- package/lib/components/Combobox/useCombobox.js +153 -15
- package/lib/components/Combobox/useCombobox.js.map +1 -1
- package/lib/components/Combobox/useComboboxStyles.js +56 -25
- package/lib/components/Combobox/useComboboxStyles.js.map +1 -1
- package/lib/components/Dropdown/Dropdown.types.js.map +1 -1
- package/lib/components/Dropdown/renderDropdown.js +3 -4
- package/lib/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdown.js +100 -8
- package/lib/components/Dropdown/useDropdown.js.map +1 -1
- package/lib/components/Dropdown/useDropdownStyles.js +41 -19
- package/lib/components/Dropdown/useDropdownStyles.js.map +1 -1
- package/lib/components/Listbox/Listbox.types.js.map +1 -1
- package/lib/components/Listbox/useListbox.js +25 -17
- package/lib/components/Listbox/useListbox.js.map +1 -1
- package/lib/components/Option/Option.types.js.map +1 -1
- package/lib/components/Option/useOption.js +29 -21
- package/lib/components/Option/useOption.js.map +1 -1
- package/lib/components/Option/useOptionStyles.js +2 -1
- package/lib/components/Option/useOptionStyles.js.map +1 -1
- package/lib/contexts/ComboboxContext.js +11 -4
- package/lib/contexts/ComboboxContext.js.map +1 -1
- package/lib/contexts/ListboxContext.js +9 -4
- 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 +8 -4
- package/lib/contexts/useListboxContextValues.js.map +1 -1
- package/lib/utils/ComboboxBase.types.js.map +1 -1
- package/lib/utils/Selection.types.js.map +1 -1
- package/lib/utils/dropdownKeyActions.js +2 -9
- package/lib/utils/dropdownKeyActions.js.map +1 -1
- package/lib/utils/useComboboxBaseState.js +29 -24
- package/lib/utils/useComboboxBaseState.js.map +1 -1
- package/lib/utils/useComboboxPopup.js +5 -3
- package/lib/utils/useComboboxPopup.js.map +1 -1
- package/lib/utils/useSelection.js +13 -4
- package/lib/utils/useSelection.js.map +1 -1
- package/lib/utils/useTriggerListboxSlots.js +45 -50
- package/lib/utils/useTriggerListboxSlots.js.map +1 -1
- package/lib-commonjs/components/Combobox/renderCombobox.js +3 -4
- package/lib-commonjs/components/Combobox/renderCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useCombobox.js +152 -14
- package/lib-commonjs/components/Combobox/useCombobox.js.map +1 -1
- package/lib-commonjs/components/Combobox/useComboboxStyles.js +56 -25
- package/lib-commonjs/components/Combobox/useComboboxStyles.js.map +1 -1
- package/lib-commonjs/components/Dropdown/renderDropdown.js +3 -4
- package/lib-commonjs/components/Dropdown/renderDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdown.js +101 -7
- package/lib-commonjs/components/Dropdown/useDropdown.js.map +1 -1
- package/lib-commonjs/components/Dropdown/useDropdownStyles.js +41 -19
- package/lib-commonjs/components/Dropdown/useDropdownStyles.js.map +1 -1
- package/lib-commonjs/components/Listbox/useListbox.js +24 -16
- package/lib-commonjs/components/Listbox/useListbox.js.map +1 -1
- package/lib-commonjs/components/Option/useOption.js +29 -21
- package/lib-commonjs/components/Option/useOption.js.map +1 -1
- package/lib-commonjs/components/Option/useOptionStyles.js +2 -1
- package/lib-commonjs/components/Option/useOptionStyles.js.map +1 -1
- package/lib-commonjs/contexts/ComboboxContext.js +11 -4
- package/lib-commonjs/contexts/ComboboxContext.js.map +1 -1
- package/lib-commonjs/contexts/ListboxContext.js +9 -4
- package/lib-commonjs/contexts/ListboxContext.js.map +1 -1
- package/lib-commonjs/contexts/useComboboxContextValues.js +8 -2
- package/lib-commonjs/contexts/useComboboxContextValues.js.map +1 -1
- package/lib-commonjs/contexts/useListboxContextValues.js +8 -4
- package/lib-commonjs/contexts/useListboxContextValues.js.map +1 -1
- package/lib-commonjs/utils/dropdownKeyActions.js +2 -9
- package/lib-commonjs/utils/dropdownKeyActions.js.map +1 -1
- package/lib-commonjs/utils/useComboboxBaseState.js +29 -24
- package/lib-commonjs/utils/useComboboxBaseState.js.map +1 -1
- package/lib-commonjs/utils/useComboboxPopup.js +5 -3
- package/lib-commonjs/utils/useComboboxPopup.js.map +1 -1
- package/lib-commonjs/utils/useSelection.js +13 -4
- package/lib-commonjs/utils/useSelection.js.map +1 -1
- package/lib-commonjs/utils/useTriggerListboxSlots.js +44 -49
- package/lib-commonjs/utils/useTriggerListboxSlots.js.map +1 -1
- package/package.json +9 -9
- package/dist/tsdoc-metadata.json +0 -11
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,120 @@
|
|
|
2
2
|
"name": "@fluentui/react-combobox",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Thu, 15 Sep 2022 09:45:21 GMT",
|
|
6
|
+
"tag": "@fluentui/react-combobox_v9.0.0-beta.9",
|
|
7
|
+
"version": "9.0.0-beta.9",
|
|
8
|
+
"comments": {
|
|
9
|
+
"prerelease": [
|
|
10
|
+
{
|
|
11
|
+
"author": "sarah.higley@microsoft.com",
|
|
12
|
+
"package": "@fluentui/react-combobox",
|
|
13
|
+
"commit": "8484a3ec4abb520d716d199ea79a3cde57fa1da2",
|
|
14
|
+
"comment": "fix: typing moves active option in Dropdown"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"author": "sarah.higley@microsoft.com",
|
|
18
|
+
"package": "@fluentui/react-combobox",
|
|
19
|
+
"commit": "286479fb4e813506a9560c279215675e8b097500",
|
|
20
|
+
"comment": "fix: Combobox and Dropdown hover/active border colors and padding styles"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"author": "olfedias@microsoft.com",
|
|
24
|
+
"package": "@fluentui/react-combobox",
|
|
25
|
+
"commit": "e610024474cfe5d45f61501a8b6a21daf4c794a2",
|
|
26
|
+
"comment": "chore: Update Griffel to latest version"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"author": "sarah.higley@microsoft.com",
|
|
30
|
+
"package": "@fluentui/react-combobox",
|
|
31
|
+
"commit": "58026c94a40e8589645d3f6a6b0171a21ba3f879",
|
|
32
|
+
"comment": "fix: Combobox and Dropdown only show option focus outline when navigating by keyboard"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"author": "sarah.higley@microsoft.com",
|
|
36
|
+
"package": "@fluentui/react-combobox",
|
|
37
|
+
"commit": "83b033de0fe819bc30cc437ec7c4a83dd4c6997e",
|
|
38
|
+
"comment": "fix: set popup Listbox width to trigger width"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"author": "sarah.higley@microsoft.com",
|
|
42
|
+
"package": "@fluentui/react-combobox",
|
|
43
|
+
"commit": "a5b36f689a2eed64ffca5f43e48e213ccba1d925",
|
|
44
|
+
"comment": "fix: open/close combobox on icon click"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"author": "sarah.higley@microsoft.com",
|
|
48
|
+
"package": "@fluentui/react-combobox",
|
|
49
|
+
"commit": "7d19a95495b04963b9f88b45da993e590df06b6a",
|
|
50
|
+
"comment": "feat: Allow typing by default, add allowFreeform"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"author": "sarah.higley@microsoft.com",
|
|
54
|
+
"package": "@fluentui/react-combobox",
|
|
55
|
+
"commit": "cde2f43f6bf0522ddf189dbf3b2905ec1f2f7f88",
|
|
56
|
+
"comment": "feat: make listbox slot nullable"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"author": "sarah.higley@microsoft.com",
|
|
60
|
+
"package": "@fluentui/react-combobox",
|
|
61
|
+
"commit": "4f921f9810a55ae8d2077de4013fad1516001c0c",
|
|
62
|
+
"comment": "fix: react-combobox change onSelect to onOptionSelect to avoid conflicts with native onSelect"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"author": "beachball",
|
|
66
|
+
"package": "@fluentui/react-combobox",
|
|
67
|
+
"comment": "Bump @fluentui/react-context-selector to v9.0.3",
|
|
68
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"author": "beachball",
|
|
72
|
+
"package": "@fluentui/react-combobox",
|
|
73
|
+
"comment": "Bump @fluentui/react-portal to v9.0.5",
|
|
74
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"author": "beachball",
|
|
78
|
+
"package": "@fluentui/react-combobox",
|
|
79
|
+
"comment": "Bump @fluentui/react-positioning to v9.2.0",
|
|
80
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"author": "beachball",
|
|
84
|
+
"package": "@fluentui/react-combobox",
|
|
85
|
+
"comment": "Bump @fluentui/react-theme to v9.1.0",
|
|
86
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"author": "beachball",
|
|
90
|
+
"package": "@fluentui/react-combobox",
|
|
91
|
+
"comment": "Bump @fluentui/react-utilities to v9.1.0",
|
|
92
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"author": "beachball",
|
|
96
|
+
"package": "@fluentui/react-combobox",
|
|
97
|
+
"comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.13",
|
|
98
|
+
"commit": "a33448fe4a0f4117686c378f80b893d1406d95a8"
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
"none": [
|
|
102
|
+
{
|
|
103
|
+
"author": "martinhochel@microsoft.com",
|
|
104
|
+
"package": "@fluentui/react-combobox",
|
|
105
|
+
"commit": "e6cf183695d6d67a24e038c49a876224e5ed35e5",
|
|
106
|
+
"comment": "chore: update package scaffold"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"author": "bernardo.sunderhus@gmail.com",
|
|
110
|
+
"package": "@fluentui/react-combobox",
|
|
111
|
+
"commit": "84017b6464e13c46a7ae8c61875ead2ff4b6965b",
|
|
112
|
+
"comment": "bugfix: update useMergedEventCallbacks to mergeCallbacks"
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"date": "Wed, 03 Aug 2022 16:03:42 GMT",
|
|
6
119
|
"tag": "@fluentui/react-combobox_v9.0.0-beta.8",
|
|
7
120
|
"version": "9.0.0-beta.8",
|
|
8
121
|
"comments": {
|
|
@@ -29,19 +142,19 @@
|
|
|
29
142
|
"author": "beachball",
|
|
30
143
|
"package": "@fluentui/react-combobox",
|
|
31
144
|
"comment": "Bump @fluentui/react-portal to v9.0.4",
|
|
32
|
-
"commit": "
|
|
145
|
+
"commit": "ee4a8be0d0831a6615f878f98db6a97cc61a802d"
|
|
33
146
|
},
|
|
34
147
|
{
|
|
35
148
|
"author": "beachball",
|
|
36
149
|
"package": "@fluentui/react-combobox",
|
|
37
150
|
"comment": "Bump @fluentui/react-positioning to v9.1.2",
|
|
38
|
-
"commit": "
|
|
151
|
+
"commit": "ee4a8be0d0831a6615f878f98db6a97cc61a802d"
|
|
39
152
|
},
|
|
40
153
|
{
|
|
41
154
|
"author": "beachball",
|
|
42
155
|
"package": "@fluentui/react-combobox",
|
|
43
156
|
"comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.12",
|
|
44
|
-
"commit": "
|
|
157
|
+
"commit": "ee4a8be0d0831a6615f878f98db6a97cc61a802d"
|
|
45
158
|
}
|
|
46
159
|
],
|
|
47
160
|
"none": [
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-combobox
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 15 Sep 2022 09:45:21 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.0.0-beta.9](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.0.0-beta.9)
|
|
8
|
+
|
|
9
|
+
Thu, 15 Sep 2022 09:45:21 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.0.0-beta.8..@fluentui/react-combobox_v9.0.0-beta.9)
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
|
|
14
|
+
- fix: typing moves active option in Dropdown ([PR #24437](https://github.com/microsoft/fluentui/pull/24437) by sarah.higley@microsoft.com)
|
|
15
|
+
- fix: Combobox and Dropdown hover/active border colors and padding styles ([PR #24362](https://github.com/microsoft/fluentui/pull/24362) by sarah.higley@microsoft.com)
|
|
16
|
+
- chore: Update Griffel to latest version ([PR #24221](https://github.com/microsoft/fluentui/pull/24221) by olfedias@microsoft.com)
|
|
17
|
+
- fix: Combobox and Dropdown only show option focus outline when navigating by keyboard ([PR #24700](https://github.com/microsoft/fluentui/pull/24700) by sarah.higley@microsoft.com)
|
|
18
|
+
- fix: set popup Listbox width to trigger width ([PR #24733](https://github.com/microsoft/fluentui/pull/24733) by sarah.higley@microsoft.com)
|
|
19
|
+
- fix: open/close combobox on icon click ([PR #24147](https://github.com/microsoft/fluentui/pull/24147) by sarah.higley@microsoft.com)
|
|
20
|
+
- feat: Allow typing by default, add allowFreeform ([PR #23819](https://github.com/microsoft/fluentui/pull/23819) by sarah.higley@microsoft.com)
|
|
21
|
+
- feat: make listbox slot nullable ([PR #24392](https://github.com/microsoft/fluentui/pull/24392) by sarah.higley@microsoft.com)
|
|
22
|
+
- fix: react-combobox change onSelect to onOptionSelect to avoid conflicts with native onSelect ([PR #24550](https://github.com/microsoft/fluentui/pull/24550) by sarah.higley@microsoft.com)
|
|
23
|
+
- Bump @fluentui/react-context-selector to v9.0.3 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
|
24
|
+
- Bump @fluentui/react-portal to v9.0.5 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
|
25
|
+
- Bump @fluentui/react-positioning to v9.2.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
|
26
|
+
- Bump @fluentui/react-theme to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
|
27
|
+
- Bump @fluentui/react-utilities to v9.1.0 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
|
28
|
+
- Bump @fluentui/react-conformance-griffel to v9.0.0-beta.13 ([PR #24808](https://github.com/microsoft/fluentui/pull/24808) by beachball)
|
|
29
|
+
|
|
7
30
|
## [9.0.0-beta.8](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.0.0-beta.8)
|
|
8
31
|
|
|
9
|
-
Wed, 03 Aug 2022 16:
|
|
32
|
+
Wed, 03 Aug 2022 16:03:42 GMT
|
|
10
33
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.0.0-beta.7..@fluentui/react-combobox_v9.0.0-beta.8)
|
|
11
34
|
|
|
12
35
|
### Changes
|
|
@@ -14,9 +37,9 @@ Wed, 03 Aug 2022 16:00:09 GMT
|
|
|
14
37
|
- fix: prevent react-combobox keyboard selection of disabled options ([PR #24073](https://github.com/microsoft/fluentui/pull/24073) by sarah.higley@microsoft.com)
|
|
15
38
|
- chore: Bump Griffel dependencies ([PR #24114](https://github.com/microsoft/fluentui/pull/24114) by miroslav.stastny@microsoft.com)
|
|
16
39
|
- bugfix: add reduced motion styles for avatar, spinner, switch, and input focus styles ([PR #23788](https://github.com/microsoft/fluentui/pull/23788) by sarah.higley@microsoft.com)
|
|
17
|
-
- Bump @fluentui/react-portal to v9.0.4 ([PR #
|
|
18
|
-
- Bump @fluentui/react-positioning to v9.1.2 ([PR #
|
|
19
|
-
- Bump @fluentui/react-conformance-griffel to v9.0.0-beta.12 ([PR #
|
|
40
|
+
- Bump @fluentui/react-portal to v9.0.4 ([PR #24131](https://github.com/microsoft/fluentui/pull/24131) by beachball)
|
|
41
|
+
- Bump @fluentui/react-positioning to v9.1.2 ([PR #24131](https://github.com/microsoft/fluentui/pull/24131) by beachball)
|
|
42
|
+
- Bump @fluentui/react-conformance-griffel to v9.0.0-beta.12 ([PR #24131](https://github.com/microsoft/fluentui/pull/24131) by beachball)
|
|
20
43
|
|
|
21
44
|
## [9.0.0-beta.7](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.0.0-beta.7)
|
|
22
45
|
|
package/Spec.md
CHANGED
|
@@ -143,9 +143,9 @@ Combobox in v9 allows both controlled and uncontrolled selection, as do the corr
|
|
|
143
143
|
| -------------------- | ------------------- | ------------------- | ------------------ | -------------------- | ------------ |
|
|
144
144
|
| Initial selection | initialSelectedKeys | defaultSelectedKeys | defaultSelectedKey | defaultSelectedItems | defaultValue |
|
|
145
145
|
| Controlled selection | selectedKeys | selectedKey | selectedKey | selectedItems | value |
|
|
146
|
-
| Callback |
|
|
146
|
+
| Callback | onOptionSelect | onChange | onChange | onChange | onChange |
|
|
147
147
|
|
|
148
|
-
The reason to move to `
|
|
148
|
+
The reason to move to `onOptionSelect` over `onChange` in the v9 Combobox is because the editable Combobox uses an `<input>` element as its primary slot. Using `onOptionSelect` allows the input to retain it's built-in `onChange` event.
|
|
149
149
|
|
|
150
150
|
## Sample Code
|
|
151
151
|
|
|
@@ -344,7 +344,7 @@ type SimpleComboboxProps = {
|
|
|
344
344
|
onOpenChange?(event: OpenEvents, data: OnOpenChangeData): void;
|
|
345
345
|
|
|
346
346
|
/* Callback when an option is selected */
|
|
347
|
-
|
|
347
|
+
onOptionSelect?(event: SelectionEvents, optionKey: string): void;
|
|
348
348
|
};
|
|
349
349
|
```
|
|
350
350
|
|
|
@@ -367,7 +367,7 @@ type SimpleListboxProps = {
|
|
|
367
367
|
selectedKeys?: string[];
|
|
368
368
|
|
|
369
369
|
/* Callback when an option is selected */
|
|
370
|
-
|
|
370
|
+
onOptionSelect?(event: SelectionEvents, optionKey: string): void;
|
|
371
371
|
};
|
|
372
372
|
```
|
|
373
373
|
|
package/dist/index.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ declare type ComboboxBaseProps = SelectionProps & {
|
|
|
75
75
|
size?: 'small' | 'medium' | 'large';
|
|
76
76
|
/**
|
|
77
77
|
* The value displayed by the Combobox.
|
|
78
|
-
* Use this with `
|
|
78
|
+
* Use this with `onOptionSelect` to directly control the displayed value string
|
|
79
79
|
*/
|
|
80
80
|
value?: string;
|
|
81
81
|
};
|
|
@@ -85,10 +85,15 @@ declare type ComboboxBaseProps = SelectionProps & {
|
|
|
85
85
|
*/
|
|
86
86
|
declare type ComboboxBaseState = Required<Pick<ComboboxBaseProps, 'appearance' | 'open' | 'inlinePopup' | 'size'>> & Pick<ComboboxBaseProps, 'placeholder' | 'value'> & OptionCollectionState & SelectionState & {
|
|
87
87
|
activeOption?: OptionValue;
|
|
88
|
-
|
|
88
|
+
focusVisible: boolean;
|
|
89
|
+
hasFocus: boolean;
|
|
90
|
+
ignoreNextBlur: React_2.MutableRefObject<boolean>;
|
|
89
91
|
selectOption(event: SelectionEvents, option: OptionValue): void;
|
|
90
92
|
setActiveOption(option?: OptionValue): void;
|
|
93
|
+
setFocusVisible(focusVisible: boolean): void;
|
|
94
|
+
setHasFocus(hasFocus: boolean): void;
|
|
91
95
|
setOpen(event: ComboboxBaseOpenEvents, newState: boolean): void;
|
|
96
|
+
setValue(newValue: string): void;
|
|
92
97
|
};
|
|
93
98
|
|
|
94
99
|
export declare const comboboxClassNames: SlotClassNames<ComboboxSlots>;
|
|
@@ -96,7 +101,7 @@ export declare const comboboxClassNames: SlotClassNames<ComboboxSlots>;
|
|
|
96
101
|
/**
|
|
97
102
|
* Context shared with Combobox, Listbox, & Options
|
|
98
103
|
*/
|
|
99
|
-
declare type ComboboxContextValue = Pick<ComboboxState, 'activeOption' | 'appearance' | '
|
|
104
|
+
declare type ComboboxContextValue = Pick<ComboboxState, 'activeOption' | 'appearance' | 'focusVisible' | 'open' | 'registerOption' | 'selectedOptions' | 'selectOption' | 'setActiveOption' | 'setOpen' | 'size'>;
|
|
100
105
|
|
|
101
106
|
export declare type ComboboxContextValues = ComboboxBaseContextValues;
|
|
102
107
|
|
|
@@ -108,14 +113,15 @@ export declare type ComboboxOpenEvents = ComboboxBaseOpenEvents;
|
|
|
108
113
|
* Combobox Props
|
|
109
114
|
*/
|
|
110
115
|
export declare type ComboboxProps = Omit<ComponentProps<Partial<ComboboxSlots>, 'input'>, 'children' | 'size'> & ComboboxBaseProps & {
|
|
111
|
-
|
|
116
|
+
freeform?: boolean;
|
|
117
|
+
children?: React_2.ReactNode;
|
|
112
118
|
};
|
|
113
119
|
|
|
114
120
|
export declare type ComboboxSlots = {
|
|
115
121
|
root: NonNullable<Slot<'div'>>;
|
|
116
122
|
expandIcon: Slot<'span'>;
|
|
117
123
|
input: NonNullable<Slot<'input'>>;
|
|
118
|
-
listbox
|
|
124
|
+
listbox?: Slot<typeof Listbox>;
|
|
119
125
|
};
|
|
120
126
|
|
|
121
127
|
/**
|
|
@@ -145,7 +151,7 @@ export declare type DropdownSlots = {
|
|
|
145
151
|
root: NonNullable<Slot<'div'>>;
|
|
146
152
|
expandIcon: Slot<'span'>;
|
|
147
153
|
button: NonNullable<Slot<'button'>>;
|
|
148
|
-
listbox
|
|
154
|
+
listbox?: Slot<typeof Listbox>;
|
|
149
155
|
};
|
|
150
156
|
|
|
151
157
|
/**
|
|
@@ -165,7 +171,7 @@ export declare const listboxClassNames: SlotClassNames<ListboxSlots>;
|
|
|
165
171
|
/**
|
|
166
172
|
* Context shared with all Listbox Options
|
|
167
173
|
*/
|
|
168
|
-
declare type ListboxContextValue = Pick<ListboxState, 'activeOption' | '
|
|
174
|
+
declare type ListboxContextValue = Pick<ListboxState, 'activeOption' | 'focusVisible' | 'multiselect' | 'registerOption' | 'selectedOptions' | 'selectOption' | 'setActiveOption'>;
|
|
169
175
|
|
|
170
176
|
export declare type ListboxContextValues = {
|
|
171
177
|
listbox: ListboxContextValue;
|
|
@@ -185,12 +191,9 @@ export declare type ListboxSlots = {
|
|
|
185
191
|
*/
|
|
186
192
|
export declare type ListboxState = ComponentState<ListboxSlots> & OptionCollectionState & SelectionState & {
|
|
187
193
|
activeOption?: OptionValue;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
declare type OnSelectData = {
|
|
192
|
-
optionValue: string;
|
|
193
|
-
selectedOptions: string[];
|
|
194
|
+
focusVisible: boolean;
|
|
195
|
+
selectOption(event: SelectionEvents, option: OptionValue): void;
|
|
196
|
+
setActiveOption(option?: OptionValue): void;
|
|
194
197
|
};
|
|
195
198
|
|
|
196
199
|
/**
|
|
@@ -239,6 +242,11 @@ export declare type OptionGroupSlots = {
|
|
|
239
242
|
*/
|
|
240
243
|
export declare type OptionGroupState = ComponentState<OptionGroupSlots>;
|
|
241
244
|
|
|
245
|
+
declare type OptionOnSelectData = {
|
|
246
|
+
optionValue: string | undefined;
|
|
247
|
+
selectedOptions: string[];
|
|
248
|
+
};
|
|
249
|
+
|
|
242
250
|
/**
|
|
243
251
|
* Option Props
|
|
244
252
|
*/
|
|
@@ -261,6 +269,7 @@ export declare type OptionSlots = {
|
|
|
261
269
|
*/
|
|
262
270
|
export declare type OptionState = ComponentState<OptionSlots> & Pick<OptionProps, 'disabled'> & {
|
|
263
271
|
active: boolean;
|
|
272
|
+
focusVisible: boolean;
|
|
264
273
|
multiselect?: boolean;
|
|
265
274
|
selected: boolean;
|
|
266
275
|
};
|
|
@@ -299,7 +308,7 @@ export declare const renderOption_unstable: (state: OptionState) => JSX.Element;
|
|
|
299
308
|
*/
|
|
300
309
|
export declare const renderOptionGroup_unstable: (state: OptionGroupState) => JSX.Element;
|
|
301
310
|
|
|
302
|
-
declare type SelectionEvents = React_2.
|
|
311
|
+
declare type SelectionEvents = React_2.ChangeEvent<HTMLElement> | React_2.KeyboardEvent<HTMLElement> | React_2.MouseEvent<HTMLElement>;
|
|
303
312
|
|
|
304
313
|
declare type SelectionProps = {
|
|
305
314
|
defaultSelectedOptions?: string[];
|
|
@@ -310,10 +319,10 @@ declare type SelectionProps = {
|
|
|
310
319
|
* @default false
|
|
311
320
|
*/
|
|
312
321
|
multiselect?: boolean;
|
|
313
|
-
|
|
322
|
+
onOptionSelect?: (event: SelectionEvents, data: OptionOnSelectData) => void;
|
|
314
323
|
/**
|
|
315
324
|
* An array of selected option keys.
|
|
316
|
-
* Use this with `
|
|
325
|
+
* Use this with `onOptionSelect` to directly control the selected option(s)
|
|
317
326
|
*/
|
|
318
327
|
selectedOptions?: string[];
|
|
319
328
|
};
|
|
@@ -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":["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"]}
|
|
@@ -11,14 +11,13 @@ export const renderCombobox_unstable = (state, contextValues) => {
|
|
|
11
11
|
slots,
|
|
12
12
|
slotProps
|
|
13
13
|
} = getSlots(state);
|
|
14
|
-
const listbox = /*#__PURE__*/React.createElement(slots.listbox, { ...slotProps.listbox
|
|
15
|
-
}, slotProps.root.children);
|
|
16
|
-
const popup = state.inlinePopup ? listbox : /*#__PURE__*/React.createElement(Portal, null, listbox);
|
|
17
14
|
return /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
|
|
18
15
|
}, /*#__PURE__*/React.createElement(ComboboxContext.Provider, {
|
|
19
16
|
value: contextValues.combobox
|
|
20
17
|
}, /*#__PURE__*/React.createElement(slots.input, { ...slotProps.input
|
|
21
18
|
}), slots.expandIcon && /*#__PURE__*/React.createElement(slots.expandIcon, { ...slotProps.expandIcon
|
|
22
|
-
}), state.
|
|
19
|
+
}), slots.listbox && (state.inlinePopup ? /*#__PURE__*/React.createElement(slots.listbox, { ...slotProps.listbox
|
|
20
|
+
}) : /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(slots.listbox, { ...slotProps.listbox
|
|
21
|
+
})))));
|
|
23
22
|
};
|
|
24
23
|
//# sourceMappingURL=renderCombobox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["components/Combobox/renderCombobox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,MAAT,QAAuB,wBAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AACA,SAAS,eAAT,QAAgC,gCAAhC;AAGA;;AAEG;;AACH,OAAO,MAAM,uBAAuB,GAAG,CAAC,KAAD,EAAuB,aAAvB,KAA+D;EACpG,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAAgB,KAAhB,CAArC;EAEA,
|
|
1
|
+
{"version":3,"sources":["components/Combobox/renderCombobox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,MAAT,QAAuB,wBAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AACA,SAAS,eAAT,QAAgC,gCAAhC;AAGA;;AAEG;;AACH,OAAO,MAAM,uBAAuB,GAAG,CAAC,KAAD,EAAuB,aAAvB,KAA+D;EACpG,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAAgB,KAAhB,CAArC;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,eACE,KAAA,CAAA,aAAA,CAAC,eAAe,CAAC,QAAjB,EAAyB;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAzB,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,KAAP,EAAY,EAAA,GAAK,SAAS,CAAC;EAAf,CAAZ,CADF,EAEG,KAAK,CAAC,UAAN,iBAAoB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,UAAP,EAAiB,EAAA,GAAK,SAAS,CAAC;EAAf,CAAjB,CAFvB,EAGG,KAAK,CAAC,OAAN,KACE,KAAK,CAAC,WAAN,gBACC,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,OAAP,EAAc,EAAA,GAAK,SAAS,CAAC;EAAf,CAAd,CADD,gBAGC,KAAA,CAAA,aAAA,CAAC,MAAD,EAAO,IAAP,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,OAAP,EAAc,EAAA,GAAK,SAAS,CAAC;EAAf,CAAd,CADF,CAJH,CAHH,CADF,CADF;AAgBD,CAnBM","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"],"sourceRoot":"../src/"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';
|
|
3
|
-
import { getPartitionedNativeProps, resolveShorthand } from '@fluentui/react-utilities';
|
|
3
|
+
import { getPartitionedNativeProps, resolveShorthand, mergeCallbacks, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
|
|
4
4
|
import { useComboboxBaseState } from '../../utils/useComboboxBaseState';
|
|
5
5
|
import { useTriggerListboxSlots } from '../../utils/useTriggerListboxSlots';
|
|
6
6
|
import { useComboboxPopup } from '../../utils/useComboboxPopup';
|
|
@@ -16,7 +16,28 @@ import { Listbox } from '../Listbox/Listbox';
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
export const useCombobox_unstable = (props, ref) => {
|
|
19
|
+
var _a;
|
|
20
|
+
|
|
19
21
|
const baseState = useComboboxBaseState(props);
|
|
22
|
+
const {
|
|
23
|
+
activeOption,
|
|
24
|
+
clearSelection,
|
|
25
|
+
getIndexOfId,
|
|
26
|
+
getOptionsMatchingValue,
|
|
27
|
+
hasFocus,
|
|
28
|
+
open,
|
|
29
|
+
selectOption,
|
|
30
|
+
selectedOptions,
|
|
31
|
+
setActiveOption,
|
|
32
|
+
setFocusVisible,
|
|
33
|
+
setOpen,
|
|
34
|
+
setValue,
|
|
35
|
+
value
|
|
36
|
+
} = baseState;
|
|
37
|
+
const {
|
|
38
|
+
freeform,
|
|
39
|
+
multiselect
|
|
40
|
+
} = props;
|
|
20
41
|
const {
|
|
21
42
|
primary: triggerNativeProps,
|
|
22
43
|
root: rootNativeProps
|
|
@@ -25,22 +46,116 @@ export const useCombobox_unstable = (props, ref) => {
|
|
|
25
46
|
primarySlotTagName: 'input',
|
|
26
47
|
excludedPropNames: ['children', 'size']
|
|
27
48
|
});
|
|
28
|
-
const
|
|
49
|
+
const rootRef = React.useRef(null);
|
|
50
|
+
const triggerRef = React.useRef(null); // calculate listbox width style based on trigger width
|
|
51
|
+
|
|
52
|
+
const [popupWidth, setPopupWidth] = React.useState();
|
|
53
|
+
React.useEffect(() => {
|
|
54
|
+
var _a;
|
|
55
|
+
|
|
56
|
+
const width = open ? `${(_a = rootRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth}px` : undefined;
|
|
57
|
+
setPopupWidth(width);
|
|
58
|
+
}, [open]); // handle input type-to-select
|
|
59
|
+
|
|
60
|
+
const getSearchString = inputValue => {
|
|
61
|
+
// if there are commas in the value string, take the text after the last comma
|
|
62
|
+
const searchString = inputValue.split(',').pop();
|
|
63
|
+
return (searchString === null || searchString === void 0 ? void 0 : searchString.trim().toLowerCase()) || '';
|
|
64
|
+
}; // set active option and selection based on typing
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
const getOptionFromInput = inputValue => {
|
|
68
|
+
var _a;
|
|
69
|
+
|
|
70
|
+
const searchString = getSearchString(inputValue);
|
|
71
|
+
|
|
72
|
+
if (searchString.length === 0) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const matcher = optionValue => optionValue.toLowerCase().indexOf(searchString) === 0;
|
|
77
|
+
|
|
78
|
+
const matches = getOptionsMatchingValue(matcher); // return first matching option after the current active option, looping back to the top
|
|
79
|
+
|
|
80
|
+
if (matches.length > 1 && activeOption) {
|
|
81
|
+
const startIndex = getIndexOfId(activeOption.id);
|
|
82
|
+
const nextMatch = matches.find(option => getIndexOfId(option.id) >= startIndex);
|
|
83
|
+
return nextMatch !== null && nextMatch !== void 0 ? nextMatch : matches[0];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (_a = matches[0]) !== null && _a !== void 0 ? _a : undefined;
|
|
87
|
+
};
|
|
88
|
+
/* Handle typed input */
|
|
89
|
+
// reset any typed value when an option is selected
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
baseState.selectOption = (ev, option) => {
|
|
93
|
+
setValue(undefined);
|
|
94
|
+
selectOption(ev, option);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const onTriggerBlur = ev => {
|
|
98
|
+
// handle selection and updating value if freeform is false
|
|
99
|
+
if (!baseState.open && !freeform) {
|
|
100
|
+
// select matching option, if the value fully matches
|
|
101
|
+
if (value && activeOption && getSearchString(value) === (activeOption === null || activeOption === void 0 ? void 0 : activeOption.value.toLowerCase())) {
|
|
102
|
+
baseState.selectOption(ev, activeOption);
|
|
103
|
+
} // reset typed value when the input loses focus while collapsed, unless freeform is true
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
setValue(undefined);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
baseState.setOpen = (ev, newState) => {
|
|
111
|
+
if (!newState && !freeform) {
|
|
112
|
+
setValue(undefined);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setOpen(ev, newState);
|
|
116
|
+
}; // update value and active option based on input
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
const onTriggerChange = ev => {
|
|
120
|
+
const inputValue = ev.target.value; // update uncontrolled value
|
|
121
|
+
|
|
122
|
+
baseState.setValue(inputValue); // handle updating active option based on input
|
|
123
|
+
|
|
124
|
+
const matchingOption = getOptionFromInput(inputValue);
|
|
125
|
+
setActiveOption(matchingOption);
|
|
126
|
+
setFocusVisible(true); // clear selection for single-select if the input value no longer matches the selection
|
|
127
|
+
|
|
128
|
+
if (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || selectedOptions[0].indexOf(inputValue) !== 0)) {
|
|
129
|
+
clearSelection(ev);
|
|
130
|
+
}
|
|
131
|
+
}; // resolve input and listbox slot props
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
let triggerSlot;
|
|
135
|
+
let listboxSlot;
|
|
136
|
+
triggerSlot = resolveShorthand(props.input, {
|
|
29
137
|
required: true,
|
|
30
138
|
defaultProps: {
|
|
31
|
-
|
|
32
|
-
/* Combobox does not yet support allowFreeForm */
|
|
33
|
-
},
|
|
139
|
+
ref: useMergedRefs((_a = props.input) === null || _a === void 0 ? void 0 : _a.ref, triggerRef),
|
|
34
140
|
type: 'text',
|
|
35
|
-
value:
|
|
141
|
+
value: value !== null && value !== void 0 ? value : '',
|
|
36
142
|
...triggerNativeProps
|
|
37
143
|
}
|
|
38
144
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
145
|
+
triggerSlot.onChange = mergeCallbacks(triggerSlot.onChange, onTriggerChange);
|
|
146
|
+
triggerSlot.onBlur = mergeCallbacks(triggerSlot.onBlur, onTriggerBlur); // only resolve listbox slot if needed
|
|
147
|
+
|
|
148
|
+
listboxSlot = open || hasFocus ? resolveShorthand(props.listbox, {
|
|
149
|
+
required: true,
|
|
150
|
+
defaultProps: {
|
|
151
|
+
children: props.children,
|
|
152
|
+
style: {
|
|
153
|
+
width: popupWidth
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}) : undefined;
|
|
157
|
+
[triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);
|
|
158
|
+
[triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);
|
|
44
159
|
const state = {
|
|
45
160
|
components: {
|
|
46
161
|
root: 'div',
|
|
@@ -50,9 +165,7 @@ export const useCombobox_unstable = (props, ref) => {
|
|
|
50
165
|
},
|
|
51
166
|
root: resolveShorthand(props.root, {
|
|
52
167
|
required: true,
|
|
53
|
-
defaultProps: {
|
|
54
|
-
children: props.children,
|
|
55
|
-
...rootNativeProps
|
|
168
|
+
defaultProps: { ...rootNativeProps
|
|
56
169
|
}
|
|
57
170
|
}),
|
|
58
171
|
input: triggerSlot,
|
|
@@ -63,8 +176,33 @@ export const useCombobox_unstable = (props, ref) => {
|
|
|
63
176
|
children: /*#__PURE__*/React.createElement(ChevronDownIcon, null)
|
|
64
177
|
}
|
|
65
178
|
}),
|
|
66
|
-
...baseState
|
|
179
|
+
...baseState,
|
|
180
|
+
setOpen
|
|
67
181
|
};
|
|
182
|
+
state.root.ref = useMergedRefs(state.root.ref, rootRef);
|
|
183
|
+
/* handle open/close + focus change when clicking expandIcon */
|
|
184
|
+
|
|
185
|
+
const {
|
|
186
|
+
onMouseDown: onIconMouseDown,
|
|
187
|
+
onClick: onIconClick
|
|
188
|
+
} = state.expandIcon || {};
|
|
189
|
+
const onExpandIconMouseDown = useEventCallback(mergeCallbacks(onIconMouseDown, () => {
|
|
190
|
+
// do not dismiss on blur when clicking the icon
|
|
191
|
+
baseState.ignoreNextBlur.current = true;
|
|
192
|
+
}));
|
|
193
|
+
const onExpandIconClick = useEventCallback(mergeCallbacks(onIconClick, event => {
|
|
194
|
+
var _a; // open and set focus
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
state.setOpen(event, !state.open);
|
|
198
|
+
(_a = triggerRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
199
|
+
}));
|
|
200
|
+
|
|
201
|
+
if (state.expandIcon) {
|
|
202
|
+
state.expandIcon.onMouseDown = onExpandIconMouseDown;
|
|
203
|
+
state.expandIcon.onClick = onExpandIconClick;
|
|
204
|
+
}
|
|
205
|
+
|
|
68
206
|
return state;
|
|
69
207
|
};
|
|
70
208
|
//# 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,MAAM,oBAAoB,GAAG,CAAC,KAAD,EAAuB,GAAvB,KAA0E;EAC5G,MAAM,SAAS,GAAG,oBAAoB,CAAC,KAAD,CAAtC;EAEA,MAAM;IAAE,OAAO,EAAE,kBAA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,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,"sources":["components/Combobox/useCombobox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,kBAAkB,IAAI,eAA/B,QAAsD,uBAAtD;AACA,SACE,yBADF,EAEE,gBAFF,EAGE,cAHF,EAIE,gBAJF,EAKE,aALF,QAMO,2BANP;AAOA,SAAS,oBAAT,QAAqC,kCAArC;AACA,SAAS,sBAAT,QAAuC,oCAAvC;AACA,SAAS,gBAAT,QAAiC,8BAAjC;AACA,SAAS,OAAT,QAAwB,oBAAxB;AAMA;;;;;;;;AAQG;;AACH,OAAO,MAAM,oBAAoB,GAAG,CAAC,KAAD,EAAuB,GAAvB,KAA0E;;;EAC5G,MAAM,SAAS,GAAG,oBAAoB,CAAC,KAAD,CAAtC;EACA,MAAM;IACJ,YADI;IAEJ,cAFI;IAGJ,YAHI;IAIJ,uBAJI;IAKJ,QALI;IAMJ,IANI;IAOJ,YAPI;IAQJ,eARI;IASJ,eATI;IAUJ,eAVI;IAWJ,OAXI;IAYJ,QAZI;IAaJ;EAbI,IAcF,SAdJ;EAeA,MAAM;IAAE,QAAF;IAAY;EAAZ,IAA4B,KAAlC;EAEA,MAAM;IAAE,OAAO,EAAE,kBAAX;IAA+B,IAAI,EAAE;EAArC,IAAyD,yBAAyB,CAAC;IACvF,KADuF;IAEvF,kBAAkB,EAAE,OAFmE;IAGvF,iBAAiB,EAAE,CAAC,UAAD,EAAa,MAAb;EAHoE,CAAD,CAAxF;EAMA,MAAM,OAAO,GAAG,KAAK,CAAC,MAAN,CAA6B,IAA7B,CAAhB;EACA,MAAM,UAAU,GAAG,KAAK,CAAC,MAAN,CAA+B,IAA/B,CAAnB,CA1B4G,CA4B5G;;EACA,MAAM,CAA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,CACvE;;;IACA,KAAK,CAAC,OAAN,CAAc,KAAd,EAAqB,CAAC,KAAK,CAAC,IAA5B;IACA,CAAA,EAAA,GAAA,UAAU,CAAC,OAAX,MAAkB,IAAlB,IAAkB,EAAA,KAAA,KAAA,CAAlB,GAAkB,KAAA,CAAlB,GAAkB,EAAA,CAAE,KAAF,EAAlB;EACD,CAJa,CAD0B,CAA1C;;EAQA,IAAI,KAAK,CAAC,UAAV,EAAsB;IACpB,KAAK,CAAC,UAAN,CAAiB,WAAjB,GAA+B,qBAA/B;IACA,KAAK,CAAC,UAAN,CAAiB,OAAjB,GAA2B,iBAA3B;EACD;;EAED,OAAO,KAAP;AACD,CArMM","sourcesContent":["import * as React from 'react';\nimport { ChevronDownRegular as ChevronDownIcon } from '@fluentui/react-icons';\nimport {\n getPartitionedNativeProps,\n resolveShorthand,\n mergeCallbacks,\n useEventCallback,\n useMergedRefs,\n} 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 { 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);\n const {\n activeOption,\n clearSelection,\n getIndexOfId,\n getOptionsMatchingValue,\n hasFocus,\n open,\n selectOption,\n selectedOptions,\n setActiveOption,\n setFocusVisible,\n setOpen,\n setValue,\n value,\n } = baseState;\n const { freeform, multiselect } = props;\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 // calculate listbox width style based on trigger width\n const [popupWidth, setPopupWidth] = React.useState<string>();\n React.useEffect(() => {\n const width = open ? `${rootRef.current?.clientWidth}px` : undefined;\n setPopupWidth(width);\n }, [open]);\n\n // handle input type-to-select\n const getSearchString = (inputValue: string): string => {\n // if there are commas in the value string, take the text after the last comma\n const searchString = inputValue.split(',').pop();\n\n return searchString?.trim().toLowerCase() || '';\n };\n\n // set active option and selection based on typing\n const getOptionFromInput = (inputValue: string): OptionValue | undefined => {\n const searchString = getSearchString(inputValue);\n\n if (searchString.length === 0) {\n return;\n }\n\n const matcher = (optionValue: string) => optionValue.toLowerCase().indexOf(searchString) === 0;\n const matches = getOptionsMatchingValue(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 && getSearchString(value) === 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 (!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 // 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\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: { width: popupWidth },\n },\n })\n : undefined;\n\n [triggerSlot, listboxSlot] = useComboboxPopup(props, triggerSlot, listboxSlot);\n [triggerSlot, listboxSlot] = useTriggerListboxSlots(props, baseState, ref, triggerSlot, listboxSlot);\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 ...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 setOpen,\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 clicking the icon\n baseState.ignoreNextBlur.current = true;\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 );\n\n if (state.expandIcon) {\n state.expandIcon.onMouseDown = onExpandIconMouseDown;\n state.expandIcon.onClick = onExpandIconClick;\n }\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|