Skip to content

Commit ab20ffd

Browse files
jelbourntinayuangao
authored andcommitted
docs(list): add example and missing JsDoc for selection-list (#6899)
1 parent dd37acf commit ab20ffd

File tree

7 files changed

+56
-8
lines changed

7 files changed

+56
-8
lines changed

src/lib/list/list.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ element in an `<md-list-item>`.
4242
</md-nav-list>
4343
```
4444

45+
### Selection lists
46+
A selection list provides an interface for selecting values, where each list item is an option.
47+
48+
<!-- example(list-selection) -->
49+
50+
The options within a selection-list should not contain further interactive controls, such
51+
as buttons and anchors.
52+
53+
4554
### Multi-line lists
4655
For lists that require multiple lines per item, annotate each line with an `mdLine` attribute.
4756
Whichever heading tag is appropriate for your DOM hierarchy should be used (not necessarily `<h3>`

src/lib/list/list.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class MdListItemBase {}
3333
export const _MdListItemMixinBase = mixinDisableRipple(MdListItemBase);
3434

3535

36+
/** Divider between items within a list. */
3637
@Directive({
3738
selector: 'md-divider, mat-divider',
3839
host: {
@@ -42,6 +43,7 @@ export const _MdListItemMixinBase = mixinDisableRipple(MdListItemBase);
4243
})
4344
export class MdListDivider {}
4445

46+
/** A Material Design list component. */
4547
@Component({
4648
moduleId: module.id,
4749
selector: 'md-list, mat-list, md-nav-list, mat-nav-list',
@@ -114,6 +116,7 @@ export class MdListIconCssMatStyler {}
114116
})
115117
export class MdListSubheaderCssMatStyler {}
116118

119+
/** An item within a Material Design list. */
117120
@Component({
118121
moduleId: module.id,
119122
selector: 'md-list-item, mat-list-item, a[md-list-item], a[mat-list-item]',

src/lib/list/selection-list.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ import {CanDisableRipple, mixinDisableRipple} from '../core/common-behaviors/dis
3636
import {MATERIAL_COMPATIBILITY_MODE} from '../core/compatibility/compatibility';
3737

3838

39+
/** @docs-private */
3940
export class MdSelectionListBase {}
4041
export const _MdSelectionListMixinBase = mixinDisableRipple(mixinDisabled(MdSelectionListBase));
4142

43+
/** @docs-private */
4244
export class MdListOptionBase {}
4345
export const _MdListOptionMixinBase = mixinDisableRipple(MdListOptionBase);
4446

45-
47+
/** Event emitted by a selection-list whenever the state of an option is changed. */
4648
export interface MdSelectionListOptionEvent {
4749
option: MdListOption;
4850
}
@@ -95,10 +97,12 @@ export class MdListOption extends _MdListOptionMixinBase
9597
get disabled() { return (this.selectionList && this.selectionList.disabled) || this._disabled; }
9698
set disabled(value: any) { this._disabled = coerceBooleanProperty(value); }
9799

100+
/** Value of the option */
98101
@Input()
99102
get value() { return this._value; }
100103
set value( val: any) { this._value = coerceBooleanProperty(val); }
101104

105+
/** Whether the option is selected. */
102106
@Input()
103107
get selected() { return this._selected; }
104108
set selected( val: boolean) { this._selected = coerceBooleanProperty(val); }
@@ -135,6 +139,7 @@ export class MdListOption extends _MdListOptionMixinBase
135139
this.destroyed.emit({option: this});
136140
}
137141

142+
/** Toggles the selection state of the option. */
138143
toggle(): void {
139144
this.selected = !this.selected;
140145
this.selectionList.selectedOptions.toggle(this);
@@ -174,6 +179,9 @@ export class MdListOption extends _MdListOptionMixinBase
174179
}
175180

176181

182+
/**
183+
* Material Design list component where each item is a selectable option. Behaves as a listbox.
184+
*/
177185
@Component({
178186
moduleId: module.id,
179187
selector: 'md-selection-list, mat-selection-list',
@@ -208,7 +216,7 @@ export class MdSelectionList extends _MdSelectionListMixinBase
208216
/** The option components contained within this selection-list. */
209217
@ContentChildren(MdListOption) options: QueryList<MdListOption>;
210218

211-
/** options which are selected. */
219+
/** The currently selected options. */
212220
selectedOptions: SelectionModel<MdListOption> = new SelectionModel<MdListOption>(true);
213221

214222
constructor(private _element: ElementRef) {
@@ -231,13 +239,12 @@ export class MdSelectionList extends _MdSelectionListMixinBase
231239
this._optionFocusSubscription.unsubscribe();
232240
}
233241

242+
/** Focus the selection-list. */
234243
focus() {
235244
this._element.nativeElement.focus();
236245
}
237246

238-
/**
239-
* Map all the options' destroy event subscriptions and merge them into one stream.
240-
*/
247+
/** Map all the options' destroy event subscriptions and merge them into one stream. */
241248
private _onDestroySubscription(): Subscription {
242249
return RxChain.from(this.options.changes)
243250
.call(startWith, this.options)
@@ -257,9 +264,7 @@ export class MdSelectionList extends _MdSelectionListMixinBase
257264
});
258265
}
259266

260-
/**
261-
* Map all the options' onFocus event subscriptions and merge them into one stream.
262-
*/
267+
/** Map all the options' onFocus event subscriptions and merge them into one stream. */
263268
private _onFocusSubscription(): Subscription {
264269
return RxChain.from(this.options.changes)
265270
.call(startWith, this.options)

src/material-examples/example-module.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {InputOverviewExample} from './input-overview/input-overview-example';
5252
import {InputPrefixSuffixExample} from './input-prefix-suffix/input-prefix-suffix-example';
5353
import {ListOverviewExample} from './list-overview/list-overview-example';
5454
import {ListSectionsExample} from './list-sections/list-sections-example';
55+
import {ListSelectionExample} from './list-selection/list-selection-example';
5556
import {MenuIconsExample} from './menu-icons/menu-icons-example';
5657
import {MenuOverviewExample} from './menu-overview/menu-overview-example';
5758
import {PaginatorConfigurableExample} from './paginator-configurable/paginator-configurable-example';
@@ -323,6 +324,12 @@ export const EXAMPLE_COMPONENTS = {
323324
additionalFiles: null,
324325
selectorName: null
325326
},
327+
'list-selection': {
328+
title: 'List with selection',
329+
component: ListSelectionExample,
330+
additionalFiles: null,
331+
selectorName: null
332+
},
326333
'menu-icons': {
327334
title: 'Menu with icons',
328335
component: MenuIconsExample,
@@ -580,6 +587,7 @@ export const EXAMPLE_LIST = [
580587
InputPrefixSuffixExample,
581588
ListOverviewExample,
582589
ListSectionsExample,
590+
ListSelectionExample,
583591
MenuIconsExample,
584592
MenuOverviewExample,
585593
PaginatorConfigurableExample,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/** No styles for this example. */
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<md-selection-list #shoes>
2+
<md-list-option *ngFor="let shoe of typesOfShoes">
3+
{{shoe}}
4+
</md-list-option>
5+
</md-selection-list>
6+
7+
<p>
8+
Options selected: {{shoes.selectedOptions.selected.length}}
9+
</p>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Component} from '@angular/core';
2+
3+
/**
4+
* @title List with selection
5+
*/
6+
@Component({
7+
selector: 'list-selection-example',
8+
styleUrls: ['list-selection-example.css'],
9+
templateUrl: 'list-selection-example.html',
10+
})
11+
export class ListSelectionExample {
12+
typesOfShoes = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers'];
13+
}

0 commit comments

Comments
 (0)