Skip to content

docs(list): add example and missing JsDoc for selection-list #6899

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/lib/list/list.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ element in an `<md-list-item>`.
</md-nav-list>
```

### Selection lists
A selection list provides an interface for selecting values, where each list item is an option.

<!-- example(list-selection) -->

The options within a selection-list should not contain further interactive controls, such
as buttons and anchors.


### Multi-line lists
For lists that require multiple lines per item, annotate each line with an `mdLine` attribute.
Whichever heading tag is appropriate for your DOM hierarchy should be used (not necessarily `<h3>`
Expand Down
3 changes: 3 additions & 0 deletions src/lib/list/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class MdListItemBase {}
export const _MdListItemMixinBase = mixinDisableRipple(MdListItemBase);


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

/** A Material Design list component. */
@Component({
moduleId: module.id,
selector: 'md-list, mat-list, md-nav-list, mat-nav-list',
Expand Down Expand Up @@ -114,6 +116,7 @@ export class MdListIconCssMatStyler {}
})
export class MdListSubheaderCssMatStyler {}

/** An item within a Material Design list. */
@Component({
moduleId: module.id,
selector: 'md-list-item, mat-list-item, a[md-list-item], a[mat-list-item]',
Expand Down
21 changes: 13 additions & 8 deletions src/lib/list/selection-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ import {CanDisableRipple, mixinDisableRipple} from '../core/common-behaviors/dis
import {MATERIAL_COMPATIBILITY_MODE} from '../core/compatibility/compatibility';


/** @docs-private */
export class MdSelectionListBase {}
export const _MdSelectionListMixinBase = mixinDisableRipple(mixinDisabled(MdSelectionListBase));

/** @docs-private */
export class MdListOptionBase {}
export const _MdListOptionMixinBase = mixinDisableRipple(MdListOptionBase);


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

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

/** Whether the option is selected. */
@Input()
get selected() { return this._selected; }
set selected( val: boolean) { this._selected = coerceBooleanProperty(val); }
Expand Down Expand Up @@ -135,6 +139,7 @@ export class MdListOption extends _MdListOptionMixinBase
this.destroyed.emit({option: this});
}

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


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

/** options which are selected. */
/** The currently selected options. */
selectedOptions: SelectionModel<MdListOption> = new SelectionModel<MdListOption>(true);

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

/** Focus the selection-list. */
focus() {
this._element.nativeElement.focus();
}

/**
* Map all the options' destroy event subscriptions and merge them into one stream.
*/
/** Map all the options' destroy event subscriptions and merge them into one stream. */
private _onDestroySubscription(): Subscription {
return RxChain.from(this.options.changes)
.call(startWith, this.options)
Expand All @@ -257,9 +264,7 @@ export class MdSelectionList extends _MdSelectionListMixinBase
});
}

/**
* Map all the options' onFocus event subscriptions and merge them into one stream.
*/
/** Map all the options' onFocus event subscriptions and merge them into one stream. */
private _onFocusSubscription(): Subscription {
return RxChain.from(this.options.changes)
.call(startWith, this.options)
Expand Down
8 changes: 8 additions & 0 deletions src/material-examples/example-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {InputOverviewExample} from './input-overview/input-overview-example';
import {InputPrefixSuffixExample} from './input-prefix-suffix/input-prefix-suffix-example';
import {ListOverviewExample} from './list-overview/list-overview-example';
import {ListSectionsExample} from './list-sections/list-sections-example';
import {ListSelectionExample} from './list-selection/list-selection-example';
import {MenuIconsExample} from './menu-icons/menu-icons-example';
import {MenuOverviewExample} from './menu-overview/menu-overview-example';
import {PaginatorConfigurableExample} from './paginator-configurable/paginator-configurable-example';
Expand Down Expand Up @@ -323,6 +324,12 @@ export const EXAMPLE_COMPONENTS = {
additionalFiles: null,
selectorName: null
},
'list-selection': {
title: 'List with selection',
component: ListSelectionExample,
additionalFiles: null,
selectorName: null
},
'menu-icons': {
title: 'Menu with icons',
component: MenuIconsExample,
Expand Down Expand Up @@ -575,6 +582,7 @@ export const EXAMPLE_LIST = [
InputPrefixSuffixExample,
ListOverviewExample,
ListSectionsExample,
ListSelectionExample,
MenuIconsExample,
MenuOverviewExample,
PaginatorConfigurableExample,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** No styles for this example. */
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<md-selection-list #shoes>
<md-list-option *ngFor="let shoe of typesOfShoes">
{{shoe}}
</md-list-option>
</md-selection-list>

<p>
Options selected: {{shoes.selectedOptions.selected.length}}
</p>
13 changes: 13 additions & 0 deletions src/material-examples/list-selection/list-selection-example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Component} from '@angular/core';

/**
* @title List with selection
*/
@Component({
selector: 'list-selection-example',
styleUrls: ['list-selection-example.css'],
templateUrl: 'list-selection-example.html',
})
export class ListSelectionExample {
typesOfShoes = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers'];
}