_index.scss 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Structural styles for the autosize text fields.
  2. @mixin text-field-autosize() {
  3. // Remove the resize handle on autosizing textareas, because whatever height
  4. // the user resized to will be overwritten once they start typing again.
  5. textarea.cdk-textarea-autosize {
  6. resize: none;
  7. }
  8. // This class is temporarily applied to the textarea when it is being measured. It is immediately
  9. // removed when measuring is complete. We use `!important` rules here to make sure user-specified
  10. // rules do not interfere with the measurement.
  11. textarea.cdk-textarea-autosize-measuring {
  12. @include _autosize-measuring-base;
  13. height: auto !important;
  14. overflow: hidden !important;
  15. }
  16. // Similar to the `cdk-textarea-autosize-measuring` class, but only applied on Firefox. We need
  17. // to use this class, because Firefox has a bug where changing the `overflow` breaks the user's
  18. // ability to undo/redo what they were typing (see #16629). This class is only scoped to Firefox,
  19. // because the measurements there don't seem to be affected by the `height: 0`, whereas on other
  20. // browsers they are, e.g. Chrome detects longer text and IE does't resize back to normal.
  21. // Identical issue report: https://bugzilla.mozilla.org/show_bug.cgi?id=448784
  22. textarea.cdk-textarea-autosize-measuring-firefox {
  23. @include _autosize-measuring-base;
  24. height: 0 !important;
  25. }
  26. }
  27. // Core styles that enable monitoring autofill state of text fields.
  28. @mixin text-field-autofill() {
  29. // Keyframes that apply no styles, but allow us to monitor when a text field becomes autofilled
  30. // by watching for the animation events that are fired when they start. Note: the /*!*/ comment is
  31. // needed to prevent LibSass from stripping the keyframes out.
  32. // Based on: https://medium.com/@brunn/detecting-autofilled-fields-in-javascript-aed598d25da7
  33. @keyframes cdk-text-field-autofill-start {/*!*/}
  34. @keyframes cdk-text-field-autofill-end {/*!*/}
  35. .cdk-text-field-autofill-monitored:-webkit-autofill {
  36. // Since Chrome 80 we need a 1ms delay, or the animationstart event won't fire.
  37. animation: cdk-text-field-autofill-start 0s 1ms;
  38. }
  39. .cdk-text-field-autofill-monitored:not(:-webkit-autofill) {
  40. // Since Chrome 80 we need a 1ms delay, or the animationstart event won't fire.
  41. animation: cdk-text-field-autofill-end 0s 1ms;
  42. }
  43. }
  44. @mixin _autosize-measuring-base {
  45. // Having 2px top and bottom padding seems to fix a bug where Chrome gets an incorrect
  46. // measurement. We just have to account for it later and subtract it off the final result.
  47. padding: 2px 0 !important;
  48. box-sizing: content-box !important;
  49. }
  50. // Used to generate UIDs for keyframes used to change the text field autofill styles.
  51. $autofill-color-frame-count: 0;
  52. // Mixin used to apply custom background and foreground colors to an autofilled text field.
  53. // Based on: https://stackoverflow.com/questions/2781549/
  54. // removing-input-background-colour-for-chrome-autocomplete#answer-37432260
  55. @mixin text-field-autofill-color($background, $foreground:'') {
  56. @keyframes cdk-text-field-autofill-color-#{$autofill-color-frame-count} {
  57. to {
  58. background: $background;
  59. @if $foreground != '' { color: $foreground; }
  60. }
  61. }
  62. &:-webkit-autofill {
  63. animation: cdk-text-field-autofill-color-#{$autofill-color-frame-count} both;
  64. }
  65. &.cdk-text-field-autofill-monitored:-webkit-autofill {
  66. // Since Chrome 80 we need a 1ms delay for cdk-text-field-autofill-start, or the animationstart
  67. // event won't fire.
  68. animation: cdk-text-field-autofill-start 0s 1ms,
  69. cdk-text-field-autofill-color-#{$autofill-color-frame-count} both;
  70. }
  71. $autofill-color-frame-count: $autofill-color-frame-count + 1 !global;
  72. }
  73. // @deprecated Use `autosize` and `autofill` instead.
  74. @mixin text-field {
  75. @include text-field-autosize();
  76. @include text-field-autofill();
  77. }