From 67b5f82d44b0d924d990eb6f706b8769f10d3e33 Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Fri, 30 Aug 2024 22:54:29 +0000 Subject: [PATCH] fix(material/form-field): Don't allow label to grow larger than input Fixes #26558 --- .../form-field/_mdc-text-field-structure.scss | 96 ++++++++++--------- src/material/form-field/form-field.html | 57 ++++++----- src/material/form-field/form-field.ts | 17 ++++ tools/public_api_guard/material/form-field.md | 4 + 4 files changed, 103 insertions(+), 71 deletions(-) diff --git a/src/material/form-field/_mdc-text-field-structure.scss b/src/material/form-field/_mdc-text-field-structure.scss index 536dd9f1a280..556b7bd9ba82 100644 --- a/src/material/form-field/_mdc-text-field-structure.scss +++ b/src/material/form-field/_mdc-text-field-structure.scss @@ -6,10 +6,14 @@ // Includes the structural styles for the form field inherited from MDC. @mixin private-text-field-structure { - $filled-slots: (tokens-mdc-filled-text-field.$prefix, - tokens-mdc-filled-text-field.get-token-slots()); - $outlined-slots: (tokens-mdc-outlined-text-field.$prefix, - tokens-mdc-outlined-text-field.get-token-slots()); + $filled-slots: ( + tokens-mdc-filled-text-field.$prefix, + tokens-mdc-filled-text-field.get-token-slots() + ); + $outlined-slots: ( + tokens-mdc-outlined-text-field.$prefix, + tokens-mdc-outlined-text-field.get-token-slots() + ); .mdc-text-field { display: inline-flex; @@ -130,19 +134,15 @@ .mdc-text-field--outlined { height: 56px; overflow: visible; - padding-left: 16px; - padding-right: 16px; - @include _supports-max { - @include token-utils.use-tokens($outlined-slots...) { - $shape-var: token-utils.get-token-variable(container-shape); - padding-right: max(16px, #{$shape-var}); - padding-left: max(16px, calc(#{$shape-var} + 4px)); + @include token-utils.use-tokens($outlined-slots...) { + $shape-var: token-utils.get-token-variable(container-shape); + padding-right: max(16px, #{$shape-var}); + padding-left: max(16px, calc(#{$shape-var} + 4px)); - [dir='rtl'] & { - padding-right: max(16px, calc(#{$shape-var} + 4px)); - padding-left: max(16px, #{$shape-var}); - } + [dir='rtl'] & { + padding-right: max(16px, calc(#{$shape-var} + 4px)); + padding-left: max(16px, #{$shape-var}); } } } @@ -342,17 +342,14 @@ border-right: none; border-top-right-radius: 0; border-bottom-right-radius: 0; - width: 12px; @include token-utils.use-tokens($outlined-slots...) { @include token-utils.create-token-slot(border-top-left-radius, container-shape); @include token-utils.create-token-slot(border-bottom-left-radius, container-shape); - @include _supports-max { - .mdc-text-field--outlined .mdc-notched-outline & { - $shape-var: token-utils.get-token-variable(container-shape); - width: max(12px, #{$shape-var}); - } + .mdc-text-field--outlined .mdc-notched-outline & { + $shape-var: token-utils.get-token-variable(container-shape); + width: max(12px, #{$shape-var}); } } @@ -397,14 +394,14 @@ .mdc-notched-outline__notch { flex: 0 0 auto; width: auto; - max-width: calc(100% - 24px); @include token-utils.use-tokens($outlined-slots...) { - @include _supports-max { - .mdc-text-field--outlined .mdc-notched-outline & { - $shape-var: token-utils.get-token-variable(container-shape); - max-width: calc(100% - max(12px, #{$shape-var}) * 2); - } + .mdc-text-field--outlined .mdc-notched-outline & { + $shape-var: token-utils.get-token-variable(container-shape); + max-width: min( + var(--mat-form-field-notch-max-width, 100%), + calc(100% - max(12px, #{$shape-var}) * 2) + ); } } @@ -420,6 +417,7 @@ padding-left: 0; padding-right: 8px; border-top: none; + --mat-form-field-notch-max-width: 100%; } [dir='rtl'] .mdc-notched-outline--notched & { @@ -433,7 +431,8 @@ } .mdc-line-ripple { - &::before, &::after { + &::before, + &::after { position: absolute; bottom: 0; left: 0; @@ -459,8 +458,10 @@ } .mdc-text-field--filled.mdc-text-field--disabled & { - @include token-utils.create-token-slot(border-bottom-color, - disabled-active-indicator-color); + @include token-utils.create-token-slot( + border-bottom-color, + disabled-active-indicator-color + ); } #{$enabled-field}.mdc-text-field--invalid & { @@ -468,8 +469,10 @@ } #{$enabled-field}.mdc-text-field--invalid:not(.mdc-text-field--focused):hover & { - @include token-utils.create-token-slot(border-bottom-color, - error-hover-active-indicator-color); + @include token-utils.create-token-slot( + border-bottom-color, + error-hover-active-indicator-color + ); } } } @@ -481,8 +484,10 @@ @include token-utils.use-tokens($filled-slots...) { .mdc-text-field--filled & { - @include token-utils.create-token-slot(border-bottom-width, - focus-active-indicator-height); + @include token-utils.create-token-slot( + border-bottom-width, + focus-active-indicator-height + ); } .mdc-text-field--filled:not(.mdc-text-field--disabled) & { @@ -490,8 +495,10 @@ } .mdc-text-field--filled.mdc-text-field--invalid:not(.mdc-text-field--disabled) & { - @include token-utils.create-token-slot(border-bottom-color, - error-focus-active-indicator-color); + @include token-utils.create-token-slot( + border-bottom-color, + error-focus-active-indicator-color + ); } } } @@ -571,21 +578,14 @@ } } -// Wraps the content in a `@supports` query targeting the `max` CSS function. -@mixin _supports-max { - // stylelint-disable material/no-prefixes - @supports (top: max(0%)) { - @content; - } - // stylelint-enable -} - // Includes the animation styles for the form field inherited from MDC. @mixin private-text-field-animations { $timing-curve: cubic-bezier(0.4, 0, 0.2, 1); .mdc-floating-label { - transition: transform 150ms $timing-curve, color 150ms $timing-curve; + transition: + transform 150ms $timing-curve, + color 150ms $timing-curve; } .mdc-text-field__input { @@ -611,6 +611,8 @@ } .mdc-line-ripple::after { - transition: transform 180ms $timing-curve, opacity 180ms $timing-curve; + transition: + transform 180ms $timing-curve, + opacity 180ms $timing-curve; } } diff --git a/src/material/form-field/form-field.html b/src/material/form-field/form-field.html index 340990c29d48..0c62f7ca809f 100644 --- a/src/material/form-field/form-field.html +++ b/src/material/form-field/form-field.html @@ -12,33 +12,39 @@ simply link the label to the control using the label `for` attribute. --> @if (_hasFloatingLabel()) { -