_input-group.scss 4.8 KB

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