Skip to content

Commit fc6fc25

Browse files
authored
docs(select): add basic readme (#2438)
Closes #2148
1 parent 8c0eef2 commit fc6fc25

File tree

2 files changed

+106
-6
lines changed

2 files changed

+106
-6
lines changed

src/lib/select/OVERVIEW.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
11
`<md-select>` is a form control for selecting a value from a set of options, similar to the native
2-
`<select>` element.
2+
`<select>` element. You can read more about selects in the
3+
[Material Design spec](https://material.google.com/components/menus.html).
34

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

6-
### Use with `@angular/forms`
7-
`<md-select>` is compatible with `@angular/forms` and supports both `FormsModule`
8-
and `ReactiveFormsModule`.
7+
### Simple select
8+
9+
In your template, create an `md-select` element. For each option you'd like in your select, add an
10+
`md-option` tag. Note that you can disable items by adding the `disabled` boolean attribute or
11+
binding to it.
12+
13+
*my-comp.html*
14+
```html
15+
<md-select placeholder="State">
16+
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}</md-option>
17+
</md-select>
18+
```
19+
20+
### Getting and setting the select value
21+
22+
The select component is set up as a custom value accessor, so you can manipulate the select's value using
23+
any of the form directives from the core `FormsModule` or `ReactiveFormsModule`: `ngModel`, `formControl`, etc.
24+
25+
*my-comp.html*
26+
```html
27+
<md-select placeholder="State" [(ngModel)]="myState">
28+
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}</md-option>
29+
</md-select>
30+
```
31+
32+
*my-comp.ts*
33+
```ts
34+
class MyComp {
35+
myState = 'AZ';
36+
states = [{code: 'AL', name: 'Alabama'}...];
37+
}
38+
```
39+
40+
#### Keyboard interaction:
41+
- <kbd>DOWN_ARROW</kbd>: Focus next option
42+
- <kbd>UP_ARROW</kbd>: Focus previous option
43+
- <kbd>ENTER</kbd> or <kbd>SPACE</kbd>: Select focused item

src/lib/select/README.md

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,68 @@
1-
## Work in progress!
1+
# md-select
22

3-
The select is still a work in progress, so most features have not been implemented. Not ready for use!
3+
`<md-select>` is a form control for selecting a value from a set of options, similar to the native
4+
`<select>` element. You can read more about selects in the
5+
[Material Design spec](https://material.google.com/components/menus.html).
6+
7+
### Not yet implemented
8+
9+
- Multi-select support
10+
- Option groups
11+
- Select headers
12+
13+
## Usage
14+
15+
### Simple select
16+
17+
In your template, create an `md-select` element. For each option you'd like in your select, add an
18+
`md-option` tag. The value property of each option dictates the value that will be set in the select's
19+
form control when that option is selected. What is between the `md-option` tags is what will be
20+
visibly displayed in the list. Note that you can disable items by adding the `disabled` boolean
21+
attribute or binding to it.
22+
23+
*my-comp.html*
24+
```html
25+
<md-select placeholder="State">
26+
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}</md-option>
27+
</md-select>
28+
```
29+
30+
Output:
31+
32+
<img src="https://material.angularjs.org/material2_assets/select/basic-select-closed.png">
33+
<img src="https://material.angularjs.org/material2_assets/select/basic-select-open.png">
34+
35+
### Getting and setting the select value
36+
37+
The select component is set up as a custom value accessor, so you can manipulate the select's value using
38+
any of the form directives from the core `FormsModule` or `ReactiveFormsModule`: `ngModel`, `formControl`, etc.
39+
40+
*my-comp.html*
41+
```html
42+
<md-select placeholder="State" [(ngModel)]="myState">
43+
<md-option *ngFor="let state of states" [value]="state.code">{{ state.name }}</md-option>
44+
</md-select>
45+
```
46+
47+
*my-comp.ts*
48+
```ts
49+
class MyComp {
50+
myState = 'AZ';
51+
states = [{code: 'AL', name: 'Alabama'}...];
52+
}
53+
```
54+
55+
Output:
56+
57+
<img src="https://material.angularjs.org/material2_assets/select/value-select-closed.png">
58+
<img src="https://material.angularjs.org/material2_assets/select/value-select-open.png">
59+
60+
### Accessibility
61+
62+
The select adds role="listbox" to the main select element and role="option" to each option. It also adds the "aria-owns", "aria-disabled",
63+
"aria-label", "aria-required", and "aria-invalid" attributes as appropriate to the select.
64+
65+
#### Keyboard events:
66+
- <kbd>DOWN_ARROW</kbd>: Focus next option
67+
- <kbd>UP_ARROW</kbd>: Focus previous option
68+
- <kbd>ENTER</kbd> or <kbd>SPACE</kbd>: Select focused item

0 commit comments

Comments
 (0)