-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs(input, select): update docs and create more examples #7673
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
Conversation
84c55ba
to
b110cdd
Compare
Validators.email, | ||
]); | ||
|
||
matcher = new MyErrorStateMatcher(); |
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.
In my experience, the custom matchers are very practical for showing errors when a parent FormGroup is invalid. As in,
- Password/confirm must be equal
end
date must be afterbegin
date.
This requires either checking control.parent.valid
or using a class property in the method. Maybe consider expanding the example? Or I'd be happy to give it a shot in a followup.
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.
Yeah that sounds like a good thing to add. I'd like to keep this example around too since it's a little less complex and we don't have to worry about also making a custom validator
src/lib/select/select.md
Outdated
using any of the form directives from the core `FormsModule` or `ReactiveFormsModule`: `ngModel`, | ||
`formControl`, etc. As with native `<select>`, `<mat-select>` also supports a `compareWith` | ||
function. (Additional information about using a custom `compareWith` function can be found in the | ||
[angular forms documentation](https://angular.io/api/forms/SelectControlValueAccessor#caveat-option-selection)). |
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.
Capitalize 'Angular'?
either the user has interacted with (touched) the element or the parent form has been submitted. If | ||
you wish to override this behavior (e.g. to show the error as soon as the invalid control is dirty | ||
or when a parent form group is invalid), you can use the `errorStateMatcher` property of the | ||
`matInput`. The property takes an instance of an `ErrorStateMatcher` object. An `ErrorStateMatcher` |
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.
I think the more common use-case for customizing the ErrorStateMatcher
is overriding the global one, rather than doing it per-control. Maybe we should have an example for that case as well?
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.
Unfortunately our examples aren't that flexible atm. We don't get to mess with the module. That's why I left an inline code snippet showing how to do it globally.
src/lib/select/select.md
Outdated
`mat-option` tag. Note that you can disable items by adding the `disabled` boolean attribute or | ||
binding to it. | ||
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`, |
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.
The select also supports setting the value via the value
input which doesn't require forms.
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.
done and added example
|
||
### Changing when error messages are shown | ||
|
||
The `<mat-form-field>` allows you to |
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.
A few of these sections are going to be the same between the select and input. Maybe we should consider (not necessarily now) having a common page for them?
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.
Yes, I'd also like to consolidate the code itself so we're not duplicating it in input and select, just need to find a good way to make it work with change detection
src/lib/select/select.ts
Outdated
@@ -461,6 +464,12 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit, | |||
} | |||
} | |||
|
|||
ngOnChanges(changes: SimpleChanges) { | |||
if (changes.disabled) { |
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.
Did these changes make it through as a part of another branch?
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 was fixing a bug I noticed when making one of the demos
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.
Add a comment here?
</mat-select> | ||
<mat-hint>Errors appear instantly!</mat-hint> | ||
<mat-error *ngIf="selected.hasError('required')">You must make a selection</mat-error> | ||
<mat-error *ngIf="selected.hasError('pattern') && !selected.hasError('required')"> |
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.
I'm not sure how common of a use case it is to have pattern validation on a select since the developer provides the possible values beforehand.
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.
Yeah its not the most practical example, but I just wanted to show a couple different error states
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.
Mostly missing CSS links and comma nits. (We should either remove the file itself or add the link to it in the TS)
/** @title Select with reset option */ | ||
@Component({ | ||
selector: 'select-reset-example', | ||
templateUrl: 'select-reset-example.html', |
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.
Missing the link to the example CSS file.
/** @title Select with option groups */ | ||
@Component({ | ||
selector: 'select-optgroup-example', | ||
templateUrl: 'select-optgroup-example.html', |
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.
Missing link to CSS file
/** @title Select with cno option ripple */ | ||
@Component({ | ||
selector: 'select-no-ripple-example', | ||
templateUrl: 'select-no-ripple-example.html', |
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.
Link to CSS file
@@ -0,0 +1,8 @@ | |||
import {Component} from '@angular/core'; | |||
|
|||
/** @title Select with cno option ripple */ |
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.
Typo: cno -> no
/** @title Select with multiple selection */ | ||
@Component({ | ||
selector: 'select-multiple-example', | ||
templateUrl: 'select-multiple-example.html', |
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.
Missing CSS link here
src/lib/select/select.md
Outdated
|
||
This error occurs if you attempt to assign something other than a function to the `compareWith` | ||
property. For more information on proper usage of `compareWith` see the | ||
[angular forms documentation](https://angular.io/api/forms/SelectControlValueAccessor#caveat-option-selection)). |
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.
Nit: angular -> Angular
src/lib/select/select.md
Outdated
|
||
Global default placeholder options can be specified by setting the `MAT_PLACEHOLDER_GLOBAL_OPTIONS` provider. This setting will apply to all components that support the floating placeholder. | ||
By default when a user clicks on a `<mat-option>` a ripple animation is shown. This can be disabled |
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.
By default, when a user clicks on a mat-option, a ripple animation is shown.
src/lib/select/select.md
Outdated
|
||
### Selecting multiple options | ||
|
||
By default the `<mat-select>` only supports selecting a single option at a time. However you can use |
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.
By default, the mat-select
src/lib/select/select.md
Outdated
|
||
### Selecting multiple options | ||
|
||
By default the `<mat-select>` only supports selecting a single option at a time. However you can use |
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.
However, you can use
/** @title Select with 2-way value binding */ | ||
@Component({ | ||
selector: 'select-value-binding-example', | ||
templateUrl: 'select-value-binding-example.html', |
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.
Missing link to the CSS file.
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.
LGTM
comments addressed. @kara we can't remove the empty CSS files because the example generator will barf. I added the links to the no-op files though |
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.
Looked at the
the `MatFormFieldControl` interface, see its | ||
[definition](https://github.com/angular/material2/blob/master/src/lib/form-field/form-field-control.ts). | ||
the `MatFormFieldControl` interface, see the | ||
[form field API documentation](https://material.angular.io/components/form-field/api). | ||
(Unfortunately generated API docs are not available yet, but we'll go through the methods and | ||
properties in this guide.) |
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.
Remove the Unfortunately...
bit? I'd rather just get into the content than draw attention to it.
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.
Actually meant to delete this since it's not true anymore
|
||
<!-- example(input-prefix-suffix) --> | ||
The `<mat-form-field>` allows you to |
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.
Should this be moved to the mat-form-field
docs?
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.
Ideally yes, in the future once the functionality is extracted into the form field, but currently this is up to the individual FormFieldControl
to add support for custom error state matchers (and the attribute goes on the <input>
not the <mat-form-field>
).
src/lib/select/select.md
Outdated
In your template, create an `mat-select` element. For each option you'd like in your select, add an | ||
`mat-option` tag. Note that you can disable items by adding the `disabled` boolean attribute or | ||
binding to it. | ||
The select component is set up as a custom value accessor, so you can manipulate the select's value |
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.
"is set up as..." -> "supports all directives from @angular/forms
"?
src/lib/select/select.md
Outdated
|
||
### Getting and setting the select value | ||
`<mat-select>` also supports 2-way binding to the `value` property without the need for Angular |
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.
Swap the order of using value
and forms?
be specified either via a `placeholder` attribute on the `<mat-select>` or a `<mat-placeholder>` | ||
element in the same form field as the `<mat-select>`. The `<mat-form-field>` also has additional | ||
options for changing the behavior of the placeholder. For more information see the | ||
[form field placeholder documentation](https://material.angular.io/components/form-field/overview#floating-placeholder). |
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.
Could this section be folded into the "Form field features" section?
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.
I'd like to keep it here too since placeholder
is an attribute that you place on the <mat-select>
(in the future when we split the placeholder and label into separate concepts it can be completely handled by the form field).
src/lib/select/select.md
Outdated
|
||
### Selecting multiple options | ||
|
||
By default, the `<mat-select>` only supports selecting a single option at a time. However, you can |
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.
"By default, the <mat-select>
only supports selecting a single option at a time. "
->
"<mat-select>
defaults to single-selection mode, but can be configured..."
|
||
#### Error: Cannot change `multiple` mode of select after initialization | ||
|
||
This error is thrown if you attempt to bind the `multiple` property on `<mat-select>` to a dynamic |
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.
Why can't we change this at run-time?
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.
I put that in place when I initially implemented multiple selection. It's there because there's some ambiguity about what to do with the selected values when you're switching modes. Also it's unlikely that you'll need to toggle it after init anyway (we haven't had any issues about it yet).
src/lib/select/select.md
Outdated
</mat-select> | ||
``` | ||
|
||
#### Error: Cannot assign truthy non-array value to select in `multiple` mode |
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.
Rename this error "Value must be an array in multiple-selection mode" ?
src/lib/select/select.md
Outdated
a `<mat-select multiple>`. For example, something like `mySelect.value = 'option1'`. What you likely | ||
meant to do was `mySelect.value = ['option1']`. | ||
|
||
#### Error: Cannot assign a non-function value to `compareWith` |
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.
Rename this error "compareWith
must be a function"?
src/lib/select/select.ts
Outdated
@@ -461,6 +464,12 @@ export class MatSelect extends _MatSelectMixinBase implements AfterContentInit, | |||
} | |||
} | |||
|
|||
ngOnChanges(changes: SimpleChanges) { | |||
if (changes.disabled) { |
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.
Add a comment here?
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.
comments addressed
|
||
<!-- example(input-prefix-suffix) --> | ||
The `<mat-form-field>` allows you to |
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.
Ideally yes, in the future once the functionality is extracted into the form field, but currently this is up to the individual FormFieldControl
to add support for custom error state matchers (and the attribute goes on the <input>
not the <mat-form-field>
).
be specified either via a `placeholder` attribute on the `<mat-select>` or a `<mat-placeholder>` | ||
element in the same form field as the `<mat-select>`. The `<mat-form-field>` also has additional | ||
options for changing the behavior of the placeholder. For more information see the | ||
[form field placeholder documentation](https://material.angular.io/components/form-field/overview#floating-placeholder). |
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.
I'd like to keep it here too since placeholder
is an attribute that you place on the <mat-select>
(in the future when we split the placeholder and label into separate concepts it can be completely handled by the form field).
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.
LGTM
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
No description provided.