Skip to content

docs(select): add basic readme #2438

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 2 commits into from
Jan 5, 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
43 changes: 39 additions & 4 deletions src/lib/select/OVERVIEW.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
`<md-select>` is a form control for selecting a value from a set of options, similar to the native
`<select>` element.
`<select>` element. You can read more about selects in the
[Material Design spec](https://material.google.com/components/menus.html).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs to stay. This is what embeds the live example on the docs site.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oopsies

<!-- example(select-overview) -->

### Use with `@angular/forms`
`<md-select>` is compatible with `@angular/forms` and supports both `FormsModule`
and `ReactiveFormsModule`.
### Simple select

In your template, create an `md-select` element. For each option you'd like in your select, add an
`md-option` tag. Note that you can disable items by adding the `disabled` boolean attribute or
binding to it.

*my-comp.html*
```html
<md-select placeholder="State">
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}</md-option>
</md-select>
```

### Getting and setting the select value

The select component is set up as a custom value accessor, so you can manipulate the select's value using
any of the form directives from the core `FormsModule` or `ReactiveFormsModule`: `ngModel`, `formControl`, etc.

*my-comp.html*
```html
<md-select placeholder="State" [(ngModel)]="myState">
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}</md-option>
</md-select>
```

*my-comp.ts*
```ts
class MyComp {
myState = 'AZ';
states = [{code: 'AL', name: 'Alabama'}...];
}
```

#### Keyboard interaction:
- <kbd>DOWN_ARROW</kbd>: Focus next option
- <kbd>UP_ARROW</kbd>: Focus previous option
- <kbd>ENTER</kbd> or <kbd>SPACE</kbd>: Select focused item
69 changes: 67 additions & 2 deletions src/lib/select/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
## Work in progress!
# md-select

The select is still a work in progress, so most features have not been implemented. Not ready for use!
`<md-select>` is a form control for selecting a value from a set of options, similar to the native
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I plan on wiping out all of the README files soon (and just pointing to the docs site)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, submitted before we had that conversation. Want me to wipe now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't matter to me; might as well keep it before we wipe them all.

`<select>` element. You can read more about selects in the
[Material Design spec](https://material.google.com/components/menus.html).

### Not yet implemented

- Multi-select support
- Option groups
- Select headers

## Usage

### Simple select

In your template, create an `md-select` element. For each option you'd like in your select, add an
`md-option` tag. The value property of each option dictates the value that will be set in the select's
form control when that option is selected. What is between the `md-option` tags is what will be
visibly displayed in the list. Note that you can disable items by adding the `disabled` boolean
attribute or binding to it.

*my-comp.html*
```html
<md-select placeholder="State">
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}</md-option>
</md-select>
```

Output:

<img src="https://material.angularjs.org/material2_assets/select/basic-select-closed.png">
<img src="https://material.angularjs.org/material2_assets/select/basic-select-open.png">

### Getting and setting the select value

The select component is set up as a custom value accessor, so you can manipulate the select's value using
any of the form directives from the core `FormsModule` or `ReactiveFormsModule`: `ngModel`, `formControl`, etc.

*my-comp.html*
```html
<md-select placeholder="State" [(ngModel)]="myState">
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}</md-option>
</md-select>
```

*my-comp.ts*
```ts
class MyComp {
myState = 'AZ';
states = [{code: 'AL', name: 'Alabama'}...];
}
```

Output:

<img src="https://material.angularjs.org/material2_assets/select/value-select-closed.png">
<img src="https://material.angularjs.org/material2_assets/select/value-select-open.png">

### Accessibility

The select adds role="listbox" to the main select element and role="option" to each option. It also adds the "aria-owns", "aria-disabled",
"aria-label", "aria-required", and "aria-invalid" attributes as appropriate to the select.

#### Keyboard events:
- <kbd>DOWN_ARROW</kbd>: Focus next option
- <kbd>UP_ARROW</kbd>: Focus previous option
- <kbd>ENTER</kbd> or <kbd>SPACE</kbd>: Select focused item