|
| 1 | +@import '../core/style/variables'; |
| 2 | +@import '../core/style/vendor-prefixes'; |
| 3 | + |
| 4 | +$mat-date-range-input-separator-spacing: 4px; |
| 5 | +$mat-date-range-input-part-max-width: calc(50% - #{$mat-date-range-input-separator-spacing}); |
| 6 | +$mat-date-range-input-placeholder-transition: |
| 7 | + color $swift-ease-out-duration $swift-ease-out-duration / 3 $swift-ease-out-timing-function; |
| 8 | + |
| 9 | +// Host of the date range input. |
| 10 | +.mat-date-range-input { |
| 11 | + display: block; |
| 12 | + width: 100%; |
| 13 | +} |
| 14 | + |
| 15 | +// Inner container that wraps around all the content. |
| 16 | +.mat-date-range-input-container { |
| 17 | + display: flex; |
| 18 | + align-items: center; |
| 19 | +} |
| 20 | + |
| 21 | +// Text shown between the two inputs. |
| 22 | +.mat-date-range-input-separator { |
| 23 | + margin: 0 $mat-date-range-input-separator-spacing; |
| 24 | + transition: $mat-date-range-input-placeholder-transition; |
| 25 | + |
| 26 | + .mat-form-field-hide-placeholder & { |
| 27 | + color: transparent; |
| 28 | + transition: none; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +// Underlying input inside the range input. |
| 33 | +.mat-date-range-input-inner { |
| 34 | + // Reset the input so it's just a transparent rectangle. |
| 35 | + font: inherit; |
| 36 | + background: transparent; |
| 37 | + color: currentColor; |
| 38 | + border: none; |
| 39 | + outline: none; |
| 40 | + padding: 0; |
| 41 | + margin: 0; |
| 42 | + vertical-align: bottom; |
| 43 | + text-align: inherit; |
| 44 | + -webkit-appearance: none; |
| 45 | + width: 100%; |
| 46 | + |
| 47 | + // Remove IE's default clear and reveal icons. |
| 48 | + &::-ms-clear, |
| 49 | + &::-ms-reveal { |
| 50 | + display: none; |
| 51 | + } |
| 52 | + |
| 53 | + @include input-placeholder { |
| 54 | + transition: $mat-date-range-input-placeholder-transition; |
| 55 | + } |
| 56 | + |
| 57 | + .mat-form-field-hide-placeholder & { |
| 58 | + @include input-placeholder { |
| 59 | + color: transparent !important; |
| 60 | + -webkit-text-fill-color: transparent; |
| 61 | + transition: none; |
| 62 | + } |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +// We want the start input to be flush against the separator, no matter how much text it has, but |
| 67 | +// the problem is that inputs have a fixed width. We work around the issue by implementing an |
| 68 | +// auto-resizing input that stretches based on its text, up to a point. It works by having |
| 69 | +// a relatively-positioned wrapper (`.mat-date-range-input-start-wrapper` below) and an absolutely- |
| 70 | +// positioned `input`, as well as a `span` inside the wrapper which mirrors the input's value and |
| 71 | +// placeholder. As the user is typing, the value gets mirrored in the span which causes the wrapper |
| 72 | +// to stretch and the input with it. |
| 73 | +.mat-date-range-input-mirror { |
| 74 | + // Disable user selection so users don't accidentally copy the text via ctrl + A. |
| 75 | + @include user-select(none); |
| 76 | + |
| 77 | + // Hide the element so it doesn't get read out by screen |
| 78 | + // readers and it doesn't show up behind the input. |
| 79 | + visibility: hidden; |
| 80 | + |
| 81 | + // Text inside inputs never wraps so the one in the span shouldn't either. |
| 82 | + white-space: nowrap; |
| 83 | + display: inline-block; |
| 84 | + |
| 85 | + // Prevent the container from collapsing. Make it more |
| 86 | + // than 1px so the input caret doesn't get clipped. |
| 87 | + min-width: 2px; |
| 88 | +} |
| 89 | + |
| 90 | +// Wrapper around the start input. Used to facilitate the auto-resizing input. |
| 91 | +.mat-date-range-input-start-wrapper { |
| 92 | + position: relative; |
| 93 | + overflow: hidden; |
| 94 | + max-width: $mat-date-range-input-part-max-width; |
| 95 | + |
| 96 | + input { |
| 97 | + position: absolute; |
| 98 | + top: 0; |
| 99 | + left: 0; |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +// Wrapper around the end input that makes sure that it has the proper size. |
| 104 | +.mat-date-range-input-end-wrapper { |
| 105 | + flex-grow: 1; |
| 106 | + max-width: $mat-date-range-input-part-max-width; |
| 107 | +} |
| 108 | + |
| 109 | +.mat-form-field-type-mat-date-range-input .mat-form-field-infix { |
| 110 | + // Bump the default width slightly since it's somewhat cramped with two inputs and a separator. |
| 111 | + width: 200px; |
| 112 | +} |
0 commit comments