Skip to content

Commit c05738f

Browse files
feat(spinner): Add inline spinner for combobox (#3134)
* feat(spinner): Add inline spinner for combobox * feat(spinner): Add inline spinner for combobox * feat(spinner): Update documentation
1 parent 46d5eba commit c05738f

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

ui/components/combobox/docs.mdx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,45 @@ To toggle visibility of the `listbox`, add the class `slds-is-open` to the `slds
114114
- Every `option` has `aria-selected="false"` by default
115115
- Disabled `option`s should have `aria-disabled="true"` applied
116116

117+
#### Loading more options
118+
119+
If you are dynamically loading in more items to the listbox, the very last `<li>` of the `<ul>` should receive the `role="presentation"` attribute and have the [Spinner component](/components/spinners/) injected into it.
120+
121+
For layout purposes, wrap the spinner in a `<div>` with the class `slds-align_absolute-center` to position the spinner in the middle of the list item, as well as `slds-p-top_medium` to provide the appropiate amount of space for the spinner to be visible.
122+
123+
<Example title="Combobox - Loading Options">
124+
<CodeView style={{maxWidth: '40rem', height: '15rem'}}>
125+
<Combobox
126+
id={_.uniqueId('combobox-id-')}
127+
aria-controls="listbox-id-222"
128+
readonly
129+
value="Accounts"
130+
inputIconPosition="right"
131+
rightInputIcon={
132+
<UtilityIcon
133+
symbol="down"
134+
className="slds-icon slds-icon_x-small slds-icon-text-default"
135+
containerClassName="slds-input__icon slds-input__icon_right"
136+
assistiveText={false}
137+
title={false}
138+
/>
139+
}
140+
listbox={
141+
<Listbox
142+
id="listbox-id-222"
143+
snapshot={Snapshot.ObjectOptions}
144+
type="plain"
145+
count={3}
146+
visualSelection
147+
loading
148+
/>
149+
}
150+
isOpen
151+
hasFocus
152+
/>
153+
</CodeView>
154+
</Example>
155+
117156
### Grouped options
118157

119158
Options within a `listbox` can be grouped together under meaningful headings. This is useful if you wish to create separation between 2 or more sets of options within a single `listbox`.

ui/components/combobox/listbox/index.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import classNames from 'classnames';
77
import SvgIcon from '../../../shared/svg-icon';
88
import { StandardIcon } from '../../icons/standard/example';
99
import { UtilityIcon } from '../../icons/base/example';
10-
10+
import { Spinner } from '../../spinners/base/example';
1111
/**
1212
* Listbox
1313
*/
@@ -295,6 +295,7 @@ class Listbox extends Component {
295295
term,
296296
type,
297297
snapshot,
298+
loading,
298299
count = 1,
299300
className = 'slds-dropdown_fluid'
300301
} = this.props;
@@ -319,6 +320,13 @@ class Listbox extends Component {
319320
: Object.keys(snapshot)
320321
.slice(0, count)
321322
.map(this.renderPlainOptions)}
323+
{loading && (
324+
<ListboxItem>
325+
<div className="slds-align_absolute-center slds-p-top_medium">
326+
<Spinner className="slds-spinner_x-small slds-spinner_inline" />
327+
</div>
328+
</ListboxItem>
329+
)}
322330
</ListboxList>
323331
</ListboxWrapper>
324332
);

ui/components/spinners/base/_index.scss

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@
4343
transform: translate(-50%, -50%) rotate(90deg);
4444
}
4545

46+
.slds-spinner_inline {
47+
position: relative;
48+
top: auto;
49+
left: auto;
50+
right: auto;
51+
bottom: auto;
52+
transform: none;
53+
}
54+
4655
.slds-spinner,
4756
.slds-spinner__dot-a,
4857
.slds-spinner__dot-b {
@@ -210,6 +219,10 @@
210219
.slds-spinner--xx-small {
211220
width: 0.5rem;
212221

222+
&.slds-spinner_inline {
223+
height: 0.5rem;
224+
}
225+
213226
&.slds-spinner:before,
214227
&.slds-spinner:after,
215228
.slds-spinner__dot-a:before,
@@ -284,6 +297,10 @@
284297
.slds-spinner--x-small {
285298
width: 1rem;
286299

300+
&.slds-spinner_inline {
301+
height: 1rem;
302+
}
303+
287304
&.slds-spinner:before,
288305
&.slds-spinner:after,
289306
.slds-spinner__dot-a:before,
@@ -358,6 +375,10 @@
358375
.slds-spinner--small {
359376
width: 1.25rem;
360377

378+
&.slds-spinner_inline {
379+
height: 1.25rem;
380+
}
381+
361382
&.slds-spinner:before,
362383
&.slds-spinner:after,
363384
.slds-spinner__dot-a:before,
@@ -432,6 +453,10 @@
432453
.slds-spinner--medium {
433454
width: 2rem;
434455

456+
&.slds-spinner_inline {
457+
height: 2rem;
458+
}
459+
435460
&.slds-spinner:before,
436461
&.slds-spinner:after,
437462
.slds-spinner__dot-a:before,
@@ -506,6 +531,10 @@
506531
.slds-spinner--large {
507532
width: 2.75rem;
508533

534+
&.slds-spinner_inline {
535+
height: 2.75rem;
536+
}
537+
509538
&.slds-spinner:before,
510539
&.slds-spinner:after,
511540
.slds-spinner__dot-a:before,

ui/components/spinners/base/example.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ export default (
4242
);
4343

4444
export let examples = [
45+
{
46+
id: 'inlined',
47+
label: 'Inlined',
48+
description:
49+
'A container is not required to use the spinner. Here, it is placed on a dark background to illustrate there is nothing there. The spinner will position itself to the closest positioned parent. So if you want it to spin over a single component, the class <code>.slds-is-relative</code> can be added to the parent.',
50+
element: (
51+
<div className="slds-align_absolute-center" style={{ height: '4rem' }}>
52+
<Spinner className="slds-spinner_medium slds-spinner_inline" />
53+
</div>
54+
)
55+
},
4556
{
4657
id: 'without-container',
4758
label: 'Without Container',

0 commit comments

Comments
 (0)