File tree Expand file tree Collapse file tree 2 files changed +11
-11
lines changed
src/material-experimental/mdc-form-field Expand file tree Collapse file tree 2 files changed +11
-11
lines changed Original file line number Diff line number Diff line change 84
84
85
85
// For the outline appearance, we re-create the active floating label transform. This is
86
86
// necessary because the transform for docked floating labels can be updated to account for
87
- // the width of prefix container. We need to re-create these styles with `!important` because
88
- // the horizontal adjustment for the label is applied through inline styles, and we want to
89
- // make sure that the label can still float as expected. It should be okay using `!important`
90
- // because it's unlikely that developers commonly overwrite the floating label transform.
87
+ // the width of prefix container.
91
88
.mat-mdc-text-field-wrapper.mdc-text-field--outlined .mdc-notched-outline--upgraded
92
89
.mdc-floating-label--float-above {
93
- $outlined-label-floating-position-y : mdc-textfield .get-outlined-label-position-y ($height );
94
- // This transform has been extracted from the MDC text-field styles. We can't access it
95
- // through a variable because MDC generates this label transform through a mixin.
96
- transform : translateY (- $outlined-label-floating-position-y ) scale (0.75 ) !important ;
90
+ --mat-mdc-form-field-label-transform : translateY (
91
+ - #{mdc-textfield .get-outlined-label-position-y ($height )} ) scale (0.75 );
92
+ transform : var (--mat-mdc-form-field-label-transform );
97
93
}
98
94
99
95
// Add vertical spacing to the infix to ensure that outlined form fields have their controls
Original file line number Diff line number Diff line change @@ -676,9 +676,13 @@ export class MatFormField
676
676
( ( iconPrefixContainer ? iconPrefixContainerWidth - WRAPPER_HORIZONTAL_PADDING : 0 ) +
677
677
textPrefixContainerWidth ) ;
678
678
679
- // Update the transform the floating label to account for the prefix container. Note
680
- // that we do not want to overwrite the default transform for docked floating labels.
681
- floatingLabel . style . transform = `${ FLOATING_LABEL_DEFAULT_DOCKED_TRANSFORM } translateX(${ labelHorizontalOffset } px)` ;
679
+ // Update the translateX of the floating label to account for the prefix container,
680
+ // but allow the CSS to override this setting via a CSS variable when the label is
681
+ // floating.
682
+ floatingLabel . style . transform = `var(
683
+ --mat-mdc-form-field-label-transform,
684
+ ${ FLOATING_LABEL_DEFAULT_DOCKED_TRANSFORM } translateX(${ labelHorizontalOffset } px
685
+ )` ;
682
686
}
683
687
684
688
/** Checks whether the form field is attached to the DOM. */
You can’t perform that action at this time.
0 commit comments