-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fix(input): make input spacing match spec #4788
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.
src/lib/input/input-container.scss
Outdated
.mat-input-container { | ||
display: inline-block; | ||
position: relative; | ||
font-family: $mat-font-family; | ||
line-height: normal; | ||
|
||
// TODO(mmalerba): should this come from typography settings? If so a lot of this CSS needs to go |
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.
There will be a typography mixin in #4375.
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.
Ah cool, so the way I set up the styles for this, I actually need the ratio of line-height/font-size. I could try to derive this by just dividing the variables in your mat-typography-level
but that expects that they have the same units. Would it be better to have the mixin take the unitless ratio?
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 whether we'd be able to exactly match the spec if we went unitless. That being said, not all values have to go through the typogaphy API necessarily. You can take the font size and have a custom line height.
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 wouldn't we be able to match the spec? For example we would just change:
$subheading: mat-typography-level(16px, 28px, 400),
to
$subheading: mat-typography-level(16px, 28 / 16, 400),
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.
Hmm you're right, I'll change it after the initial PR gets in. It also doesn't handle margins at the moment so I can do them together. If you hardcode it and leave a comment, I can change it when I do a pass on the components.
src/lib/input/input-container.scss
Outdated
.mat-datepicker-toggle { | ||
width: 1em; | ||
height: 1em; | ||
font-size: $mat-input-prefix-suffix-icon-font-size; |
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 one could use a TODO to switch it to the typography API.
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 this one I want to depend on the input's font-size so that the ratio from the spec is preserved. Therefore doesn't need to come from the typography API
<div class="mat-input-prefix" *ngIf="_prefixChildren.length"> | ||
<!-- TODO(andrewseguin): remove [md-prefix] --> | ||
<ng-content select="[mdPrefix], [matPrefix], [md-prefix]"></ng-content> | ||
<ng-content select="[mdPrefix], [matPrefix]"></ng-content> |
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.
There are three use sites for md-prefix
and one for md-suffix
inside google
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'll fix them
src/lib/input/input-container.scss
Outdated
// The height of the underline. | ||
$mat-input-underline-height: 1px !default; | ||
// The amount to scale the font for the floating label and subscript. | ||
$mat-input-helper-font-scale: 0.75 !default; |
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.
"helper"?
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's the terminology used in the spec, changed it to subscript to match our terminology
src/lib/input/input-container.scss
Outdated
$mat-input-wrapper-padding-bottom: | ||
($mat-input-subscript-margin-top + $mat-input-line-height) * $mat-input-helper-font-scale; | ||
// The amount of y-offset to apply to the placeholder when it is floating. | ||
$mat-input-floating-placeholder-offset: -$mat-input-infix-padding - 1em; |
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.
optional: maybe it would be useful to have a diagram for how all this comes together?
src/lib/input/input-container.scss
Outdated
transform: translate3d(0, -1.35em, 0) scale($mat-input-floating-placeholder-scale-factor); | ||
width: 100% / $mat-input-floating-placeholder-scale-factor; | ||
transform: translateY(-$mat-input-infix-margin-top - $mat-input-infix-padding) | ||
perspective(1px) // fixes text blurriness. |
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.
Huh, I've never seen this before in my life. Can you elaborate in a comment on what the problem is and how this fixes it? Any resources to link that led to this approach?
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.
just trial and error of various approaches people suggested, linked to the site where I saw this suggestion
src/lib/input/input-container.scss
Outdated
scale($mat-input-helper-font-scale); | ||
width: 100% / $mat-input-helper-font-scale; | ||
// fixes text blurriness, see | ||
// https://css-tricks.com/forums/topic/transforms-cause-font-smoothing-weirdness-in-webkit/ |
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.
Would be better to link to the relevant article instead of the question
http://www.useragentman.com/blog/2014/05/04/fixing-typography-inside-of-2-d-css-transforms/
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 a second pass and it LGTM. A couple of notes:
- There's some weird shifting of the placeholder text that is going on in IE when you focus/blur. It's probably related to
transform
weirdness and we most likely can't do much about it. - I think there might a regression of the fix from fix(input): correct invalid colors #4771, but it'll probably be solved after a rebase.
7d41437
to
368fab8
Compare
Addressed comments @crisbeto managed to tweak the transforms to get it to look decent on Chrome, IE, and FF |
rebased and moved a bunch of the styles into the typography mixin, PTAL |
$button: mat-typography-level(14px, 14px, 500) | ||
$button: mat-typography-level(14px, 14px, 500), | ||
// Line-height must be unit-less fraction of the font-size. | ||
$input: mat-typography-level(16px, 1.125, 400) |
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.
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 inherit is better; users can always set it to 16px if they want
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
perspective(100px) translateZ(0.001px); | ||
// The tricks above used to smooth out the animation on chrome and firefox actually make things | ||
// worse on IE, so we don't include them in the IE version. | ||
-ms-transform: translateY(-$mat-input-infix-margin-top - $mat-input-infix-padding) |
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 doesn't cause a stylelint error?
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.
nope, seems fine
still WIP placeholder working, still WIP fixed main styles, now just themes... themes working again icon button support
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. |
redo the input CSS to make the spacing between various elements match the material spec (https://material.io/guidelines/components/text-fields.html).
The spec shows what things look like at 16px font size, we currently use 14px which I could change, but for now I've left it so everything should look like a scaled down version of the mock.
Also adds support for icon buttons inside prefix and suffix