_text-field.scss 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Core styles that enable monitoring autofill state of text fields.
  2. @mixin cdk-text-field {
  3. // Keyframes that apply no styles, but allow us to monitor when an text field becomes autofilled
  4. // by watching for the animation events that are fired when they start. Note: the /*!*/ comment is
  5. // needed to prevent LibSass from stripping the keyframes out.
  6. // Based on: https://medium.com/@brunn/detecting-autofilled-fields-in-javascript-aed598d25da7
  7. @keyframes cdk-text-field-autofill-start {/*!*/}
  8. @keyframes cdk-text-field-autofill-end {/*!*/}
  9. .cdk-text-field-autofill-monitored:-webkit-autofill {
  10. animation-name: cdk-text-field-autofill-start;
  11. }
  12. .cdk-text-field-autofill-monitored:not(:-webkit-autofill) {
  13. animation-name: cdk-text-field-autofill-end;
  14. }
  15. // Remove the resize handle on autosizing textareas, because whatever height
  16. // the user resized to will be overwritten once they start typing again.
  17. textarea.cdk-textarea-autosize {
  18. resize: none;
  19. }
  20. // This class is temporarily applied to the textarea when it is being measured. It is immediately
  21. // removed when measuring is complete. We use `!important` rules here to make sure user-specified
  22. // rules do not interfere with the measurement.
  23. textarea.cdk-textarea-autosize-measuring {
  24. height: auto !important;
  25. overflow: hidden !important;
  26. // Having 2px top and bottom padding seems to fix a bug where Chrome gets an incorrect
  27. // measurement. We just have to account for it later and subtract it off the final result.
  28. padding: 2px 0 !important;
  29. box-sizing: content-box !important;
  30. }
  31. }
  32. // Used to generate UIDs for keyframes used to change the text field autofill styles.
  33. $cdk-text-field-autofill-color-frame-count: 0;
  34. // Mixin used to apply custom background and foreground colors to an autofilled text field.
  35. // Based on: https://stackoverflow.com/questions/2781549/
  36. // removing-input-background-colour-for-chrome-autocomplete#answer-37432260
  37. @mixin cdk-text-field-autofill-color($background, $foreground:'') {
  38. @keyframes cdk-text-field-autofill-color-#{$cdk-text-field-autofill-color-frame-count} {
  39. to {
  40. background: $background;
  41. @if $foreground != '' { color: $foreground; }
  42. }
  43. }
  44. &:-webkit-autofill {
  45. animation-name: cdk-text-field-autofill-color-#{$cdk-text-field-autofill-color-frame-count};
  46. animation-fill-mode: both;
  47. }
  48. &.cdk-text-field-autofill-monitored:-webkit-autofill {
  49. animation-name: cdk-text-field-autofill-start,
  50. cdk-text-field-autofill-color-#{$cdk-text-field-autofill-color-frame-count};
  51. }
  52. $cdk-text-field-autofill-color-frame-count:
  53. $cdk-text-field-autofill-color-frame-count + 1 !global;
  54. }