You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ui/components/combobox/docs.mdx
+88-19Lines changed: 88 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,10 +61,10 @@ A Base Combobox is a readonly text `input` that allows a user to select an optio
61
61
62
62
### Displaying options
63
63
64
-
To display the `listbox` of options in a Combobox, it is most common that the user will click and place their focus inside the text `input` and the options will display instantly. Optionally, you can choose to not display the `listbox` immediately and wait for user input by means of typing a letter or pressing the down arrow key in the `input` field, before displaying the options.
65
-
66
64
To toggle visibility of the `listbox`, add the class `slds-is-open` to the `slds-dropdown-trigger` element.
67
65
66
+
It is most common to expand the `listbox` of options when a user clicks on the Combobox. For a more detailed description of interaction behaviors, see the [Interaction](#Interaction) section.
When toggling visibility of the Combobox, the <codeclassName="doc">aria-expanded</code> attribute needs to be toggled to <codeclassName="doc">true</code>. Set it to <codeclassName="doc">false</code> again when the options are hidden.
70
70
</Blockquote>
@@ -214,17 +214,87 @@ The options in the `listbox` can have a left icon and/or metatext.
214
214
</CodeView>
215
215
</Example>
216
216
217
-
### Handling focus
217
+
### Interaction
218
+
219
+
At its most basic, the `listbox` of options should be displayed when a user interacts with the Combobox. When the user leaves the combobox the options are hidden. However, there are some differences when interacting with a Combobox with a mouse versus with a keyboard.
218
220
219
-
When a combobox is clicked or focused, it is common for the options to be displayed at the same time. When you leave the combobox it is also common that the options are hidden.
221
+
#### Expanding the Combobox
220
222
221
-
When an option from the `listbox` is "in focus", user focus never leaves the `input` field, we manually create a programmatic or "faux focus" state that highlights the selected option and associates it to the `input`.
223
+
A mouse or pointer device user can click on a Combobox and the `listbox` will display automatically whilst focus is placed inside the Combobox input field.
After focusing inside the Combobox with the keyboard, pressing the `Down` or `Enter` key will expand the collapsed Combobox and display the `listbox` options. Be sure to update `aria-expanded` to be true. This will also highlight the first option in the listbox.
Update <codeclassName="doc">aria-expanded</code> to "true" when the Combobox is expanded.
280
+
</Blockquote>
281
+
282
+
#### Highlighting an option
283
+
284
+
To Highlight an option in the `Listbox` use the `Up` and `Down` arrow keys to cycle through all the available options in the list.
285
+
286
+
- Each press of the arrow key **must** update the `input` value to reflect the currently selected option
287
+
- It is common to loop the selected option to the first option when you get to the last option in the list. Similarly, loop to the last option when you reach the first option.
288
+
289
+
When an option from the `listbox` is "in focus", user focus never leaves the `input` field, since we manually create a programmatic or "faux focus" state that highlights the selected option and associates it to the `input`.
When highlighting an option with "faux focus", the <codeclassName="doc">aria-activedescendant</code> attribute on the <codeclassName="doc">input</code> needs to be set to the value of the ID of the highlighted option. The highlighted option must also have <codeclassName="doc">aria-selected="true"</code>. When no option is highlighted, <codeclassName="doc">aria-activedescendant</code> must be removed.
225
293
</Blockquote>
226
294
227
-
<Exampletitle="Combobox - Handling focus">
295
+
By typing the first letter of an option name, the first matching option will highlight. When the letter doesn't match an option, highlighting doesn't move.
296
+
297
+
<Exampletitle="Combobox - Highlighting an option">
@@ -250,18 +320,15 @@ When an option from the `listbox` is "in focus", user focus never leaves the `in
250
320
251
321
</Example>
252
322
253
-
###Keyboard interaction
323
+
#### Collapsing the Combobox
254
324
255
-
To use a combobox with your keyboard, you must first place focus inside the `input`. From here:
325
+
To collapse the Combobox the user should be able to press the `Escape` key on their keyboard or click anywhere outside of the Combobox.
256
326
257
-
- If the Combobox is collapsed, use the `down` arrow key to expand it, updating `aria-expanded` to `true`
258
-
- Use the `Escape` key to collapse the Combobox, updating `aria-expanded` to `false`
259
-
- Use `up` or `down` arrow keys to cycle through the options, updating `aria-activedescendant` and setting `aria-selected="true"` on the next option with each key press
260
-
- Each press of the arrow key **must** update the `input` value to reflect the currently selected option
261
-
- It is common to loop the selected option to the first option when you get to the last option in the list. Similarly, loop to the last option when you reach to the first option.
262
-
- By typing the first letter of an option name, the first matching option will highlight, updating `aria-activedescendant` and setting `aria-selected="true"` on the option
263
-
- When the letter doesn't match an option, highlighting don't move
264
-
-`Enter` will select the highlighted option
327
+
Pressing the `Enter` key whilst an option is highlighted will select the option as the current value and collapse the Combobox.
Update <codeclassName="doc">aria-expanded</code> to "false" when the Combobox is collapsed.
331
+
</Blockquote>
265
332
266
333
### Selecting an option
267
334
@@ -483,7 +550,7 @@ If no option matches, the user can complete the value of the combobox by finishi
483
550
484
551
### Displaying options
485
552
486
-
Displaying options happens just like a base Combobox, by placing user focus inside the Combobox text `input`.
553
+
Displaying options for the Autocomplete Combobox happens just like the base Combobox, except there is no difference between mouse and keyboard users when interacting with the Combobox for the first time. Clicking or placing focus on the Combobox text `input` will automatically expand the Combobox and display the options.
487
554
488
555
When a user stops interacting with the Combobox, or selects an option, the Combobox collapses and hides the options.
489
556
@@ -1027,7 +1094,7 @@ The containing `div` of the comboboxes should have the class `slds-combobox-grou
1027
1094
1028
1095
When a user is not focused on any element inside of the combobox group, the pill container should become collapsed to reduce vertical space.
1029
1096
1030
-
The combobox group element needs the class `slds-has-selection` when a selection has been made. The pill selections are found inside of another[Listbox of Pills](/components/pills?variant=listbox-of-pill-options) located after the combobox group. It requires the class `slds-listbox_selection-group` to provide appropriate styling for the expanding and collapsing behavior of this region.
1097
+
The combobox group element needs the class `slds-has-selection` when a selection has been made. The pill selections are found inside of a[Listbox of Pills](/components/pills?variant=listbox-of-pill-options) located after the combobox group. It requires the class `slds-listbox_selection-group` to provide appropriate styling for the expanding and collapsing behavior of this region.
1031
1098
1032
1099
#### Collapsed
1033
1100
@@ -1064,7 +1131,7 @@ By default, the `slds-listbox_selection-group` is collapsed.
1064
1131
1065
1132
#### Expanded
1066
1133
1067
-
When a user focuses on _any_ element inside of the combobox group, the class `slds-is-expanded` should be applied to the `slds-listbox_selection-group`. The selection group should remain opened until the user removes focus from the combobox group.
1134
+
When a user focuses on _any_ element inside of the combobox group, the class `slds-is-expanded` should be applied to the `slds-listbox_selection-group`. The selection group should remain open until the user moves away from any element inside the combobox group.
@@ -1096,6 +1163,8 @@ When a user focuses on _any_ element inside of the combobox group, the class `sl
1096
1163
1097
1164
</Example>
1098
1165
1166
+
For mouse users, clicking on the "+{x} more" text would expand the selection group and place the user's focus on the first pill inside the Listbox of Pills.
1167
+
1099
1168
### Scoping results
1100
1169
1101
1170
A grouped combobox is intended to be used to filter down or scope you search results. You can do so by interacting with the object switcher to scope down to an object type.
0 commit comments