Skip to content

Commit 04bde0c

Browse files
authored
docs(combobox): Update interaction documentation (#3194)
* docs(combobox): Update interaction documentation
1 parent b6df0b0 commit 04bde0c

File tree

1 file changed

+88
-19
lines changed

1 file changed

+88
-19
lines changed

ui/components/combobox/docs.mdx

Lines changed: 88 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ A Base Combobox is a readonly text `input` that allows a user to select an optio
6161

6262
### Displaying options
6363

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-
6664
To toggle visibility of the `listbox`, add the class `slds-is-open` to the `slds-dropdown-trigger` element.
6765

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.
67+
6868
<Blockquote type="a11y" header="Accessibility Requirement">
6969
When toggling visibility of the Combobox, the <code className="doc">aria-expanded</code> attribute needs to be toggled to <code className="doc">true</code>. Set it to <code className="doc">false</code> again when the options are hidden.
7070
</Blockquote>
@@ -214,17 +214,87 @@ The options in the `listbox` can have a left icon and/or metatext.
214214
</CodeView>
215215
</Example>
216216

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.
218220

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
220222

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.
224+
225+
<Example title="Combobox - Handling focus">
226+
227+
<CodeView style={{maxWidth: '40rem', height: '15rem'}}>
228+
<Combobox
229+
id={_.uniqueId('combobox-id-')}
230+
aria-controls="listbox-id-4"
231+
readonly
232+
inputIconPosition="right"
233+
rightInputIcon={
234+
<UtilityIcon
235+
symbol="down"
236+
className="slds-icon slds-icon_x-small slds-icon-text-default"
237+
containerClassName="slds-input__icon slds-input__icon_right"
238+
assistiveText={false}
239+
title={false}
240+
/>
241+
}
242+
listbox={<Listbox id="listbox-id-4" snapshot={Snapshot.ObjectOptions} type="plain" count={8} visualSelection />}
243+
isOpen
244+
hasFocus
245+
/>
246+
</CodeView>
247+
248+
</Example>
249+
250+
If using a keyboard, placing focus into the Combobox input field _will not_ display the `listbox` of options automatically.
251+
252+
<Example title="Combobox - Handling focus with a keyboard">
253+
254+
<CodeView style={{maxWidth: '40rem', height: '5rem'}}>
255+
<Combobox
256+
id={_.uniqueId('combobox-id-')}
257+
aria-controls="listbox-id-4"
258+
readonly
259+
inputIconPosition="right"
260+
rightInputIcon={
261+
<UtilityIcon
262+
symbol="down"
263+
className="slds-icon slds-icon_x-small slds-icon-text-default"
264+
containerClassName="slds-input__icon slds-input__icon_right"
265+
assistiveText={false}
266+
title={false}
267+
/>
268+
}
269+
listbox={<Listbox id="listbox-id-4" snapshot={Snapshot.ObjectOptionsFocused} type="plain" count={8} visualSelection />}
270+
hasFocus
271+
/>
272+
</CodeView>
273+
274+
</Example>
275+
276+
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.
277+
278+
<Blockquote type="a11y" header="Accessibility Requirement">
279+
Update <code className="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`.
222290

223291
<Blockquote type="a11y" header="Accessibility Requirement">
224292
When highlighting an option with "faux focus", the <code className="doc">aria-activedescendant</code> attribute on the <code className="doc">input</code> needs to be set to the value of the ID of the highlighted option. The highlighted option must also have <code className="doc">aria-selected="true"</code>. When no option is highlighted, <code className="doc">aria-activedescendant</code> must be removed.
225293
</Blockquote>
226294

227-
<Example title="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+
<Example title="Combobox - Highlighting an option">
228298

229299
<CodeView style={{maxWidth: '40rem', height: '15rem'}}>
230300
<Combobox
@@ -250,18 +320,15 @@ When an option from the `listbox` is "in focus", user focus never leaves the `in
250320

251321
</Example>
252322

253-
### Keyboard interaction
323+
#### Collapsing the Combobox
254324

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.
256326

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.
328+
329+
<Blockquote type="a11y" header="Accessibility Requirement">
330+
Update <code className="doc">aria-expanded</code> to "false" when the Combobox is collapsed.
331+
</Blockquote>
265332

266333
### Selecting an option
267334

@@ -483,7 +550,7 @@ If no option matches, the user can complete the value of the combobox by finishi
483550

484551
### Displaying options
485552

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.
487554

488555
When a user stops interacting with the Combobox, or selects an option, the Combobox collapses and hides the options.
489556

@@ -1027,7 +1094,7 @@ The containing `div` of the comboboxes should have the class `slds-combobox-grou
10271094

10281095
When a user is not focused on any element inside of the combobox group, the pill container should become collapsed to reduce vertical space.
10291096

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.
10311098

10321099
#### Collapsed
10331100

@@ -1064,7 +1131,7 @@ By default, the `slds-listbox_selection-group` is collapsed.
10641131

10651132
#### Expanded
10661133

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.
10681135

10691136
<Example title="Combobox - Grouped - Expanded pills">
10701137

@@ -1096,6 +1163,8 @@ When a user focuses on _any_ element inside of the combobox group, the class `sl
10961163

10971164
</Example>
10981165

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+
10991168
### Scoping results
11001169

11011170
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

Comments
 (0)