Skip to content

Conversation

mmalerba
Copy link
Contributor

No description provided.

@mmalerba mmalerba added docs This issue is related to documentation pr: merge safe labels Sep 29, 2017
@mmalerba mmalerba requested review from jelbourn and kara September 29, 2017 21:34
@mmalerba mmalerba requested a review from amcdnl as a code owner September 29, 2017 21:34
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 29, 2017
Copy link
Contributor

@kara kara left a 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
Copy link
Contributor

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
Copy link
Contributor

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>
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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`.
Copy link
Contributor

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>`
Copy link
Contributor

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

@kara kara removed their assignment Sep 29, 2017
@mmalerba
Copy link
Contributor Author

mmalerba commented Oct 2, 2017

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
Copy link

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();
Copy link

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();
Copy link

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()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching these!

Copy link

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?

@mmalerba mmalerba force-pushed the ff-docs branch 2 times, most recently from 2912f4a to 39fbfd9 Compare October 4, 2017 16:33
<!--
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).
-->
Copy link
Member

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.

<!-- example(form-field-overview) -->

### Floating placeholder
The floating placeholder is an indicative text label displayed on top of the form field control when
Copy link
Member

Choose a reason for hiding this comment

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

Omit "indicative"?

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
Copy link
Member

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" ?

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
Copy link
Member

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

<!-- 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
Copy link
Member

Choose a reason for hiding this comment

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

HTML -> Custom content?

<!-- 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
Copy link
Member

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


### 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
Copy link
Member

Choose a reason for hiding this comment

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

ofr -> of

@mmalerba
Copy link
Contributor Author

mmalerba commented Oct 4, 2017

comments addressed

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Oct 4, 2017
@mmalerba mmalerba force-pushed the ff-docs branch 5 times, most recently from 40dbe1d to 468f1e1 Compare October 4, 2017 21:59
@mmalerba mmalerba requested a review from devversion as a code owner October 4, 2017 21:59
@kara kara added pr: needs rebase and removed action: merge The PR is ready for merge by the caretaker labels Oct 4, 2017
@kara kara assigned mmalerba and unassigned jelbourn Oct 4, 2017
@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker and removed pr: needs rebase labels Oct 4, 2017
@mmalerba
Copy link
Contributor Author

mmalerba commented Oct 4, 2017

@kara rebased

@kara kara merged commit adf9b5b into angular:master Oct 4, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement docs This issue is related to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants