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