_mdc-text-field-density-overrides.scss 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. @use '../core/tokens/m2/mat/form-field' as tokens-mat-form-field;
  2. @use '../core/tokens/token-utils';
  3. // Mixin that includes the density styles for form fields. MDC provides their own density
  4. // styles for MDC text-field which we cannot use. MDC relies on input elements to stretch
  5. // vertically when the height is reduced as per density scale. This doesn't work for our
  6. // form field since we support custom form field controls without a fixed height. Instead, we
  7. // provide spacing that makes arbitrary controls align as specified in the Material Design
  8. // specification. In order to support density, we need to adjust the vertical spacing to be
  9. // based on the density scale.
  10. @mixin private-text-field-density-overrides() {
  11. @include token-utils.use-tokens(
  12. tokens-mat-form-field.$prefix, tokens-mat-form-field.get-token-slots()) {
  13. $height: token-utils.get-token-variable(container-height);
  14. .mat-mdc-form-field-infix {
  15. // We add a minimum height to the infix container to ensure that custom controls have the
  16. // same default vertical space as text-field inputs (with respect to the vertical padding).
  17. min-height: #{$height};
  18. @include token-utils.create-token-slot(padding-top,
  19. filled-with-label-container-padding-top);
  20. @include token-utils.create-token-slot(padding-bottom,
  21. filled-with-label-container-padding-bottom);
  22. .mdc-text-field--outlined &,
  23. .mdc-text-field--no-label & {
  24. @include token-utils.create-token-slot(padding-top, container-vertical-padding);
  25. @include token-utils.create-token-slot(padding-bottom, container-vertical-padding);
  26. }
  27. }
  28. // By default, MDC aligns the label using percentage. This will be overwritten based
  29. // on whether a textarea is used. This is not possible in our implementation of the
  30. // form-field because we do not know what type of form-field control is set up. Hence
  31. // we always use a fixed position for the label. This does not have any implications.
  32. .mat-mdc-text-field-wrapper .mat-mdc-form-field-flex .mat-mdc-floating-label {
  33. top: calc(#{$height} / 2);
  34. }
  35. // We need to conditionally hide the floating label based on the height of the form field.
  36. .mdc-text-field--filled .mat-mdc-floating-label {
  37. display: token-utils.get-token-variable(filled-label-display, $fallback: block);
  38. }
  39. // For the outline appearance, we re-create the active floating label transform. This is
  40. // necessary because the transform for docked floating labels can be updated to account for
  41. // the width of prefix container.
  42. .mat-mdc-text-field-wrapper.mdc-text-field--outlined .mdc-notched-outline--upgraded
  43. .mdc-floating-label--float-above {
  44. // Needs to be in a string form to work around an internal check that incorrectly flags this
  45. // interpolation in `calc` as unnecessary. If we don't have it, Sass won't evaluate it.
  46. $offset: 'calc(6.75px + #{$height} / 2)';
  47. $translate: 'calc(#{$offset} * -1)';
  48. --mat-mdc-form-field-label-transform: translateY(#{$translate})
  49. scale(var(--mat-mdc-form-field-floating-label-scale, 0.75));
  50. transform: var(--mat-mdc-form-field-label-transform);
  51. }
  52. }
  53. }