_input-group.scss 3.46 KB
Newer Older
1
//
Mark Otto's avatar
Mark Otto committed
2
// Base styles
3
4
//

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

12
  > .form-control,
Mark Otto's avatar
Mark Otto committed
13
14
  > .form-select,
  > .form-file {
15
    position: relative; // For focus state's z-index
16
17
    flex: 1 1 auto;
    width: 1%;
18
    min-width: 0; // https://stackoverflow.com/questions/36247140/why-dont-flex-items-shrink-past-content-size
Mark Otto's avatar
Mark Otto committed
19
20
  }

ysds's avatar
ysds committed
21
22
  // Bring the "active" form control to the top of surrounding elements
  > .form-control:focus,
Mark Otto's avatar
Mark Otto committed
23
24
  > .form-select:focus,
  > .form-file .form-file-input:focus ~ .form-file-label {
ysds's avatar
ysds committed
25
26
27
    z-index: 3;
  }

28
  // Bring the custom file input above the label
Mark Otto's avatar
Mark Otto committed
29
  > .form-file {
30
31
32
    > .form-file-input:focus {
      z-index: 4;
    }
33

34
35
36
    &:not(:last-child) > .form-file-label {
      @include border-right-radius(0);
    }
37

38
39
40
41
    &:not(:first-child) > .form-file-label {
      @include border-left-radius(0);
    }
  }
42

43
44
45
46
47
48
  // 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;
49
50
51
52

    &:focus {
      z-index: 3;
    }
53
  }
54
55
}

56

57
// Textual addons
58
//
59
60
// Serves as a catch-all element for any text or radio/checkbox input you wish
// to prepend or append to an input.
61

62
.input-group-text {
63
64
  display: flex;
  align-items: center;
65
  padding: $input-group-addon-padding-y $input-group-addon-padding-x;
66
  @include font-size($input-font-size); // Match inputs
67
  font-weight: $input-group-addon-font-weight;
68
  line-height: $input-line-height;
69
  color: $input-group-addon-color;
Mark Otto's avatar
Mark Otto committed
70
  text-align: center;
71
  white-space: nowrap;
Mark Otto's avatar
Mark Otto committed
72
  background-color: $input-group-addon-bg;
73
  border: $input-border-width solid $input-group-addon-border-color;
74
  @include border-radius($input-border-radius);
Mark Otto's avatar
Mark Otto committed
75
76
}

77

78
// Sizing
79
//
80
81
// Remix the default form control sizing classes into new ones for easier
// manipulation.
82

83
.input-group-lg > .form-control {
84
  min-height: $input-height-lg;
85
86
}

87
88
89
90
.input-group-lg > .form-select {
  height: $input-height-lg;
}

91
.input-group-lg > .form-control,
Mark Otto's avatar
Mark Otto committed
92
.input-group-lg > .form-select,
93
94
.input-group-lg > .input-group-text,
.input-group-lg > .btn {
Mark Otto's avatar
Mark Otto committed
95
  padding: $input-padding-y-lg $input-padding-x-lg;
96
  @include font-size($input-font-size-lg);
Mark Otto's avatar
Mark Otto committed
97
  @include border-radius($input-border-radius-lg);
Mark Otto's avatar
Mark Otto committed
98
}
99

100
.input-group-sm > .form-control {
101
  min-height: $input-height-sm;
102
103
}

104
105
106
107
.input-group-sm > .form-select {
  height: $input-height-sm;
}

108
.input-group-sm > .form-control,
Mark Otto's avatar
Mark Otto committed
109
.input-group-sm > .form-select,
110
111
.input-group-sm > .input-group-text,
.input-group-sm > .btn {
Mark Otto's avatar
Mark Otto committed
112
  padding: $input-padding-y-sm $input-padding-x-sm;
113
  @include font-size($input-font-size-sm);
Mark Otto's avatar
Mark Otto committed
114
  @include border-radius($input-border-radius-sm);
Mark Otto's avatar
Mark Otto committed
115
}
116

Mark Otto's avatar
Mark Otto committed
117
118
119
.input-group-lg > .form-select,
.input-group-sm > .form-select {
  padding-right: $form-select-padding-x + $form-select-indicator-padding;
120
121
}

Mark Otto's avatar
Mark Otto committed
122

123
// Rounded corners
124
//
125
126
127
// 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.
128

129
130
131
132
133
134
// stylelint-disable-next-line no-duplicate-selectors
.input-group {
  > :not(:last-child):not(.dropdown-toggle):not(.dropdown-menu),
  > .dropdown-toggle:nth-last-child(n + 3) {
    @include border-right-radius(0);
  }
135

136
137
138
139
  > :not(:first-child):not(.dropdown-menu) {
    margin-left: -$input-border-width;
    @include border-left-radius(0);
  }
Mark Otto's avatar
Mark Otto committed
140
}