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 notch visual artifact #25201

Merged
merged 3 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/material-experimental/mdc-form-field/_form-field-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@
.mat-mdc-form-field.mat-warn {
@include _color-styles(error);
}

// This fixes an issue where the notch appears to be thicker than the rest of the outline when
// zoomed in on Chrome. The border inconsistency seems to be some kind of rendering artifact
// that arises from a combination of the fact that the notch contains text, while the leading
// and trailing outline do not, combined with the fact that the border is semi-transparent.
// Experimentally, I discovered that adding a transparent left border fixes the inconsistency.
// Note: class name is repeated to achieve sufficient specificity over the various MDC states.
// (hover, focus, etc.)
// TODO(mmalerba): port this fix into MDC
.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field {
&.mat-mdc-form-field .mdc-notched-outline__notch {
border-left: 1px solid transparent;
}
}

[dir='rtl'] {
.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field {
&.mat-mdc-form-field .mdc-notched-outline__notch {
border-left: none;
border-right: 1px solid transparent;
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ export class MatFormFieldNotchedOutline implements AfterViewInit {
_getNotchWidth() {
if (this.open) {
const NOTCH_ELEMENT_PADDING = 8;
const NOTCH_ELEMENT_BORDER = 1;
return this.labelWidth > 0
? `calc(${this.labelWidth}px * var(--mat-mdc-form-field-floating-label-scale, 0.75) + ${NOTCH_ELEMENT_PADDING}px)`
? `calc(${this.labelWidth}px * var(--mat-mdc-form-field-floating-label-scale, 0.75) + ${
NOTCH_ELEMENT_PADDING + NOTCH_ELEMENT_BORDER
}px)`
: '0px';
}

Expand Down
15 changes: 15 additions & 0 deletions src/material-experimental/mdc-form-field/form-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@
box-sizing: border-box;
}

// In the form-field theme, we add a 1px left margin to the notch to fix a rendering bug in Chrome.
// Here we apply negative margin to offset the effect on the layout and a clip-path to ensure the
// left border is completely hidden. (Though the border is transparent, it still creates a triangle
// shaped artifact where it meets the top and bottom borders.)
.mat-mdc-form-field .mdc-notched-outline__notch {
margin-left: -1px;
@include mat.private-clip-path(inset(-9em -9em -9em 1px));

[dir='rtl'] & {
margin-left: 0;
margin-right: -1px;
@include mat.private-clip-path(inset(-9em 1px -9em -9em));
}
}

// In order to make it possible for developers to disable animations for form-fields,
// we only activate the animation styles if animations are not explicitly disabled.
.mat-mdc-form-field:not(.mat-form-field-no-animations) {
Expand Down
2 changes: 1 addition & 1 deletion src/material/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@forward './core/style/layout-common' as private-* show private-fill;
@forward './core/style/private' show private-theme-elevation, private-animation-noop;
@forward './core/style/vendor-prefixes' as private-* show private-user-select,
private-position-sticky, private-color-adjust;
private-position-sticky, private-color-adjust, private-clip-path;
@forward './core/theming/palette' as private-* show $private-dark-primary-text,
$private-dark-disabled-text;
@forward './core/style/variables' as private-* show $private-swift-ease-in-duration,
Expand Down
5 changes: 5 additions & 0 deletions src/material/core/style/_vendor-prefixes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@
-webkit-background-clip: $value;
background-clip: $value;
}

@mixin clip-path($value) {
-webkit-clip-path: $value;
clip-path: $value;
}
// stylelint-enable