Skip to content

Commit ce0477a

Browse files
authored
Merge pull request #342 from youda97/skeleton-dropdown
feat(dropdown): Add skeleton state
2 parents 5c2fec5 + 4c4b692 commit ce0477a

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/dropdown/dropdown.component.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ import { I18n } from "./../i18n/i18n.module";
2929
selector: "ibm-dropdown",
3030
template: `
3131
<div
32-
class="bx--list-box"
33-
[ngClass]="{'bx--dropdown--light': theme === 'light'}">
32+
class="bx--list-box bx--dropdown-v2"
33+
[ngClass]="{
34+
'bx--dropdown--light': theme === 'light',
35+
'bx--list-box--inline': inline,
36+
'bx--skeleton': skeleton
37+
}">
3438
<button
3539
type="button"
3640
#dropdownButton
@@ -42,7 +46,7 @@ import { I18n } from "./../i18n/i18n.module";
4246
(blur)="onBlur()"
4347
[disabled]="disabled">
4448
<span class="bx--list-box__label">{{getDisplayValue() | async}}</span>
45-
<div class="bx--list-box__menu-icon" [ngClass]="{'bx--list-box__menu-icon--open': !menuIsClosed }">
49+
<div *ngIf="!skeleton" class="bx--list-box__menu-icon" [ngClass]="{'bx--list-box__menu-icon--open': !menuIsClosed }">
4650
<svg fill-rule="evenodd" height="5" role="img" viewBox="0 0 10 5" width="10" alt="Open menu" [attr.aria-label]="menuButtonLabel">
4751
<title>{{menuButtonLabel}}</title>
4852
<path d="M0 0l5 4.998L10 0z"></path>
@@ -93,6 +97,14 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
9397
* Set to `true` to disable the dropdown.
9498
*/
9599
@Input() disabled = false;
100+
/**
101+
* Set to `true` for a loading dropdown.
102+
*/
103+
@Input() skeleton = false;
104+
/**
105+
* Set to `true` for an inline dropdown.
106+
*/
107+
@Input() inline = false;
96108
/**
97109
* Deprecated. Dropdown now defaults to appending inline
98110
* Set to `true` if the `Dropdown` is to be appended to the DOM body.
@@ -198,13 +210,18 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
198210
* The `type` property specifies whether the `Dropdown` allows single selection or multi selection.
199211
*/
200212
ngOnInit() {
201-
this.view.type = this.type;
213+
if (this.view) {
214+
this.view.type = this.type;
215+
}
202216
}
203217

204218
/**
205219
* Initializes classes and subscribes to events for single or multi selection.
206220
*/
207221
ngAfterContentInit() {
222+
if (!this.view) {
223+
return;
224+
}
208225
this.view.type = this.type;
209226
this.view.size = this.size;
210227
this.view.select.subscribe(event => {
@@ -323,6 +340,9 @@ export class Dropdown implements OnInit, AfterContentInit, OnDestroy {
323340
* Returns the display value if there is no selection, otherwise the selection will be returned.
324341
*/
325342
getDisplayValue(): Observable<string> {
343+
if (!this.view) {
344+
return;
345+
}
326346
let selected = this.view.getSelected();
327347
if (selected && !this.displayValue) {
328348
if (this.type === "multi") {

src/dropdown/dropdown.stories.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,25 @@ storiesOf("Dropdown", module)
8787
],
8888
model: null
8989
}
90+
}))
91+
.add("Skeleton", () => ({
92+
template: `
93+
<div style="width: 300px">
94+
<ibm-dropdown skeleton="true">
95+
<ibm-dropdown-list [items]="items"></ibm-dropdown-list>
96+
</ibm-dropdown>
97+
&nbsp;
98+
<ibm-dropdown skeleton="true" inline="true">
99+
<ibm-dropdown-list [items]="items"></ibm-dropdown-list>
100+
</ibm-dropdown>
101+
</div>
102+
`,
103+
props: {
104+
items: [
105+
{ content: "one" },
106+
{ content: "two" },
107+
{ content: "three" },
108+
{ content: "four" }
109+
]
110+
}
90111
}));

0 commit comments

Comments
 (0)