You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
6.4 KiB

9 months ago
  1. //
  2. // General form controls (plus a few specific high-level interventions)
  3. //
  4. .form-control {
  5. display: block;
  6. width: 100%;
  7. padding: $input-padding-y $input-padding-x;
  8. font-family: $input-font-family;
  9. @include font-size($input-font-size);
  10. font-weight: $input-font-weight;
  11. line-height: $input-line-height;
  12. color: $input-color;
  13. appearance: none; // Fix appearance for date inputs in Safari
  14. background-color: $input-bg;
  15. background-clip: padding-box;
  16. border: $input-border-width solid $input-border-color;
  17. // Note: This has no effect on <select>s in some browsers, due to the limited stylability of `<select>`s in CSS.
  18. @include border-radius($input-border-radius, 0);
  19. @include box-shadow($input-box-shadow);
  20. @include transition($input-transition);
  21. &[type="file"] {
  22. overflow: hidden; // prevent pseudo element button overlap
  23. &:not(:disabled):not([readonly]) {
  24. cursor: pointer;
  25. }
  26. }
  27. // Customize the `:focus` state to imitate native WebKit styles.
  28. &:focus {
  29. color: $input-focus-color;
  30. background-color: $input-focus-bg;
  31. border-color: $input-focus-border-color;
  32. outline: 0;
  33. @if $enable-shadows {
  34. @include box-shadow($input-box-shadow, $input-focus-box-shadow);
  35. } @else {
  36. // Avoid using mixin so we can pass custom focus shadow properly
  37. box-shadow: $input-focus-box-shadow;
  38. }
  39. }
  40. &::-webkit-date-and-time-value {
  41. // On Android Chrome, form-control's "width: 100%" makes the input width too small
  42. // Tested under Android 11 / Chrome 89, Android 12 / Chrome 100, Android 13 / Chrome 109
  43. //
  44. // On iOS Safari, form-control's "appearance: none" + "width: 100%" makes the input width too small
  45. // Tested under iOS 16.2 / Safari 16.2
  46. min-width: 85px; // Seems to be a good minimum safe width
  47. // Add some height to date inputs on iOS
  48. // https://github.com/twbs/bootstrap/issues/23307
  49. // TODO: we can remove this workaround once https://bugs.webkit.org/show_bug.cgi?id=198959 is resolved
  50. // Multiply line-height by 1em if it has no unit
  51. height: if(unit($input-line-height) == "", $input-line-height * 1em, $input-line-height);
  52. // Android Chrome type="date" is taller than the other inputs
  53. // because of "margin: 1px 24px 1px 4px" inside the shadow DOM
  54. // Tested under Android 11 / Chrome 89, Android 12 / Chrome 100, Android 13 / Chrome 109
  55. margin: 0;
  56. }
  57. // Prevent excessive date input height in Webkit
  58. // https://github.com/twbs/bootstrap/issues/34433
  59. &::-webkit-datetime-edit {
  60. display: block;
  61. padding: 0;
  62. }
  63. // Placeholder
  64. &::placeholder {
  65. color: $input-placeholder-color;
  66. // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526.
  67. opacity: 1;
  68. }
  69. // Disabled inputs
  70. //
  71. // HTML5 says that controls under a fieldset > legend:first-child won't be
  72. // disabled if the fieldset is disabled. Due to implementation difficulty, we
  73. // don't honor that edge case; we style them as disabled anyway.
  74. &:disabled {
  75. color: $input-disabled-color;
  76. background-color: $input-disabled-bg;
  77. border-color: $input-disabled-border-color;
  78. // iOS fix for unreadable disabled content; see https://github.com/twbs/bootstrap/issues/11655.
  79. opacity: 1;
  80. }
  81. // File input buttons theming
  82. &::file-selector-button {
  83. padding: $input-padding-y $input-padding-x;
  84. margin: (-$input-padding-y) (-$input-padding-x);
  85. margin-inline-end: $input-padding-x;
  86. color: $form-file-button-color;
  87. @include gradient-bg($form-file-button-bg);
  88. pointer-events: none;
  89. border-color: inherit;
  90. border-style: solid;
  91. border-width: 0;
  92. border-inline-end-width: $input-border-width;
  93. border-radius: 0; // stylelint-disable-line property-disallowed-list
  94. @include transition($btn-transition);
  95. }
  96. &:hover:not(:disabled):not([readonly])::file-selector-button {
  97. background-color: $form-file-button-hover-bg;
  98. }
  99. }
  100. // Readonly controls as plain text
  101. //
  102. // Apply class to a readonly input to make it appear like regular plain
  103. // text (without any border, background color, focus indicator)
  104. .form-control-plaintext {
  105. display: block;
  106. width: 100%;
  107. padding: $input-padding-y 0;
  108. margin-bottom: 0; // match inputs if this class comes on inputs with default margins
  109. line-height: $input-line-height;
  110. color: $input-plaintext-color;
  111. background-color: transparent;
  112. border: solid transparent;
  113. border-width: $input-border-width 0;
  114. &:focus {
  115. outline: 0;
  116. }
  117. &.form-control-sm,
  118. &.form-control-lg {
  119. padding-right: 0;
  120. padding-left: 0;
  121. }
  122. }
  123. // Form control sizing
  124. //
  125. // Build on `.form-control` with modifier classes to decrease or increase the
  126. // height and font-size of form controls.
  127. //
  128. // Repeated in `_input_group.scss` to avoid Sass extend issues.
  129. .form-control-sm {
  130. min-height: $input-height-sm;
  131. padding: $input-padding-y-sm $input-padding-x-sm;
  132. @include font-size($input-font-size-sm);
  133. @include border-radius($input-border-radius-sm);
  134. &::file-selector-button {
  135. padding: $input-padding-y-sm $input-padding-x-sm;
  136. margin: (-$input-padding-y-sm) (-$input-padding-x-sm);
  137. margin-inline-end: $input-padding-x-sm;
  138. }
  139. }
  140. .form-control-lg {
  141. min-height: $input-height-lg;
  142. padding: $input-padding-y-lg $input-padding-x-lg;
  143. @include font-size($input-font-size-lg);
  144. @include border-radius($input-border-radius-lg);
  145. &::file-selector-button {
  146. padding: $input-padding-y-lg $input-padding-x-lg;
  147. margin: (-$input-padding-y-lg) (-$input-padding-x-lg);
  148. margin-inline-end: $input-padding-x-lg;
  149. }
  150. }
  151. // Make sure textareas don't shrink too much when resized
  152. // https://github.com/twbs/bootstrap/pull/29124
  153. // stylelint-disable selector-no-qualifying-type
  154. textarea {
  155. &.form-control {
  156. min-height: $input-height;
  157. }
  158. &.form-control-sm {
  159. min-height: $input-height-sm;
  160. }
  161. &.form-control-lg {
  162. min-height: $input-height-lg;
  163. }
  164. }
  165. // stylelint-enable selector-no-qualifying-type
  166. .form-control-color {
  167. width: $form-color-width;
  168. height: $input-height;
  169. padding: $input-padding-y;
  170. &:not(:disabled):not([readonly]) {
  171. cursor: pointer;
  172. }
  173. &::-moz-color-swatch {
  174. border: 0 !important; // stylelint-disable-line declaration-no-important
  175. @include border-radius($input-border-radius);
  176. }
  177. &::-webkit-color-swatch {
  178. border: 0 !important; // stylelint-disable-line declaration-no-important
  179. @include border-radius($input-border-radius);
  180. }
  181. &.form-control-sm { height: $input-height-sm; }
  182. &.form-control-lg { height: $input-height-lg; }
  183. }