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(material-experimental/mdc-form-field): fix outline notch width #23005

Merged
merged 2 commits into from Sep 14, 2021

Conversation

devversion
Copy link
Member

This commit fixes a couple of issues that have been introduced
by accident over time:

  1. The outline notch width is incorrectly calculated since fix(material-experimental/mdc-typography): update mdc components typography to match spec #21676. This happens because we manually override
    the label's typography level to body1 but didn't account for the font-size set
    by the notched-outline. This resulted in the computed label width being incorrect.

  2. fix(material-experimental/mdc-form-field): fix height for form field … #22089 added line-height: 0 to fix textarea's accidentally expanding the infix vertically.
    This breaks custom controls and their alignment. Textarea's seem to behave a
    little different compared to a native input, and the actual fix seems
    to be to fix the alignment from top to middle so that the infix
    does not try to add additional padding (due to the inherited body1
    line-height and to satisfy min-height). Example:
    https://jsfiddle.net/rpvm4bkL/6/.

  3. Typography has been moved with
    fix(material-experimental/mdc-typography): update mdc components typography to match spec #21676 to the
    input control (notice how font: inherit is removed too). This
    breaks custom form controls that rely on the typography provided
    by the form-field (these controls would just inherit typography)

  4. Not an actual fix, but a cleanup since 21ab17f
    added a class to avoid styles from the form-field leaking into
    standalone inputs. The class has been updated to be more specific that
    it only matches form-control inputs, and not any type of form
    control.

Also cleans up logic for the label offset computation. Instead of hard-coding values extracted from MDC, we should have a constant describing where this value comes from. Lastly, deletes a .swp file that has sneaked into the repo.

@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 17, 2021
@devversion devversion changed the title fix(material-experimental/mdc-form-fiel): fix outline notch width fix(material-experimental/mdc-form-field): fix outline notch width Jun 17, 2021
@devversion devversion added the target: patch This PR is targeted for the next patch release label Jun 17, 2021
@devversion devversion marked this pull request as ready for review June 17, 2021 15:36
// Set the vertical alignment for textareas inside form fields to be the middle. This
// ensures that textareas do not stretch the infix container vertically without having
// multiple rows of text. See: https://github.com/angular/components/pull/22089.
vertical-align: middle;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure this doesn't mess up prefix/suffix icon alignment?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've tested with a text suffix/prefix and icons, looks good. Here is a screenshot for you to verify:
image

It looks like the icon aligns in the middle vertically if the textarea is resized to be larger; but that seems unrelated to this change, and I'm not sure what is expected here

Copy link
Member

Choose a reason for hiding this comment

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

Is it just me or are there some extra lines in that screenshot?
122447133-b815fe00-cfa3-11eb-8865-0c7dd87bd938

Copy link
Member Author

Choose a reason for hiding this comment

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

This is unrelated to this PR (can be observed in Miles' form-field demo too; https://mmalerba-demo-1.web.app/mdc-input). I'll have a look at this in a separate PR; it's also observable on the MDC textfield itself but not as obvious.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I've noticed that extra line before too, it comes from the MDC styles. I remember having a similar issue back when I was writing our outline form field too.

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.

LGTM, but leaving to Miles for final approval.

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Jun 18, 2021
@devversion devversion added the P2 The issue is important to a large percentage of users, with a workaround label Jun 24, 2021
@devversion devversion force-pushed the fix/form-field-fixes-mdc branch 2 times, most recently from 4882d9f to cc8bb0e Compare July 6, 2021 13:11
@mmalerba
Copy link
Contributor

@devversion needs rebase

@mmalerba mmalerba added the G This is is related to a Google internal issue label Jul 12, 2021
@devversion
Copy link
Member Author

@mmalerba Done.

@wagnermaciel
Copy link
Contributor

I believe the additional padding is causing the text area to overflow

Before

Screen Shot 2021-07-13 at 11 06 16 AM

After

Screen Shot 2021-07-13 at 11 06 23 AM

This is causing a lot of screenshot test failures internally

@wagnermaciel
Copy link
Contributor

Did some more digging. Turns out there used to be resize: none on the textareas coming from cdk/text-field/_index.scss. They are now getting resize: auto from material-experimental/mdc-form-field/_mdc-text-field-textarea-overrides.scss. That plus some of the other styles from there are probably what's breaking the screenshot tests

@devversion
Copy link
Member Author

@wagnermaciel Nice findings. It makes sense that this happens now because our MDC styles for the textarea have increased in specificity. I'd need to look how we can make this work. It seems like even with same specificity of the CDK textarea styles this is prone to break.

@wagnermaciel
Copy link
Contributor

Does that mean this an expected failure? Is this how the text input is meant to look now?

@devversion
Copy link
Member Author

@wagnermaciel It's not expected. I didn't realize this was happening because our examples of the form-field are quite large. Updated the PR to let cdk-textarea-autosize override the resize CSS property to none. Should be good for another presubmit.

// MDC uses `subtitle1` for the input value, placeholder and floating label. The spec
// shows `body1` for text fields though, so we manually override the typography.
// Note: Form controls inherit the typography from the parent form field.
.mat-mdc-form-field,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think changing these selectors broke some of the typography. I'm seeing a few screenshots in g3 where the font changed. Can we change them back?

@zarend zarend added the presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged label Jul 29, 2021
This commit fixes a couple of issues that have been introduced
by accident over time:

1. The outline notch width is incorrectly calculated since
   angular#21676. This happens
   because we manually override the label's typography level to `body1`
   but didn't account for the `font-size` set by the `notched-outline`.
   This resulted in the computed label width being incorrect.

2. angular#22089 added `line-height:
   0` to fix textarea's accidentally expanding the infix vertically.
   This breaks custom controls and their alignment. Textarea's behave a
   little different compared to a native input, and the actual fix seems
   to be to fix the alignment from `top` to `middle` so that the infix
   does not try to add additional padding (due to the inherited `body1`
   line-height and to satisfy `min-height`). Example:
   https://jsfiddle.net/rpvm4bkL/6/.

3. Typography has been moved with
   angular#21676 to the
   input control (notice how `font: inherit` is removed too). This
   breaks custom form controls that rely on the typography provided
   by the form-field (these controls would just inherit typography)

4. Not an actual fix, but a cleanup since 21ab17f
  added a class to avoid styles from the form-field leaking into
  standalone inputs. The class has been updated to be more specific that
  it only matches form-control inputs, and not _any_ type of form
  control.
@mmalerba mmalerba removed the presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged label Sep 14, 2021
@andrewseguin andrewseguin merged commit 04d2aaa into angular:master Sep 14, 2021
andrewseguin pushed a commit that referenced this pull request Sep 14, 2021
…23005)

* fix(material-experimental/mdc-form-field): fix outline notch width

This commit fixes a couple of issues that have been introduced
by accident over time:

1. The outline notch width is incorrectly calculated since
   #21676. This happens
   because we manually override the label's typography level to `body1`
   but didn't account for the `font-size` set by the `notched-outline`.
   This resulted in the computed label width being incorrect.

2. #22089 added `line-height:
   0` to fix textarea's accidentally expanding the infix vertically.
   This breaks custom controls and their alignment. Textarea's behave a
   little different compared to a native input, and the actual fix seems
   to be to fix the alignment from `top` to `middle` so that the infix
   does not try to add additional padding (due to the inherited `body1`
   line-height and to satisfy `min-height`). Example:
   https://jsfiddle.net/rpvm4bkL/6/.

3. Typography has been moved with
   #21676 to the
   input control (notice how `font: inherit` is removed too). This
   breaks custom form controls that rely on the typography provided
   by the form-field (these controls would just inherit typography)

4. Not an actual fix, but a cleanup since 21ab17f
  added a class to avoid styles from the form-field leaking into
  standalone inputs. The class has been updated to be more specific that
  it only matches form-control inputs, and not _any_ type of form
  control.

* fix(material-experimental/mdc-form-field): increase specificity of `line-height: normal` on the floating label

Co-authored-by: Miles Malerba <mmalerba@google.com>
(cherry picked from commit 04d2aaa)
@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 Oct 15, 2021
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 G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants