Skip to content

Commit c6841d6

Browse files
authored
Merge branch 'master' into loading-inactive
2 parents f819a15 + c175059 commit c6841d6

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

.storybook/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ addDecorator(
2727
);
2828

2929
// load global styles
30-
require("!style-loader!css-loader!sass-loader!./preview.scss");
31-
require("!style-loader!css-loader!sass-loader!./preview-experimental.scss");
30+
require("!style-loader!css-loader!postcss-loader!sass-loader!./preview.scss");
31+
require("!style-loader!css-loader!postcss-loader!sass-loader!./preview-experimental.scss");
3232

3333
require("../src/index.stories");
3434
// automatically import all files ending in *.stories.ts

src/content-switcher/content-switcher-option.directive.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {
1111
selector: "[ibmContentOption]"
1212
})
1313
export class ContentSwitcherOption {
14+
/**
15+
* Used to activate the option. Only one option may be `active` at a time
16+
*/
1417
@Input() set active (value: boolean) {
1518
this._active = value;
1619
this.selectedClass = value;
@@ -22,8 +25,16 @@ export class ContentSwitcherOption {
2225
return this._active;
2326
}
2427

28+
/**
29+
* Internal name for the option.
30+
* Should be something that identifies the option to the application.
31+
* Accessible from the `ContentSwitcher` `selected` emitter
32+
*/
2533
@Input() name = "option";
2634

35+
/**
36+
* Emits when the option is selected.
37+
*/
2738
@Output() selected = new EventEmitter();
2839

2940
@HostBinding("class") switcherClass = "bx--content-switcher-btn";

src/content-switcher/content-switcher.component.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ import { ContentSwitcherOption } from "./content-switcher-option.directive";
1313
import { isFocusInLastItem, isFocusInFirstItem } from "./../common/tab.service";
1414

1515
/**
16+
* The content switcher can be used for toggling between distinct options.
17+
* Similar to tabs, but without an associated content panel
1618
*
17-
*
19+
* ```html
20+
* <ibm-content-switcher (selected)="selected($event)">
21+
* <button ibmContentOption>First section</button>
22+
* <button ibmContentOption>Second section</button>
23+
* <button ibmContentOption>Third section</button>
24+
* </ibm-content-switcher>
25+
* ```
1826
*/
1927
@Component({
2028
selector: "ibm-content-switcher",
@@ -28,16 +36,27 @@ import { isFocusInLastItem, isFocusInFirstItem } from "./../common/tab.service";
2836
`
2937
})
3038
export class ContentSwitcher implements AfterViewInit {
39+
/**
40+
* aria-label for the content switcher. Should be set to something descriptive
41+
*/
3142
@Input() label = "content switcher";
3243

44+
/**
45+
* Emits the activated `ContentSwitcherOption`
46+
*/
3347
@Output() selected = new EventEmitter();
3448

3549
@ContentChildren(ContentSwitcherOption) options: QueryList<ContentSwitcherOption>;
3650

3751
constructor(protected elementRef: ElementRef) {}
3852

3953
ngAfterViewInit() {
40-
this.options.first.active = true;
54+
const firstActive = this.options.find(option => option.active);
55+
// delay setting active until the DOM has settled
56+
if (!firstActive) {
57+
setTimeout(() => this.options.first.active = true);
58+
}
59+
// subscribe to each item, emit when one is selected, and reset the active states
4160
this.options.forEach(option => {
4261
option.selected.subscribe(_ => {
4362
const active = option;
@@ -53,7 +72,7 @@ export class ContentSwitcher implements AfterViewInit {
5372

5473
@HostListener("keydown", ["$event"])
5574
hostkeys(event: KeyboardEvent) {
56-
const buttonList = Array.from<any>(this.elementRef.nativeElement.querySelectorAll(".bx--content-switcher-btn"));
75+
const buttonList = Array.from<any>(this.elementRef.nativeElement.querySelectorAll("[ibmContentOption]"));
5776

5877
switch (event.key) {
5978
case "Right": // IE specific value

src/dropdown/list/dropdown-list.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export class DropdownList implements AbstractDropdownView, AfterViewInit, OnDest
212212
this.index = this._items.findIndex(item => item.selected);
213213
this.setupFocusObservable();
214214
setTimeout(() => {
215+
if (!this.getSelected()) { return; }
215216
if (this.type === "single") {
216217
this.select.emit({ item: this._items.find(item => item.selected) });
217218
} else {

src/pagination/pagination.component.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { ExperimentalService } from "./../experimental.module";
2323
*
2424
* ```typescript
2525
* selectPage(page) {
26-
* // ... your code to laod the page goes here
26+
* // ... your code to load the page goes here
2727
*
2828
* this.model.currentPage = page;
2929
*
@@ -279,7 +279,6 @@ export class Pagination {
279279
* `PaginationModel` with the information about pages you're controlling.
280280
*
281281
* @type {Model}
282-
* @memberof Pagination
283282
*/
284283
@Input() model: PaginationModel;
285284

@@ -327,32 +326,28 @@ export class Pagination {
327326
*
328327
* You should tie into this and update `model.currentPage` once the fresh
329328
* data is finally loaded.
330-
*
331-
* @memberof Pagination
332329
*/
333330
@Output() selectPage = new EventEmitter<number>();
334331

335332
get itemsPerPage() {
336333
return this.model.pageLength;
337334
}
338335
set itemsPerPage(value) {
339-
this.model.pageLength = value;
336+
this.model.pageLength = Number(value);
340337
this.currentPage = 1; // reset page
341338
}
342339

343340
get currentPage() {
344341
return this.model.currentPage;
345342
}
346343
set currentPage(value) {
344+
value = Number(value);
347345
// emits the value to allow the user to update current page
348346
// in the model once the page is loaded
349347
this.selectPage.emit(value);
350348
}
351349
/**
352350
* The last page number to display in the pagination view.
353-
*
354-
* @returns {number}
355-
* @memberof Pagination
356351
*/
357352
get lastPage(): number {
358353
const last = Math.ceil(this.model.totalDataLength / this.model.pageLength);
@@ -371,19 +366,13 @@ export class Pagination {
371366

372367
/**
373368
* The previous page number to navigate to, from the current page.
374-
*
375-
* @returns {number}
376-
* @memberof Pagination
377369
*/
378370
get previousPage(): number {
379371
return this.currentPage <= 1 ? 1 : this.currentPage - 1;
380372
}
381373

382374
/**
383375
* The next page number to navigate to, from the current page.
384-
*
385-
* @returns {number}
386-
* @memberof Pagination
387376
*/
388377
get nextPage(): number {
389378
const lastPage = this.lastPage;
@@ -412,12 +401,7 @@ export class Pagination {
412401
/**
413402
* Generates a list of numbers. (Python function)
414403
* Used to display the correct pagination controls.
415-
*
416-
* @param {number} stop
417-
* @param {number} [start=0]
418-
* @param {number} [step=1]
419404
* @returns {array}
420-
* @memberof Pagination
421405
*/
422406
range(stop: number, start = 0, step = 1) {
423407
return range(stop, start, step);

0 commit comments

Comments
 (0)