Skip to content
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

Merged
merged 9 commits into from
Jun 2, 2017

Conversation

mmalerba
Copy link
Contributor

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

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 25, 2017
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

Code seems fine, but a few of the examples in the demo are broken on IE.

oh no

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

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

@crisbeto crisbeto May 25, 2017

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.

.mat-datepicker-toggle {
width: 1em;
height: 1em;
font-size: $mat-input-prefix-suffix-icon-font-size;
Copy link
Member

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.

Copy link
Contributor Author

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll fix them

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

Choose a reason for hiding this comment

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

"helper"?

Copy link
Contributor Author

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

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

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?

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

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?

Copy link
Contributor Author

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

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

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/

Copy link
Member

@crisbeto crisbeto left a 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.

@mmalerba mmalerba force-pushed the input-spec branch 2 times, most recently from 7d41437 to 368fab8 Compare May 31, 2017 18:36
@mmalerba
Copy link
Contributor Author

Addressed comments

@crisbeto managed to tweak the transforms to get it to look decent on Chrome, IE, and FF

@mmalerba
Copy link
Contributor Author

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

Choose a reason for hiding this comment

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

@jelbourn @crisbeto spec says 16px for inputs, but by doing this I ruin its ability to inherit from its parent (e.g. so that an input inside an <h1> matches the font size, should I keep this as 16px or change to inherit?

Copy link
Member

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

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

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, seems fine

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Jun 1, 2017
mmalerba added 5 commits June 2, 2017 13:58
still WIP

placeholder working, still WIP

fixed main styles, now just themes...

themes working again

icon button support
@mmalerba mmalerba merged commit 16b65e8 into angular:master Jun 2, 2017
@mmalerba mmalerba deleted the input-spec branch April 3, 2018 15:17
@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 8, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants