_input-group.scss 5.42 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
20
    margin-bottom: 0;

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

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

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

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

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

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

57
58
59
60
61
62
63
64
65

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

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

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

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

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


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

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

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

119

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

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

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

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

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

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

Mark Otto's avatar
Mark Otto committed
164

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

171

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

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