Skip to content

Commit c028452

Browse files
committed
fixup! fix(material-experimental/mdc-form-field): fix notch visual artifact
1 parent fffd46e commit c028452

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

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

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

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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,18 @@
122122
box-sizing: border-box;
123123
}
124124

125-
// This fixes an issue where the notch appears to be thicker than the rest of the outline when
126-
// zoomed in on Chrome. The border inconsistency seems to be some kind of rendering artifact that
127-
// arises from a combination of the fact that the notch contains text, while the leading and
128-
// trailing outline do not, combined with the fact that the border is semi-transparent.
129-
// Experimentally, I discovered that adding a transparent left border fixes the inconsistency.
130-
// In addition some negative left margin is added to compensate for the transparent border and
131-
// fully fix the issue.
132-
// TODO(mmalerba): port this fix into MDC
133-
.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field.mat-mdc-form-field {
134-
.mdc-notched-outline__notch {
135-
border-left: 1px solid transparent;
136-
margin-left: -1px;
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+
clip-path: inset(-100vh -100vw -100vh 1px);
132+
133+
[dir='rtl'] & {
134+
margin-left: 0;
135+
margin-right: -1px;
136+
clip-path: inset(-100vh 1px -100vh -100vh);
137137
}
138138
}
139139

0 commit comments

Comments
 (0)