Skip to content

Commit 3d4af71

Browse files
author
Ayesha Mazumdar
authored
feat(combobox): Add example to show listbox options with right icon and/or metatext, options with drill in (#3091)
1 parent 9407709 commit 3d4af71

File tree

6 files changed

+280
-4
lines changed

6 files changed

+280
-4
lines changed

ui/components/combobox/__tests__/__snapshots__/render_combobox_renders_different_styles_of_options_in_the_listbox.json

Lines changed: 63 additions & 0 deletions
Large diffs are not rendered by default.

ui/components/combobox/__tests__/__snapshots__/render_combobox_renders_different_styles_of_options_in_the_listbox_with_drill_in.json

Lines changed: 52 additions & 0 deletions
Large diffs are not rendered by default.

ui/components/combobox/__tests__/index.spec.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,66 @@ describe('render combobox', () => {
585585
hasFocus
586586
/>
587587
));
588+
it('renders different styles of options in the listbox', () =>
589+
matchesMarkupAndStyle(
590+
<Combobox
591+
id={comboboxId}
592+
aria-controls={listboxId}
593+
readonly
594+
value="Accounts"
595+
inputIconPosition="right"
596+
rightInputIcon={
597+
<UtilityIcon
598+
symbol="down"
599+
className="slds-icon slds-icon_x-small slds-icon-text-default"
600+
containerClassName="slds-input__icon slds-input__icon_right"
601+
assistiveText={false}
602+
title={false}
603+
/>
604+
}
605+
listbox={
606+
<Listbox
607+
id={listboxId}
608+
snapshot={Snapshot.PlainStylingOptions}
609+
type="entity"
610+
count={4}
611+
visualSelection
612+
/>
613+
}
614+
isOpen
615+
hasFocus
616+
/>
617+
));
618+
it('renders different styles of options in the listbox with drill in', () =>
619+
matchesMarkupAndStyle(
620+
<Combobox
621+
id={comboboxId}
622+
aria-controls={listboxId}
623+
readonly
624+
value="Accounts"
625+
inputIconPosition="right"
626+
rightInputIcon={
627+
<UtilityIcon
628+
symbol="down"
629+
className="slds-icon slds-icon_x-small slds-icon-text-default"
630+
containerClassName="slds-input__icon slds-input__icon_right"
631+
assistiveText={false}
632+
title={false}
633+
/>
634+
}
635+
listbox={
636+
<Listbox
637+
id={listboxId}
638+
snapshot={Snapshot.EntityStylingOptions}
639+
type="entity"
640+
count={3}
641+
visualSelection
642+
/>
643+
}
644+
isOpen
645+
hasFocus
646+
/>
647+
));
588648
it('renders autocomplete combobox', () =>
589649
matchesMarkupAndStyle(
590650
<Combobox

ui/components/combobox/docs.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,22 @@ Options within a `listbox` can be grouped together under meaningful headings. Th
160160
- The `ul` element in this case has `role="group"` with an `aria-label` that matches the visible label
161161
- Display the group label visually, but due to the way a `listbox` works it can only be marked as `role="presentation"`, as a `listbox` can only have `option` children. This allows us to communicate the group label visually and programmatically to a screen reader
162162

163+
### Styling choices for options
164+
165+
The options in the `listbox` can have a left icon and/or metatext.
166+
167+
<Example title="Combobox - Styling Options">
168+
<CodeView style={{position: 'relative', maxWidth: '20rem', height: '12rem'}}>
169+
<Listbox
170+
id="listbox-id-2"
171+
snapshot={Snapshot.PlainStylingOptions}
172+
type="plain"
173+
count={4}
174+
visualSelection
175+
/>
176+
</CodeView>
177+
</Example>
178+
163179
### Handling focus
164180

165181
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.
@@ -495,6 +511,22 @@ Whilst typing, the highlighted option in the `listbox` should be the user's text
495511

496512
</Example>
497513

514+
### Drill In for Autocomplete
515+
516+
The options in the autocomplete `listbox` can have a right icon to indicate an option that drills in for more options.
517+
518+
<Example title="Combobox - Autocomplete DrillIn Styling">
519+
<CodeView style={{position: 'relative', maxWidth: '20rem', height: '10rem'}}>
520+
<Listbox
521+
id="listbox-id-3"
522+
snapshot={Snapshot.EntityStylingOptions}
523+
type="entity"
524+
count={3}
525+
visualSelection
526+
/>
527+
</CodeView>
528+
</Example>
529+
498530
### Keyboard interaction
499531

500532
The same keyboard interactions apply from the base Combobox, but with these differences:

ui/components/combobox/listbox/index.jsx

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,15 @@ const EntityOption = props => (
127127
)}
128128
</span>
129129
)}
130+
{props.rightIcon && (
131+
<UtilityIcon
132+
className="slds-icon_x-small slds-icon-text-default"
133+
containerClassName="slds-align-middle"
134+
symbol={props.rightIcon.toLowerCase()}
135+
title={props.rightIconAssistiveText}
136+
assistiveText={props.rightIconAssistiveText}
137+
/>
138+
)}
130139
</ListboxOption>
131140
);
132141

@@ -176,12 +185,22 @@ export const Option = props => (
176185
props.className
177186
)}
178187
>
179-
{!props.label && (
188+
{!props.label &&
189+
!props.rightIcon && (
190+
<span className="slds-media__figure">
191+
<SvgIcon
192+
className="slds-icon slds-icon_x-small slds-listbox__icon-selected"
193+
sprite="utility"
194+
symbol="check"
195+
/>
196+
</span>
197+
)}
198+
{props.rightIcon && (
180199
<span className="slds-media__figure">
181200
<SvgIcon
182-
className="slds-icon slds-icon_x-small slds-listbox__icon-selected"
201+
className="slds-icon slds-icon_x-small slds-icon-text-default"
183202
sprite="utility"
184-
symbol="check"
203+
symbol={props.rightIcon}
185204
/>
186205
</span>
187206
)}
@@ -192,7 +211,9 @@ export const Option = props => (
192211
) : (
193212
<span className="slds-media__body">
194213
<span
195-
className="slds-truncate"
214+
className={classNames('slds-truncate', {
215+
'slds-m-bottom_xxx-small': props.plainMeta
216+
})}
196217
title={
197218
props.term
198219
? `${props.beforeTerm}${props.term}${props.afterTerm}`
@@ -212,6 +233,11 @@ export const Option = props => (
212233
props.name
213234
)}
214235
</span>
236+
{props.plainMeta && (
237+
<span className="slds-listbox__option-meta slds-listbox__option-meta_entity">
238+
{props.plainMeta}
239+
</span>
240+
)}
215241
</span>
216242
)}
217243
</ListboxOption>
@@ -240,6 +266,8 @@ class Listbox extends Component {
240266
term={option.term}
241267
beforeTerm={option.beforeTerm}
242268
afterTerm={option.afterTerm}
269+
rightIcon={option.rightIcon}
270+
rightIconAssistiveText={option.rightIconAssistiveText}
243271
/>
244272
</ListboxItem>
245273
);
@@ -259,6 +287,8 @@ class Listbox extends Component {
259287
term={option.term}
260288
beforeTerm={option.beforeTerm}
261289
afterTerm={option.afterTerm}
290+
plainMeta={option.plainMeta}
291+
rightIcon={option.rightIcon}
262292
/>
263293
</ListboxItem>
264294
);
@@ -322,6 +352,7 @@ export class ListboxGroup extends Component {
322352
entityLocation={option.entityLocation}
323353
term={option.term}
324354
label={option.label}
355+
rightIcon={option.rightIcon}
325356
/>
326357
</ListboxItem>
327358
);

ui/components/combobox/snapshots.data.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,41 @@ export const PlainOptionsTypeahead = {
396396
afterTerm: 'ortunity Pipeline'
397397
}
398398
};
399+
400+
export const PlainStylingOptions = {
401+
option1: {
402+
name: 'Edge Communications'
403+
},
404+
option2: {
405+
name: 'Alexandria Textiles Corp of America',
406+
rightIcon: 'anchor'
407+
},
408+
option3: {
409+
name: 'Express Logistics and Transport',
410+
plainMeta: 'Durham, NC'
411+
},
412+
option4: {
413+
name: 'Alexandria Textiles Corp of America',
414+
plainMeta: 'Alexandria, VA',
415+
rightIcon: 'anchor'
416+
}
417+
};
418+
419+
export const EntityStylingOptions = {
420+
option1: {
421+
name: 'Edge Communications'
422+
},
423+
option2: {
424+
name: 'Express Logistics and Transport',
425+
entityMeta: true,
426+
entityLocation: 'Durham, NC'
427+
},
428+
option3: {
429+
name: 'Alexandria Textiles Corp of America',
430+
entityMeta: true,
431+
entityType: 'Account',
432+
entityLocation: 'Alexandria, VA',
433+
rightIcon: 'chevronright',
434+
rightIconAssistiveText: 'Has further options'
435+
}
436+
};

0 commit comments

Comments
 (0)