/
date-range-input.scss
142 lines (120 loc) · 4.47 KB
/
date-range-input.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
@use '../core/style/variables';
@use '../core/style/vendor-prefixes';
@use '../core/style/private';
@use '../../cdk/a11y';
$date-range-input-separator-spacing: 4px;
$date-range-input-part-max-width: calc(50% - #{$date-range-input-separator-spacing});
@mixin _placeholder-transition($property) {
transition: #{$property} variables.$swift-ease-out-duration
private.private-div(variables.$swift-ease-out-duration, 3)
variables.$swift-ease-out-timing-function;
}
// Host of the date range input.
.mat-date-range-input {
display: block;
width: 100%;
}
// Inner container that wraps around all the content.
.mat-date-range-input-container {
display: flex;
align-items: center;
}
// Text shown between the two inputs.
.mat-date-range-input-separator {
@include _placeholder-transition(opacity);
margin: 0 $date-range-input-separator-spacing;
}
.mat-date-range-input-separator-hidden {
// Disable text selection, because the user can click
// through the main label when the input is disabled.
@include vendor-prefixes.user-select(none);
// Use opacity to hide the text, because `color: transparent` will be shown in high contrast mode.
opacity: 0;
transition: none;
}
// Underlying input inside the range input.
.mat-date-range-input-inner {
// Reset the input so it's just a transparent rectangle.
font: inherit;
background: transparent;
color: currentColor;
border: none;
outline: none;
padding: 0;
margin: 0;
vertical-align: bottom;
text-align: inherit;
-webkit-appearance: none;
width: 100%;
// Remove IE's default clear and reveal icons.
&::-ms-clear,
&::-ms-reveal {
display: none;
}
// Undo the red box-shadow glow added by Firefox on invalid inputs.
// See https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-ui-invalid
&:-moz-ui-invalid {
box-shadow: none;
}
@include vendor-prefixes.input-placeholder {
@include _placeholder-transition(color);
}
.mat-form-field-hide-placeholder &,
.mat-date-range-input-hide-placeholders & {
@include vendor-prefixes.input-placeholder {
// Disable text selection, because the user can click
// through the main label when the input is disabled.
@include vendor-prefixes.user-select(none);
// Needs to be !important, because the placeholder will end up inheriting the
// input color in IE, if the consumer overrides it with a higher specificity.
color: transparent !important;
-webkit-text-fill-color: transparent;
transition: none;
@include a11y.high-contrast(active, off) {
// In high contrast mode the browser will render the
// placeholder despite the `color: transparent` above.
opacity: 0;
}
}
}
}
// We want the start input to be flush against the separator, no matter how much text it has, but
// the problem is that inputs have a fixed width. We work around the issue by implementing an
// auto-resizing input that stretches based on its text, up to a point. It works by having
// a relatively-positioned wrapper (`.mat-date-range-input-start-wrapper` below) and an absolutely-
// positioned `input`, as well as a `span` inside the wrapper which mirrors the input's value and
// placeholder. As the user is typing, the value gets mirrored in the span which causes the wrapper
// to stretch and the input with it.
.mat-date-range-input-mirror {
// Disable user selection so users don't accidentally copy the text via ctrl + A.
@include vendor-prefixes.user-select(none);
// Hide the element so it doesn't get read out by screen
// readers and it doesn't show up behind the input.
visibility: hidden;
// Text inside inputs never wraps so the one in the span shouldn't either.
white-space: nowrap;
display: inline-block;
// Prevent the container from collapsing. Make it more
// than 1px so the input caret doesn't get clipped.
min-width: 2px;
}
// Wrapper around the start input. Used to facilitate the auto-resizing input.
.mat-date-range-input-start-wrapper {
position: relative;
overflow: hidden;
max-width: $date-range-input-part-max-width;
.mat-date-range-input-inner {
position: absolute;
top: 0;
left: 0;
}
}
// Wrapper around the end input that makes sure that it has the proper size.
.mat-date-range-input-end-wrapper {
flex-grow: 1;
max-width: $date-range-input-part-max-width;
}
.mat-form-field-type-mat-date-range-input .mat-form-field-infix {
// Bump the default width slightly since it's somewhat cramped with two inputs and a separator.
width: 200px;
}