-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(form-field): support for different spec variants #9366
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
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning 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.
Some more notes:
- Text inside the
box
variant looks fuzzy. I'm guessing it could be because of theperspective
, because I'm not seeing it on IE. See https://i.imgur.com/6zg8Uz0.png - For the
box
variant + non-floating placeholder we could log a warning in dev mode that it's unsupported. You can use theMATERIAL_SANITY_CHECKS
token so users are able to disable the warning. - I noticed a weird issue on Firefox where only the ellipsis inside an invalid field is white. It doesn't seem to be in master. See https://i.imgur.com/9T63rIb.png
- Regarding prefixes and suffixes, I agree with assuming that they're icons. The text-based prefixes should be handled using a mask inside the input.
@import '../core/style/vendor-prefixes'; | ||
|
||
|
||
// Styles that only apply to the standard variant of 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.
Inaccurate comment.
|
||
.mat-form-field-label { | ||
// The perspective helps smooth out animations on Chrome and Firefox but isn't needed on IE. | ||
transform: translateY(-50%) perspective(100px); |
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 100px
seems arbitrary. Add a comment about where it comes from?
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 just trial and error to balance jumpiness and blurriness issues across different browsers. I'm going to try switching to filter
and backface-visibility
to fix some of these issues. It makes the blurriness better and improves the jumpiness in chrome, but makes firefox a little more jumpy. Overall I think its a little bit better solution
.mat-form-field-label { | ||
// The perspective helps smooth out animations on Chrome and Firefox but isn't needed on IE. | ||
transform: translateY(-50%) perspective(100px); | ||
-ms-transform: translateY(-50%); |
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.
Does it get in the way of IE? If the outcome is the same we might as well keep the single declaration.
src/lib/form-field/form-field.ts
Outdated
@@ -86,6 +95,9 @@ let nextUniqueId = 0; | |||
export class MatFormField implements AfterViewInit, AfterContentInit, AfterContentChecked { | |||
private _labelOptions: LabelOptions; | |||
|
|||
/** The form-field style variant. */ | |||
@Input() variant: 'legacy' | 'standard' | 'box' = 'legacy'; |
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.
Turn this into a type so users can import it?
src/lib/form-field/form-field.ts
Outdated
@@ -86,6 +95,9 @@ let nextUniqueId = 0; | |||
export class MatFormField implements AfterViewInit, AfterContentInit, AfterContentChecked { | |||
private _labelOptions: LabelOptions; | |||
|
|||
/** The form-field style variant. */ | |||
@Input() variant: 'legacy' | 'standard' | 'box' = 'legacy'; | |||
|
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.
Sidenote: maybe we should add an injection token that allows you to specify the default variant?
I took a look at the firefox ellipsis issue, it looks like its caused by the combination of the |
} | ||
|
||
.mat-form-field-label { | ||
backface-visibility: initial; |
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.
IE doesn't support the initial
value, we should have a lint rule for it as well. You can default it to visible
instead.
I also see the blurriness in the box style |
|
||
$underline-color: mat-color($foreground, divider, if($is-dark-theme, 0.7, 0.42)); | ||
|
||
.mat-form-field-variant-legacy { |
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 increases the specificity of these rules, so anyone with an override might find their styles no longer apply. We'll have to look through peoples' styles to gauge the extent of this.
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 if this isn't feasible we can add all the legacy styles to the base styles and then override the ones we don't want in standard, box, and outline
src/lib/form-field/form-field.scss
Outdated
@@ -108,6 +108,9 @@ $mat-form-field-default-infix-width: 180px !default; | |||
// Hide the label initially, and only show it when it's floating or the control is empty. | |||
display: none; | |||
|
|||
// Helps prevent text jumpiness when transforming the label. |
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.
Can you provide any background on why this is so?
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.
Changed some things so this is no longer needed
src/lib/form-field/form-field.scss
Outdated
@@ -77,6 +78,9 @@ $mat-form-field-default-infix-width: 180px !default; | |||
height: 100%; | |||
overflow: hidden; | |||
pointer-events: none; // We shouldn't catch mouse events (let them through). | |||
|
|||
// Helps prevent text jumpiness when transforming the label. |
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.
Can you provide any background on why this is so?
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.
Changed some things so this is no longer needed
src/lib/form-field/form-field.scss
Outdated
transform: scaleX(1); | ||
transition: transform 300ms $swift-ease-out-timing-function, | ||
opacity 100ms $swift-ease-out-timing-function, | ||
background-color 300ms $swift-ease-out-timing-function; |
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.
Indent overflow lines?
@@ -100,5 +105,7 @@ $mat-select-placeholder-arrow-space: 2 * ($mat-select-arrow-size + $mat-select-a | |||
// Remove the transition to prevent the placeholder | |||
// from overlapping when the label comes back down. | |||
transition: none; | |||
// Prevents the '...' from showing on the parent element. | |||
display: block; |
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.
Wouldn't the parent element just not have overflow: ellipses
?
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 overflow: ellipses
on the parent is also what gives the value its ...
so we need to do it this way even though its a little strange
src/lib/select/select.scss
Outdated
|
||
// When used in a box variant form-field the arrow should be centered in the box. | ||
.mat-form-field-variant-box & { | ||
transform: translateY(-50%); |
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.
Transforming by a percentage value like this can lead to blurriness due to subpixel rendering. Generally it's better to center via flex styles
src/lib/form-field/form-field.ts
Outdated
@@ -86,6 +98,9 @@ let nextUniqueId = 0; | |||
export class MatFormField implements AfterViewInit, AfterContentInit, AfterContentChecked { | |||
private _labelOptions: LabelOptions; | |||
|
|||
/** The form-field style variant. */ | |||
@Input() variant: MatFormFieldVariant = 'legacy'; |
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.
Not necessarily in this PR, but we'll also need a provider to set the default appearance 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.
Yep, will add this later
I've updated all of the demos with the latest changes (you may need to clear your cache). I also sent an email to the material design team hoping that they can clarify the prefix/suffix thing for us. |
I've updated the Remaining issues I plan to address in future PRs:
|
resolved the bazel failure, PTAL |
[Based on the spec](https://material.io/guidelines/components/text-fields.html#text-fields-states) form fields should have a hover state where the underline gets darkened while the user is hovering and gets replaced by the theme color after the focus the input.
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
* feat(form-field): implement hover state [Based on the spec](https://material.io/guidelines/components/text-fields.html#text-fields-states) form fields should have a hover state where the underline gets darkened while the user is hovering and gets replaced by the theme color after the focus the input. * branch css logic * extract underline css into standard variant * box variant underline * box variant spacing * add legacy variant * fix select ellipsis * move hover state changes out of legacy variant * add variants section to input demo * use filter/backface-visibility to address label jumpiness * address comments * fix box variant text fuzziness * remove bluriness fixes that aren't needed anymore * address comments * remove the floatLabel=never option in the new variants * variant --> appearance * add tests for new label & placeholder behavior * update demo to use mat-label * fix bazel build
* feat(form-field): implement hover state [Based on the spec](https://material.io/guidelines/components/text-fields.html#text-fields-states) form fields should have a hover state where the underline gets darkened while the user is hovering and gets replaced by the theme color after the focus the input. * branch css logic * extract underline css into standard variant * box variant underline * box variant spacing * add legacy variant * fix select ellipsis * move hover state changes out of legacy variant * add variants section to input demo * use filter/backface-visibility to address label jumpiness * address comments * fix box variant text fuzziness * remove bluriness fixes that aren't needed anymore * address comments * remove the floatLabel=never option in the new variants * variant --> appearance * add tests for new label & placeholder behavior * update demo to use mat-label * fix bazel build
* feat(form-field): implement hover state [Based on the spec](https://material.io/guidelines/components/text-fields.html#text-fields-states) form fields should have a hover state where the underline gets darkened while the user is hovering and gets replaced by the theme color after the focus the input. * branch css logic * extract underline css into standard variant * box variant underline * box variant spacing * add legacy variant * fix select ellipsis * move hover state changes out of legacy variant * add variants section to input demo * use filter/backface-visibility to address label jumpiness * address comments * fix box variant text fuzziness * remove bluriness fixes that aren't needed anymore * address comments * remove the floatLabel=never option in the new variants * variant --> appearance * add tests for new label & placeholder behavior * update demo to use mat-label * fix bazel build
* feat(form-field): implement hover state [Based on the spec](https://material.io/guidelines/components/text-fields.html#text-fields-states) form fields should have a hover state where the underline gets darkened while the user is hovering and gets replaced by the theme color after the focus the input. * branch css logic * extract underline css into standard variant * box variant underline * box variant spacing * add legacy variant * fix select ellipsis * move hover state changes out of legacy variant * add variants section to input demo * use filter/backface-visibility to address label jumpiness * address comments * fix box variant text fuzziness * remove bluriness fixes that aren't needed anymore * address comments * remove the floatLabel=never option in the new variants * variant --> appearance * add tests for new label & placeholder behavior * update demo to use mat-label * fix bazel build
…ter (#9762) * feat(form-field): support for different spec variants (#9366) * feat(form-field): implement hover state [Based on the spec](https://material.io/guidelines/components/text-fields.html#text-fields-states) form fields should have a hover state where the underline gets darkened while the user is hovering and gets replaced by the theme color after the focus the input. * branch css logic * extract underline css into standard variant * box variant underline * box variant spacing * add legacy variant * fix select ellipsis * move hover state changes out of legacy variant * add variants section to input demo * use filter/backface-visibility to address label jumpiness * address comments * fix box variant text fuzziness * remove bluriness fixes that aren't needed anymore * address comments * remove the floatLabel=never option in the new variants * variant --> appearance * add tests for new label & placeholder behavior * update demo to use mat-label * fix bazel build * feat(chips): Add chip avatar and chip trailing icon (#9557) * feat(chips): Add chip avatar and chip trailing icon * Removed MatBasicChip and MatStandardChip * Add mat-chip-trailing-icon style to MatChipRemove and add examples in demo * fix(form-field): rename box to fill and tweak the styles a bit (#9636) * make some tweaks to the box appearance * rename 'box' appearance to 'fill' * feat(form-field): add outline style (#9705) * remove datepicker reliance on form-field's underlineRef * add spacing and alignment rules for outline variant * outline color & thickness * style tweaks * correctly position and size the gap * address comments * fix(form-field): correct prefix & suffix icons as well as select arrow for various form field appearances (#9743) * feat(input): add utilities for custom styling and monitoring state of input autofill (#9719) * add utility for monitoring input autofill * add scss mixin for styling input autofill colors * tests * move everything from cdk to MatInputModule * address comments * add doc comments * fix(form-field): fixes for outline appearance (#9759) * use the `AutofillMonitor` in `MatInput` * Make `updateOutlineGap` public so users can call it if needed * feat(chips): add ripple to chips (#9761) * fix(form-field, chips): fix tests & lint (#9767) * undo change that caused darkened color for legacy form field * fix change detection * fix(chips): remove margin for chip list (#9793) * add terminateOnPointerUp to ripple config
I don't get it. Why so drastic change in the behavior of the non floating label? I liked that feature and I'm using it in production. Can't we not place that mat-label and have a placeholder like thing, but with the required asterisk, you can't put a colored asterisk in the placeholder attribute normally. With that drastic change I'll be forced to stick to 5.2.1. So is it possible to make 1 more component mat-placeholder to act like a placeholder, but have a required mark and be possible to not use mat-label for the purpose of a placeholder |
@talamaska I've upped the priority on #7645 for adding text mask support to the input. I'm not 100% sure our text masking solution will be able to cover this use case, but I'll keep it in mind while designing. The never-float placeholder stuff was really just an artifact of the fact that the spec didn't used to distinguish between label and placeholder and we therefore needed some way to emulate standard placeholder behavior with the floating label. The spec is now much more clear about the fact that the label and placeholder are two different things and the required |
Having a required mark in the placeholder doen't have anything to do with the text masking. It is a totaly separated feature. I see the spec have changed and you think it was wrong to provide that feature, which is adopted by a lot of people. The reality is that forms with just placeholders and without labels have been designed and used long before any of angular or material existed, and will exist in the future so basically by making this decision you again deliver a breaking change, something that happens too often for a mature framework. Maybe that's the point? To make people not count on any of your products and do their own ui framework? Probably this is something I'm going to do - fork the material inputs and hope they will work in future angular versions. |
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. |
Add support for variants and create 3 to start with:
legacy
(same as current master),standard
(same as current master + a couple tweaks to be more in line with the spec),box
(the box style from the spec).Demos:
https://mmalerba-demo1.firebaseapp.com - current master
https://mmalerba-demo2.firebaseapp.com - default variant = legacy (should be identical to master)
https://mmalerba-demo3.firebaseapp.com - default variant = standard
https://mmalerba-demo4.firebaseapp.com - default variant = box
Couple notes:
legacy
is the actual default I used, so nothing should change for anyone unless they explicitly set a variant.box
spec yet.box
variant because of how the label is aligned (see the "first name" input at https://mmalerba-demo4.firebaseapp.com/input). Should we allow it to look broken? Ignore thefloatLabel="never"
option?box
variant. The reason is that we're using prefix/suffix for 2 different purposes:I think (ii) is actually a misuse of the prefix/suffix. It should behave more like a placeholder that only appears once the label floats up. The spec provides more examples of this kind of thing here: https://material.io/guidelines/components/text-fields.html#text-fields-input-types. I think we should probably add support for formats to
MatInput
to handle this case rather than relying on the form-field's prefix/suffix. If you guys agree with this I'll go ahead and make the prefix/suffix behave like the icon case in the spec forstandard
andbox
and leave thelegacy
behavior as is.