_input-group.scss 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // stylelint-disable selector-no-qualifying-type
  2. //
  3. // Base styles
  4. //
  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. background: #000;
  12. > .form-control,
  13. > .form-control-plaintext,
  14. > .custom-select,
  15. > .custom-file {
  16. position: relative; // For focus state's z-index
  17. flex: 1 1 auto;
  18. width: 1%;
  19. min-width: 0; // https://stackoverflow.com/questions/36247140/why-dont-flex-items-shrink-past-content-size
  20. margin-bottom: 0;
  21. + .form-control,
  22. + .custom-select,
  23. + .custom-file {
  24. margin-left: -$input-border-width;
  25. }
  26. }
  27. // Bring the "active" form control to the top of surrounding elements
  28. > .form-control:focus,
  29. > .custom-select:focus,
  30. > .custom-file .custom-file-input:focus ~ .custom-file-label {
  31. z-index: 3;
  32. }
  33. // Bring the custom file input above the label
  34. > .custom-file .custom-file-input:focus {
  35. z-index: 4;
  36. }
  37. > .form-control,
  38. > .custom-select {
  39. &:not(:first-child) {
  40. @include border-left-radius(0);
  41. }
  42. }
  43. // Custom file inputs have more complex markup, thus requiring different
  44. // border-radius overrides.
  45. > .custom-file {
  46. display: flex;
  47. align-items: center;
  48. &:not(:last-child) .custom-file-label,
  49. &:not(:first-child) .custom-file-label {
  50. @include border-left-radius(0);
  51. }
  52. }
  53. &:not(.has-validation) {
  54. > .form-control:not(:last-child),
  55. > .custom-select:not(:last-child),
  56. > .custom-file:not(:last-child) .custom-file-label::after {
  57. @include border-right-radius(0);
  58. }
  59. }
  60. &.has-validation {
  61. > .form-control:nth-last-child(n + 3),
  62. > .custom-select:nth-last-child(n + 3),
  63. > .custom-file:nth-last-child(n + 3) .custom-file-label::after {
  64. @include border-right-radius(0);
  65. }
  66. }
  67. }
  68. // Prepend and append
  69. //
  70. // While it requires one extra layer of HTML for each, dedicated prepend and
  71. // append elements allow us to 1) be less clever, 2) simplify our selectors, and
  72. // 3) support HTML5 form validation.
  73. .input-group-prepend,
  74. .input-group-append {
  75. display: flex;
  76. // Ensure buttons are always above inputs for more visually pleasing borders.
  77. // This isn't needed for `.input-group-text` since it shares the same border-color
  78. // as our inputs.
  79. .btn {
  80. position: relative;
  81. z-index: 2;
  82. &:focus {
  83. z-index: 3;
  84. }
  85. }
  86. .btn + .btn,
  87. .btn + .input-group-text,
  88. .input-group-text + .input-group-text,
  89. .input-group-text + .btn {
  90. margin-left: -$input-border-width;
  91. }
  92. }
  93. .input-group-prepend {
  94. margin-right: -$input-border-width;
  95. }
  96. .input-group-append {
  97. margin-left: -$input-border-width;
  98. }
  99. // Textual addons
  100. //
  101. // Serves as a catch-all element for any text or radio/checkbox input you wish
  102. // to prepend or append to an input.
  103. .input-group-text {
  104. display: flex;
  105. align-items: center;
  106. padding: $input-padding-y $input-padding-x;
  107. margin-bottom: 0; // Allow use of <label> elements by overriding our default margin-bottom
  108. @include font-size($input-font-size); // Match inputs
  109. font-weight: $font-weight-normal;
  110. line-height: $input-line-height;
  111. color: $input-group-addon-color;
  112. text-align: center;
  113. white-space: nowrap;
  114. background-color: $input-group-addon-bg;
  115. border: $input-border-width solid $input-group-addon-border-color;
  116. @include border-radius($input-border-radius);
  117. // Nuke default margins from checkboxes and radios to vertically center within.
  118. input[type="radio"],
  119. input[type="checkbox"] {
  120. margin-top: 0;
  121. }
  122. }
  123. // Sizing
  124. //
  125. // Remix the default form control sizing classes into new ones for easier
  126. // manipulation.
  127. .input-group-lg > .form-control:not(textarea),
  128. .input-group-lg > .custom-select {
  129. height: $input-height-lg;
  130. }
  131. .input-group-lg > .form-control,
  132. .input-group-lg > .custom-select,
  133. .input-group-lg > .input-group-prepend > .input-group-text,
  134. .input-group-lg > .input-group-append > .input-group-text,
  135. .input-group-lg > .input-group-prepend > .btn,
  136. .input-group-lg > .input-group-append > .btn {
  137. padding: $input-padding-y-lg $input-padding-x-lg;
  138. @include font-size($input-font-size-lg);
  139. line-height: $input-line-height-lg;
  140. @include border-radius($input-border-radius-lg);
  141. }
  142. .input-group-sm > .form-control:not(textarea),
  143. .input-group-sm > .custom-select {
  144. height: $input-height-sm;
  145. }
  146. .input-group-sm > .form-control,
  147. .input-group-sm > .custom-select,
  148. .input-group-sm > .input-group-prepend > .input-group-text,
  149. .input-group-sm > .input-group-append > .input-group-text,
  150. .input-group-sm > .input-group-prepend > .btn,
  151. .input-group-sm > .input-group-append > .btn {
  152. padding: $input-padding-y-sm $input-padding-x-sm;
  153. @include font-size($input-font-size-sm);
  154. line-height: $input-line-height-sm;
  155. @include border-radius($input-border-radius-sm);
  156. }
  157. .input-group-lg > .custom-select,
  158. .input-group-sm > .custom-select {
  159. padding-right: $custom-select-padding-x + $custom-select-indicator-padding;
  160. }
  161. // Prepend and append rounded corners
  162. //
  163. // These rulesets must come after the sizing ones to properly override sm and lg
  164. // border-radius values when extending. They're more specific than we'd like
  165. // with the `.input-group >` part, but without it, we cannot override the sizing.
  166. .input-group > .input-group-prepend > .btn,
  167. .input-group > .input-group-prepend > .input-group-text,
  168. .input-group:not(.has-validation) > .input-group-append:not(:last-child) > .btn,
  169. .input-group:not(.has-validation) > .input-group-append:not(:last-child) > .input-group-text,
  170. .input-group.has-validation > .input-group-append:nth-last-child(n + 3) > .btn,
  171. .input-group.has-validation > .input-group-append:nth-last-child(n + 3) > .input-group-text,
  172. .input-group > .input-group-append:last-child > .btn:not(:last-child):not(.dropdown-toggle),
  173. .input-group > .input-group-append:last-child > .input-group-text:not(:last-child) {
  174. @include border-right-radius(0);
  175. }
  176. .input-group > .input-group-append > .btn,
  177. .input-group > .input-group-append > .input-group-text,
  178. .input-group > .input-group-prepend:not(:first-child) > .btn,
  179. .input-group > .input-group-prepend:not(:first-child) > .input-group-text,
  180. .input-group > .input-group-prepend:first-child > .btn:not(:first-child),
  181. .input-group > .input-group-prepend:first-child > .input-group-text:not(:first-child) {
  182. @include border-left-radius(0);
  183. }