_input-group.scss 5.7 KB

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