_input-group.scss 6.37 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
1
2
// stylelint-disable selector-no-qualifying-type

3
//
Mark Otto's avatar
Mark Otto committed
4
// Base styles
5
6
//

Mark Otto's avatar
Mark Otto committed
7
.input-group {
8
  position: relative;
9
  display: flex;
10
  flex-wrap: wrap; // For form validation feedback
11
  align-items: stretch;
12
  width: 100%;
13

14
  > .form-control,
15
  > .form-control-plaintext,
16
17
  > .custom-select,
  > .custom-file {
18
    position: relative; // For focus state's z-index
19
20
    flex: 1 1 auto;
    width: 1%;
21
    min-width: 0; // https://stackoverflow.com/questions/36247140/why-dont-flex-items-shrink-past-content-size
22
23
    margin-bottom: 0;

24
25
26
    + .form-control,
    + .custom-select,
    + .custom-file {
27
      margin-left: -$input-border-width;
Chris Rebert's avatar
Chris Rebert committed
28
    }
Mark Otto's avatar
Mark Otto committed
29
30
  }

ysds's avatar
ysds committed
31
32
33
34
35
36
37
  // Bring the "active" form control to the top of surrounding elements
  > .form-control:focus,
  > .custom-select:focus,
  > .custom-file .custom-file-input:focus ~ .custom-file-label {
    z-index: 3;
  }

38
39
40
41
42
  // Bring the custom file input above the label
  > .custom-file .custom-file-input:focus {
    z-index: 4;
  }

43
44
  > .form-control,
  > .custom-select {
45
    &:not(:first-child) { @include border-left-radius(0); }
46
  }
47

48
49
  // Custom file inputs have more complex markup, thus requiring different
  // border-radius overrides.
50
  > .custom-file {
51
52
53
    display: flex;
    align-items: center;

ysds's avatar
ysds committed
54
    &:not(:last-child) .custom-file-label,
55
    &:not(:last-child) .custom-file-label::after { @include border-right-radius(0); }
56
    &:not(:first-child) .custom-file-label { @include border-left-radius(0); }
57
  }
58
59
60
61

  &:not(.has-validation) {
    > .form-control:not(:last-child),
    > .custom-select:not(:last-child),
62
    > .custom-file:not(:last-child) .custom-file-label,
63
64
65
66
67
68
69
70
    > .custom-file:not(:last-child) .custom-file-label::after {
      @include border-right-radius(0);
    }
  }

  &.has-validation {
    > .form-control:nth-last-child(n + 3),
    > .custom-select:nth-last-child(n + 3),
71
    > .custom-file:nth-last-child(n + 3) .custom-file-label,
72
73
74
75
    > .custom-file:nth-last-child(n + 3) .custom-file-label::after {
      @include border-right-radius(0);
    }
  }
76
77
}

78
79
80
81
82
83
84
85
86

// Prepend and append
//
// While it requires one extra layer of HTML for each, dedicated prepend and
// append elements allow us to 1) be less clever, 2) simplify our selectors, and
// 3) support HTML5 form validation.

.input-group-prepend,
.input-group-append {
87
88
  display: flex;

89
90
91
92
93
94
  // Ensure buttons are always above inputs for more visually pleasing borders.
  // This isn't needed for `.input-group-text` since it shares the same border-color
  // as our inputs.
  .btn {
    position: relative;
    z-index: 2;
95
96
97
98

    &:focus {
      z-index: 3;
    }
99
  }
100

101
102
103
104
105
106
  .btn + .btn,
  .btn + .input-group-text,
  .input-group-text + .input-group-text,
  .input-group-text + .btn {
    margin-left: -$input-border-width;
  }
107
108
}

109
110
.input-group-prepend { margin-right: -$input-border-width; }
.input-group-append { margin-left: -$input-border-width; }
111
112


113
// Textual addons
114
//
115
116
// Serves as a catch-all element for any text or radio/checkbox input you wish
// to prepend or append to an input.
117

118
.input-group-text {
119
120
  display: flex;
  align-items: center;
121
  padding: $input-padding-y $input-padding-x;
122
  margin-bottom: 0; // Allow use of <label> elements by overriding our default margin-bottom
123
  @include font-size($input-font-size); // Match inputs
124
  font-weight: $font-weight-normal;
125
  line-height: $input-line-height;
126
  color: $input-group-addon-color;
Mark Otto's avatar
Mark Otto committed
127
  text-align: center;
128
  white-space: nowrap;
Mark Otto's avatar
Mark Otto committed
129
  background-color: $input-group-addon-bg;
130
  border: $input-border-width solid $input-group-addon-border-color;
131
  @include border-radius($input-border-radius);
Mark Otto's avatar
Mark Otto committed
132
133
134
135
136
137
138
139

  // Nuke default margins from checkboxes and radios to vertically center within.
  input[type="radio"],
  input[type="checkbox"] {
    margin-top: 0;
  }
}

140

141
// Sizing
142
//
143
144
// Remix the default form control sizing classes into new ones for easier
// manipulation.
145

146
147
148
149
150
.input-group-lg > .form-control:not(textarea),
.input-group-lg > .custom-select {
  height: $input-height-lg;
}

151
.input-group-lg > .form-control,
152
.input-group-lg > .custom-select,
153
154
155
156
.input-group-lg > .input-group-prepend > .input-group-text,
.input-group-lg > .input-group-append > .input-group-text,
.input-group-lg > .input-group-prepend > .btn,
.input-group-lg > .input-group-append > .btn {
Mark Otto's avatar
Mark Otto committed
157
  padding: $input-padding-y-lg $input-padding-x-lg;
158
  @include font-size($input-font-size-lg);
Mark Otto's avatar
Mark Otto committed
159
160
  line-height: $input-line-height-lg;
  @include border-radius($input-border-radius-lg);
Mark Otto's avatar
Mark Otto committed
161
}
162

163
164
165
166
167
.input-group-sm > .form-control:not(textarea),
.input-group-sm > .custom-select {
  height: $input-height-sm;
}

168
.input-group-sm > .form-control,
169
.input-group-sm > .custom-select,
170
171
172
173
.input-group-sm > .input-group-prepend > .input-group-text,
.input-group-sm > .input-group-append > .input-group-text,
.input-group-sm > .input-group-prepend > .btn,
.input-group-sm > .input-group-append > .btn {
Mark Otto's avatar
Mark Otto committed
174
  padding: $input-padding-y-sm $input-padding-x-sm;
175
  @include font-size($input-font-size-sm);
Mark Otto's avatar
Mark Otto committed
176
177
  line-height: $input-line-height-sm;
  @include border-radius($input-border-radius-sm);
Mark Otto's avatar
Mark Otto committed
178
}
179

180
181
.input-group-lg > .custom-select,
.input-group-sm > .custom-select {
182
  padding-right: $custom-select-padding-x + $custom-select-indicator-padding;
183
184
}

Mark Otto's avatar
Mark Otto committed
185

186
// Prepend and append rounded corners
187
//
188
189
190
// These rulesets must come after the sizing ones to properly override sm and lg
// border-radius values when extending. They're more specific than we'd like
// with the `.input-group >` part, but without it, we cannot override the sizing.
191

192

193
.input-group > .input-group-prepend > .btn,
194
.input-group > .input-group-prepend > .input-group-text,
195
196
197
198
.input-group:not(.has-validation) > .input-group-append:not(:last-child) > .btn,
.input-group:not(.has-validation) > .input-group-append:not(:last-child) > .input-group-text,
.input-group.has-validation > .input-group-append:nth-last-child(n + 3) > .btn,
.input-group.has-validation > .input-group-append:nth-last-child(n + 3) > .input-group-text,
199
200
.input-group > .input-group-append:last-child > .btn:not(:last-child):not(.dropdown-toggle),
.input-group > .input-group-append:last-child > .input-group-text:not(:last-child) {
201
202
  @include border-right-radius(0);
}
203

204
205
206
207
208
209
210
.input-group > .input-group-append > .btn,
.input-group > .input-group-append > .input-group-text,
.input-group > .input-group-prepend:not(:first-child) > .btn,
.input-group > .input-group-prepend:not(:first-child) > .input-group-text,
.input-group > .input-group-prepend:first-child > .btn:not(:first-child),
.input-group > .input-group-prepend:first-child > .input-group-text:not(:first-child) {
  @include border-left-radius(0);
Mark Otto's avatar
Mark Otto committed
211
}