Skip to content

Commit 4727c8b

Browse files
committed
fix(material-experimental/mdc-form-field): fix notch visual artifact (#25201)
* fix(material-experimental/mdc-form-field): fix notch visual artifact * fixup! fix(material-experimental/mdc-form-field): fix notch visual artifact * fixup! fix(material-experimental/mdc-form-field): fix notch visual artifact (cherry picked from commit 63aad54)
1 parent 07feece commit 4727c8b

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

src/material-experimental/mdc-form-field/_form-field-theme.scss

+23
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@
5858
.mat-mdc-form-field.mat-warn {
5959
@include _color-styles(error);
6060
}
61+
62+
// This fixes an issue where the notch appears to be thicker than the rest of the outline when
63+
// zoomed in on Chrome. The border inconsistency seems to be some kind of rendering artifact
64+
// that arises from a combination of the fact that the notch contains text, while the leading
65+
// and trailing outline do not, combined with the fact that the border is semi-transparent.
66+
// Experimentally, I discovered that adding a transparent left border fixes the inconsistency.
67+
// Note: class name is repeated to achieve sufficient specificity over the various MDC states.
68+
// (hover, focus, etc.)
69+
// TODO(mmalerba): port this fix into MDC
70+
.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field {
71+
&.mat-mdc-form-field .mdc-notched-outline__notch {
72+
border-left: 1px solid transparent;
73+
}
74+
}
75+
76+
[dir='rtl'] {
77+
.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field {
78+
&.mat-mdc-form-field .mdc-notched-outline__notch {
79+
border-left: none;
80+
border-right: 1px solid transparent;
81+
}
82+
}
83+
}
6184
}
6285
}
6386
}

src/material-experimental/mdc-form-field/directives/notched-outline.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ export class MatFormFieldNotchedOutline implements AfterViewInit {
6262
_getNotchWidth() {
6363
if (this.open) {
6464
const NOTCH_ELEMENT_PADDING = 8;
65+
const NOTCH_ELEMENT_BORDER = 1;
6566
return this.labelWidth > 0
66-
? `calc(${this.labelWidth}px * var(--mat-mdc-form-field-floating-label-scale, 0.75) + ${NOTCH_ELEMENT_PADDING}px)`
67+
? `calc(${this.labelWidth}px * var(--mat-mdc-form-field-floating-label-scale, 0.75) + ${
68+
NOTCH_ELEMENT_PADDING + NOTCH_ELEMENT_BORDER
69+
}px)`
6770
: '0px';
6871
}
6972

src/material-experimental/mdc-form-field/form-field.scss

+15
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@
122122
box-sizing: border-box;
123123
}
124124

125+
// In the form-field theme, we add a 1px left margin to the notch to fix a rendering bug in Chrome.
126+
// Here we apply negative margin to offset the effect on the layout and a clip-path to ensure the
127+
// left border is completely hidden. (Though the border is transparent, it still creates a triangle
128+
// shaped artifact where it meets the top and bottom borders.)
129+
.mat-mdc-form-field .mdc-notched-outline__notch {
130+
margin-left: -1px;
131+
@include mat.private-clip-path(inset(-9em -9em -9em 1px));
132+
133+
[dir='rtl'] & {
134+
margin-left: 0;
135+
margin-right: -1px;
136+
@include mat.private-clip-path(inset(-9em 1px -9em -9em));
137+
}
138+
}
139+
125140
// In order to make it possible for developers to disable animations for form-fields,
126141
// we only activate the animation styles if animations are not explicitly disabled.
127142
.mat-mdc-form-field:not(.mat-form-field-no-animations) {

src/material/_index.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
@forward './core/style/layout-common' as private-* show private-fill;
2222
@forward './core/style/private' show private-theme-elevation, private-animation-noop;
2323
@forward './core/style/vendor-prefixes' as private-* show private-user-select,
24-
private-position-sticky, private-color-adjust;
24+
private-position-sticky, private-color-adjust, private-clip-path;
2525
@forward './core/theming/palette' as private-* show $private-dark-primary-text,
2626
$private-dark-disabled-text;
2727
@forward './core/style/variables' as private-* show $private-swift-ease-in-duration,

src/material/core/style/_vendor-prefixes.scss

+5
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@
3838
-webkit-background-clip: $value;
3939
background-clip: $value;
4040
}
41+
42+
@mixin clip-path($value) {
43+
-webkit-clip-path: $value;
44+
clip-path: $value;
45+
}
4146
// stylelint-enable

0 commit comments

Comments
 (0)