_input-group.scss 5.53 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,
Mark Otto's avatar
Mark Otto committed
15
16
  > .form-select,
  > .form-file {
17
    position: relative; // For focus state's z-index
18
    flex: 1 1 0%;
19
    min-width: 0; // https://stackoverflow.com/questions/36247140/why-dont-flex-items-shrink-past-content-size
20
21
    margin-bottom: 0;

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

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

36
  // Bring the custom file input above the label
Mark Otto's avatar
Mark Otto committed
37
  > .form-file .form-file-input:focus {
38
39
40
    z-index: 4;
  }

41
  > .form-control,
Mark Otto's avatar
Mark Otto committed
42
  > .form-select {
43
44
    &:not(:last-child) { @include border-right-radius(0); }
    &:not(:first-child) { @include border-left-radius(0); }
45
  }
46

47
48
  // Custom file inputs have more complex markup, thus requiring different
  // border-radius overrides.
Mark Otto's avatar
Mark Otto committed
49
  > .form-file {
50
51
52
    display: flex;
    align-items: center;

Mark Otto's avatar
Mark Otto committed
53
54
    &:not(:last-child) .form-file-label { @include border-right-radius(0); }
    &:not(:first-child) .form-file-label { @include border-left-radius(0); }
55
56
57
  }
}

58
59
60
61
62
63
64
65
66

// 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 {
67
68
  display: flex;

69
70
71
72
73
74
  // 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;
75
76
77
78

    &:focus {
      z-index: 3;
    }
79
  }
80

81
82
83
84
85
86
  .btn + .btn,
  .btn + .input-group-text,
  .input-group-text + .input-group-text,
  .input-group-text + .btn {
    margin-left: -$input-border-width;
  }
87
88
}

89
90
.input-group-prepend { margin-right: -$input-border-width; }
.input-group-append { margin-left: -$input-border-width; }
91
92


93
// Textual addons
94
//
95
96
// Serves as a catch-all element for any text or radio/checkbox input you wish
// to prepend or append to an input.
97

98
.input-group-text {
99
100
  display: flex;
  align-items: center;
101
  padding: $input-padding-y $input-padding-x;
102
  margin-bottom: 0; // Allow use of <label> elements by overriding our default margin-bottom
103
  @include font-size($input-font-size); // Match inputs
104
  font-weight: $font-weight-normal;
105
  line-height: $input-line-height;
106
  color: $input-group-addon-color;
Mark Otto's avatar
Mark Otto committed
107
  text-align: center;
108
  white-space: nowrap;
Mark Otto's avatar
Mark Otto committed
109
  background-color: $input-group-addon-bg;
110
  border: $input-border-width solid $input-group-addon-border-color;
111
  @include border-radius($input-border-radius);
Mark Otto's avatar
Mark Otto committed
112
113
114
115
116
117
118
119

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

120

121
// Sizing
122
//
123
124
// Remix the default form control sizing classes into new ones for easier
// manipulation.
125

126
.input-group-lg > .form-control:not(textarea),
Mark Otto's avatar
Mark Otto committed
127
.input-group-lg > .form-select {
128
129
130
  height: $input-height-lg;
}

131
.input-group-lg > .form-control,
Mark Otto's avatar
Mark Otto committed
132
.input-group-lg > .form-select,
133
134
135
136
.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
137
  padding: $input-padding-y-lg $input-padding-x-lg;
138
  @include font-size($input-font-size-lg);
Mark Otto's avatar
Mark Otto committed
139
140
  line-height: $input-line-height-lg;
  @include border-radius($input-border-radius-lg);
Mark Otto's avatar
Mark Otto committed
141
}
142

143
.input-group-sm > .form-control:not(textarea),
Mark Otto's avatar
Mark Otto committed
144
.input-group-sm > .form-select {
145
146
147
  height: $input-height-sm;
}

148
.input-group-sm > .form-control,
Mark Otto's avatar
Mark Otto committed
149
.input-group-sm > .form-select,
150
151
152
153
.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
154
  padding: $input-padding-y-sm $input-padding-x-sm;
155
  @include font-size($input-font-size-sm);
Mark Otto's avatar
Mark Otto committed
156
157
  line-height: $input-line-height-sm;
  @include border-radius($input-border-radius-sm);
Mark Otto's avatar
Mark Otto committed
158
}
159

Mark Otto's avatar
Mark Otto committed
160
161
162
.input-group-lg > .form-select,
.input-group-sm > .form-select {
  padding-right: $form-select-padding-x + $form-select-indicator-padding;
163
164
}

Mark Otto's avatar
Mark Otto committed
165

166
// Prepend and append rounded corners
167
//
168
169
170
// 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.
171

172

173
.input-group > .input-group-prepend > .btn,
174
175
176
177
178
.input-group > .input-group-prepend > .input-group-text,
.input-group > .input-group-append:not(:last-child) > .btn,
.input-group > .input-group-append:not(:last-child) > .input-group-text,
.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) {
179
180
  @include border-right-radius(0);
}
181

182
183
184
185
186
187
188
.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
189
}