Skip to content

Commit fb033c8

Browse files
committed
2 parents 43bc0ad + cd8e0b1 commit fb033c8

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

src/combobox/combobox.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import { NG_VALUE_ACCESSOR } from "@angular/forms";
6767
class="bx--text-input"
6868
aria-label="ListBox input field"
6969
autocomplete="off"
70-
placeholder="Filter..."/>
70+
[placeholder]="placeholder"/>
7171
<div
7272
[ngClass]="{'bx--list-box__menu-icon--open': open}"
7373
class="bx--list-box__menu-icon">
@@ -132,7 +132,7 @@ export class ComboBox implements OnChanges, OnInit, AfterViewInit, AfterContentI
132132
* Text to show when nothing is selected.
133133
* @memberof ComboBox
134134
*/
135-
@Input() placeholder = "";
135+
@Input() placeholder = "Filter...";
136136
/**
137137
* Combo box type (supporting single or multi selection of items).
138138
* @type {("single" | "multi")}
@@ -351,6 +351,9 @@ export class ComboBox implements OnChanges, OnInit, AfterViewInit, AfterContentI
351351
});
352352
this.view["updateList"](this.items);
353353
this.updatePills();
354+
// clearSelected can only fire on type=multi
355+
// so we just emit getSelected() (just in case there's any disabled but selected items)
356+
this.selected.emit(this.view.getSelected() as any);
354357
}
355358

356359
/**

src/combobox/combobox.stories.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ storiesOf("Combobox", module)
1616
.addDecorator(withKnobs)
1717
.add("Basic", () => ({
1818
template: `
19-
<ibm-combo-box [items]="items">
19+
<ibm-combo-box [items]="items" (selected)="selected($event)">
2020
<ibm-dropdown-list></ibm-dropdown-list>
2121
</ibm-combo-box>
2222
`,
@@ -40,7 +40,7 @@ storiesOf("Combobox", module)
4040
}))
4141
.add("Multi-select", () => ({
4242
template: `
43-
<ibm-combo-box [items]="items" type="multi">
43+
<ibm-combo-box [items]="items" type="multi" (selected)="selected($event)">
4444
<ibm-dropdown-list></ibm-dropdown-list>
4545
</ibm-combo-box>
4646
`,

src/table/table.component.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ import { getScrollbarWidth } from "../common/utils";
102102
*
103103
* See `TableHeaderItem` class for more information.
104104
*
105+
* ## No data template
106+
*
107+
* When table has no data to show, it can show a message you provide it instead.
108+
*
109+
* ```html
110+
* <ibm-table [model]="model">No data.</ibm-table>
111+
* ```
112+
*
113+
* ... will show `No data.` message, but you can get creative and provide any template you want
114+
* to replace table's default `tbody`.
115+
*
105116
* ## Use pagination as table footer
106117
*
107118
* ```html
@@ -195,9 +206,9 @@ import { getScrollbarWidth } from "../common/utils";
195206
<svg
196207
class="bx--table-sort-v2__icon"
197208
width="10" height="5" viewBox="0 0 10 5"
198-
aria-label="Sort rows by this header in descending order"
199-
alt="Sort rows by this header in descending order">
200-
<title>Sort rows by this header in descending order</title>
209+
[attr.aria-label]="(column.sorted && column.ascending ? sortDescendingLabel : sortAscendingLabel)"
210+
[attr.alt]="(column.sorted && column.ascending ? sortDescendingLabel : sortAscendingLabel)">
211+
<title>{{(column.sorted && column.ascending ? sortDescendingLabel : sortAscendingLabel)}}</title>
201212
<path d="M0 0l5 4.998L10 0z" fill-rule="evenodd" />
202213
</svg>
203214
</button>
@@ -269,6 +280,7 @@ import { getScrollbarWidth } from "../common/utils";
269280
</tr>
270281
</thead>
271282
<tbody
283+
*ngIf="!noData; else noDataTemplate"
272284
[ngStyle]="{'overflow-y': 'scroll'}"
273285
(scroll)="onScroll($event)">
274286
<ng-container *ngFor="let row of model.data; let i = index">
@@ -292,6 +304,7 @@ import { getScrollbarWidth } from "../common/utils";
292304
<button
293305
*ngIf="model.isRowExpandable(i)"
294306
(click)="model.expandRow(i, !model.rowsExpanded[i])"
307+
[attr.aria-label]="expandButtonAriaLabel"
295308
class="bx--table-expand-v2__button">
296309
<svg class="bx--table-expand-v2__svg" width="7" height="12" viewBox="0 0 7 12">
297310
<path fill-rule="nonzero" d="M5.569 5.994L0 .726.687 0l6.336 5.994-6.335 6.002L0 11.27z" />
@@ -331,6 +344,7 @@ import { getScrollbarWidth } from "../common/utils";
331344
</tr>
332345
</ng-container>
333346
</tbody>
347+
<ng-template #noDataTemplate><ng-content></ng-content></ng-template>
334348
<tfoot>
335349
<tr *ngIf="this.model.isLoading">
336350
<td class="table_loading-indicator">
@@ -440,6 +454,10 @@ export class Table {
440454
*/
441455
@Input() columnsDraggable = false;
442456

457+
@Input() expandButtonAriaLabel = "Expand row";
458+
@Input() sortDescendingLabel = "Sort rows by this header in descending order";
459+
@Input() sortAscendingLabel = "Sort rows by this header in ascending order";
460+
443461
/**
444462
* Controls if all checkboxes are viewed as selected.
445463
*
@@ -511,6 +529,12 @@ export class Table {
511529
*/
512530
@Output() scrollLoad = new EventEmitter<TableModel>();
513531

532+
get noData() {
533+
return !this.model.data ||
534+
this.model.data.length === 0 ||
535+
this.model.data.length === 1 && this.model.data[0].length === 0;
536+
}
537+
514538
private _model: TableModel;
515539

516540
private columnResizeWidth: number;

src/table/table.stories.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const en = require("./../../src/i18n/en.json");
4040
[showSelectionColumn]="showSelectionColumn"
4141
[striped]="striped"
4242
(sort)="simpleSort($event)">
43+
<ng-content></ng-content>
4344
</ibm-table>
4445
`
4546
})
@@ -429,6 +430,11 @@ simpleModel.header = [
429430
new TableHeaderItem({data: "Name"}), new TableHeaderItem({data: "hwer", style: {"width": "auto"} })
430431
];
431432

433+
const emptyModel = new TableModel();
434+
emptyModel.header = [
435+
new TableHeaderItem({data: "Name"}), new TableHeaderItem({data: "hwer", style: {"width": "auto"} })
436+
];
437+
432438
function sort(model, index: number) {
433439
if (model.header[index].sorted) {
434440
// if already sorted flip sorting direction
@@ -475,6 +481,30 @@ storiesOf("Table", module).addDecorator(
475481
sortable: boolean("sortable", true)
476482
}
477483
}))
484+
.add("with no data", () => ({
485+
template: `
486+
<app-table
487+
[model]="model"
488+
[size]="size"
489+
[showSelectionColumn]="showSelectionColumn"
490+
[striped]="striped">
491+
<tbody><tr><td class="no-data" colspan="3"><div>No data.</div></td></tr></tbody>
492+
</app-table>
493+
`,
494+
styles: [`
495+
.no-data {
496+
width: 100%;
497+
height: 150px;
498+
text-align: center;
499+
}
500+
`],
501+
props: {
502+
model: emptyModel,
503+
size: selectV2("size", {Small: "sm", Normal: "md", Large: "lg"}, "md", "table-size-selection"),
504+
showSelectionColumn: boolean("showSelectionColumn", true),
505+
striped: boolean("striped", true)
506+
}
507+
}))
478508
.add("with expansion", () => ({
479509
template: `
480510
<app-expansion-table

0 commit comments

Comments
 (0)