-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs(form-field): add docs, examples, and guide #7424
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
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 comma nits
@@ -0,0 +1,337 @@ | |||
It is possible to create custom form field controls that can be used inside `<mat-form-field>`. This | |||
can be useful if you need to create a components that shares a lot of common behavior with a form |
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 components -> a component
can be useful if you need to create a components that shares a lot of common behavior with a form | ||
field, but adds some additional logic. | ||
|
||
In order to learn how to build custom form field controls, lets start with a simple input component |
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.
lets -> let's
font: inherit; | ||
text-align: center; | ||
} | ||
</style> |
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.
Q: why style tags instead of using the styles property?
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.
for the sake of cramming it all into 1 markdown box. do you think it would be better to do 2 boxes?
```css
...
```
```ts
...
```
} | ||
``` | ||
|
||
### Providing our component as an MatFormFieldControl |
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.
an -> a
|
||
### Providing our component as an MatFormFieldControl | ||
The first step is to provide our new component as an implementation of the `MatFormFieldControl` | ||
interface that the `<mat-form-field>` knows how to work with. To do this we will have our class |
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.
To do this we -> To do this, we
``` | ||
|
||
#### `empty` | ||
This property indicates whether the form field control is empty. For our control we'll consider 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.
For our control we'll -> For our control, we'll
#### `shouldPlaceholderFloat` | ||
This property is used to indicate whether the placeholder should be in the floating position. We'll | ||
use the same logic as `matInput` and float the placeholder when the input is focused or non-empty. | ||
Since the placeholder will be overlapping our control when when its not floating, we should hide the |
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.
its not floating -> it's not floating
This property is used to indicate whether the placeholder should be in the floating position. We'll | ||
use the same logic as `matInput` and float the placeholder when the input is focused or non-empty. | ||
Since the placeholder will be overlapping our control when when its not floating, we should hide the | ||
`–` characters when its not floating. |
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.
its not floating -> it's not floating
|
||
#### `errorState` | ||
This property indicates whether the associated `NgControl` is in an error state. Since we're not | ||
using an `NgControl` in this example we don't need to do anything other than just set it to `false`. |
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 this example we -> in this example, we
|
||
### Trying it out | ||
Now that we've fully implemented the interface, we're ready to try our component out! All we need to | ||
do is place it inside of a `<mat-form-filed>` |
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.
mat-form-filed -> mat-form-field
comments addressed |
already has a value property, we don't need to do anything for this one. | ||
|
||
#### `stateChanges` | ||
Because the `<mat-form-field>` used the `OnPush` change detection strategy, we need to let it know |
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.
used -> uses?
|
||
set value(tel: MyTel | null) { | ||
... | ||
stateChanges.next(); |
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.stateChanges.next()
} | ||
|
||
ngOnDestory() { | ||
stateChanges.destroy(); |
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.
ngOnDestory -> ngOnDestroy
this.stateChanges.complete()
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.
Thanks for catching these!
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.
@mmalerba As far as I'm aware, there is no destroy
method on Subject. Should it not be complete?
2912f4a
to
39fbfd9
Compare
<!-- | ||
TODO(mmalerba): Link to Plunker/StackBlitz with complete example code after beta 12. | ||
(Beta 11 is missing some of the features used in the example). | ||
--> |
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.
We can embed live examples in guides too, so it doesn't have to be an external link.
src/lib/form-field/form-field.md
Outdated
<!-- example(form-field-overview) --> | ||
|
||
### Floating placeholder | ||
The floating placeholder is an indicative text label displayed on top of the form field control when |
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.
Omit "indicative"?
src/lib/form-field/form-field.md
Outdated
the control does not contain any text. By default, when text is present the floating placeholder | ||
floats above the form field control. | ||
|
||
The placeholder text can be specified using the `placeholder` property on the form field control, or |
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 placeholder text" -> "Placeholder text" ?
src/lib/form-field/form-field.md
Outdated
has interacted with the element or the parent form has been submitted. Since the errors occupy the | ||
same space as the hints, the hints are hidden when the errors are shown. | ||
|
||
If an form field can have more than one error state, it is up to the consumer to toggle which |
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.
an form field
-> a form field
src/lib/form-field/form-field.md
Outdated
<!-- example(form-field-error) --> | ||
|
||
### Prefix & suffix | ||
HTML can be included before and after the input tag, as a prefix or suffix. It will be underlined |
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.
HTML
-> Custom content
?
src/lib/form-field/form-field.md
Outdated
<!-- example(form-field-error) --> | ||
|
||
### Prefix & suffix | ||
HTML can be included before and after the input tag, as a prefix or suffix. It will be underlined |
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.
It will be underlined...
-> It will be included within the visual container that wraps the form control
.
Since the new style inputs are more than just the underline style
src/lib/form-field/form-field.md
Outdated
|
||
### Theming | ||
`<mat-form-field>` has a `color` property which can be set to `primary`, `accent`, or `warn`. This | ||
will set the color ofr the form field underline and floating placeholder based on the theme colors |
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.
ofr
-> of
comments addressed |
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
40dbe1d
to
468f1e1
Compare
@kara rebased |
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.