_input-group.scss 4.75 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
15
16
  > .form-control,
  > .custom-select,
  > .custom-file {
17
    position: relative; // For focus state's z-index
18
19
    flex: 1 1 auto;
    // Add width 1% and flex-basis auto to ensure that button will not wrap out
20
    // the column. Applies to IE Edge+ and Firefox. Chrome does not require this.
21
22
23
    width: 1%;
    margin-bottom: 0;

24
25
26
27
28
    // Bring the "active" form control to the top of surrounding elements
    &:focus {
      z-index: 3;
    }

29
30
31
    + .form-control,
    + .custom-select,
    + .custom-file {
32
      margin-left: -$input-border-width;
Chris Rebert's avatar
Chris Rebert committed
33
    }
Mark Otto's avatar
Mark Otto committed
34
35
  }

36
37
  > .form-control,
  > .custom-select {
38
39
    &:not(:last-child) { @include border-right-radius(0); }
    &:not(:first-child) { @include border-left-radius(0); }
40
  }
41

42
43
  // Custom file inputs have more complex markup, thus requiring different
  // border-radius overrides.
44
  > .custom-file {
45
46
47
    display: flex;
    align-items: center;

ysds's avatar
ysds committed
48
    &:not(:last-child) .custom-file-label,
49
    &:not(:last-child) .custom-file-label::after { @include border-right-radius(0); }
ysds's avatar
ysds committed
50
    &:not(:first-child) .custom-file-label,
51
    &:not(:first-child) .custom-file-label::after { @include border-left-radius(0); }
52
53
54
  }
}

55
56
57
58
59
60
61
62
63

// 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 {
64
65
  display: flex;

66
67
68
69
70
71
72
  // 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;
  }
73

74
75
76
77
78
79
  .btn + .btn,
  .btn + .input-group-text,
  .input-group-text + .input-group-text,
  .input-group-text + .btn {
    margin-left: -$input-border-width;
  }
80
81
}

82
83
.input-group-prepend { margin-right: -$input-border-width; }
.input-group-append { margin-left: -$input-border-width; }
84
85


86
// Textual addons
87
//
88
89
// Serves as a catch-all element for any text or radio/checkbox input you wish
// to prepend or append to an input.
90

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

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

113

114
// Sizing
115
//
116
117
// Remix the default form control sizing classes into new ones for easier
// manipulation.
118

119
120
121
122
123
124
.input-group-lg > .form-control,
.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 {
  @extend .form-control-lg;
Mark Otto's avatar
Mark Otto committed
125
}
126

127
128
129
130
131
132
.input-group-sm > .form-control,
.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 {
  @extend .form-control-sm;
Mark Otto's avatar
Mark Otto committed
133
}
134

Mark Otto's avatar
Mark Otto committed
135

136
// Prepend and append rounded corners
137
//
138
139
140
// 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.
141

142

143
.input-group > .input-group-prepend > .btn,
144
145
146
147
148
.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) {
149
150
  @include border-right-radius(0);
}
151

152
153
154
155
156
157
158
.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
159
}