-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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). | ||
|
||
<!-- 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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, submitted before we had that conversation. Want me to wipe now? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oopsies