Skip to content

Commit f003174

Browse files
committed
fix(material-experimental/mdc-form-field): address feedback
1 parent 124f1cc commit f003174

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
// the width of prefix container.
8888
.mat-mdc-text-field-wrapper.mdc-text-field--outlined .mdc-notched-outline--upgraded
8989
.mdc-floating-label--float-above {
90-
--mat-mdc-form-field-label-transform:
91-
translateY(-#{mdc-textfield.get-outlined-label-position-y($height)}) scale(0.75);
90+
--mat-mdc-form-field-label-transform: translateY(
91+
-#{mdc-textfield.get-outlined-label-position-y($height)}) scale(0.75);
9292
}
9393

9494
// Add vertical spacing to the infix to ensure that outlined form fields have their controls

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ const DEFAULT_FLOAT_LABEL: FloatLabelType = 'auto';
101101
/** Default way that the subscript element height is set. */
102102
const DEFAULT_SUBSCRIPT_SIZING: SubscriptSizing = 'fixed';
103103

104+
/**
105+
* Default transform for docked floating labels in a MDC text-field. This value has been
106+
* extracted from the MDC text-field styles because we programmatically modify the docked
107+
* label transform, but do not want to accidentally discard the default label transform.
108+
*/
109+
const FLOATING_LABEL_DEFAULT_DOCKED_TRANSFORM = `translateY(-50%)`;
110+
104111
/**
105112
* Horizontal padding in pixels used by the MDC for the wrapper containing infix.
106113
* This value is extracted from MDC's Sass variables. See `$padding-horizontal`.
@@ -669,8 +676,13 @@ export class MatFormField
669676
((iconPrefixContainer ? iconPrefixContainerWidth - WRAPPER_HORIZONTAL_PADDING : 0) +
670677
textPrefixContainerWidth);
671678

672-
// Update the transform x of the floating label to account for the prefix container.
673-
floatingLabel.style.transform = `var(--mat-mdc-form-field-label-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+
// docked.
682+
floatingLabel.style.transform = `var(
683+
--mat-mdc-form-field-label-transform,
684+
${FLOATING_LABEL_DEFAULT_DOCKED_TRANSFORM} translateX(${labelHorizontalOffset}px
685+
)`;
674686
}
675687

676688
/** Checks whether the form field is attached to the DOM. */

0 commit comments

Comments
 (0)