Skip to content

Commit 078a1c8

Browse files
committed
Use consistent padding for input and select elements
Only apply extra top padding to textareas where it is needed. Also removed unnecessary floating label background for non-textareas (supersedes #39480).
1 parent 1edcce4 commit 078a1c8

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

scss/_variables.scss

+4-4
Original file line numberDiff line numberDiff line change
@@ -1072,10 +1072,10 @@ $form-floating-height: add(3.5rem, $input-height-border) !defau
10721072
$form-floating-line-height: 1.3125 !default;
10731073
$form-floating-padding-x: $input-padding-x !default;
10741074
$form-floating-padding-y: 1rem !default;
1075-
$form-floating-input-padding-t: 1.625rem !default;
1076-
$form-floating-input-padding-b: .625rem !default;
1077-
$form-floating-select-padding-t: 1.25rem !default;
1078-
$form-floating-select-padding-b: .25rem !default;
1075+
$form-floating-input-padding-t: 1.25rem !default;
1076+
$form-floating-input-padding-b: .25rem !default;
1077+
$form-floating-textarea-padding-t: 1.625rem !default;
1078+
$form-floating-textarea-padding-b: .625rem !default;
10791079
$form-floating-label-height: 1.5em !default;
10801080
$form-floating-label-opacity: .65 !default;
10811081
$form-floating-label-transform: scale(.85) translateY(-.5rem) translateX(.15rem) !default;

scss/forms/_floating-labels.scss

+21-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
}
4848

4949
> .form-select {
50-
padding-top: $form-floating-select-padding-t;
51-
padding-bottom: $form-floating-select-padding-b;
50+
padding-top: $form-floating-input-padding-t;
51+
padding-bottom: $form-floating-input-padding-b;
5252
}
5353

5454
> .form-control:focus,
@@ -65,11 +65,29 @@
6565
z-index: -1;
6666
height: $form-floating-label-height;
6767
content: "";
68-
background-color: $input-bg;
6968
@include border-radius($input-border-radius);
7069
}
7170
}
7271
}
72+
> textarea.form-control {
73+
// textareas require additional top padding to prevent label from overlapping text,
74+
// and additional bottom padding for when text is scrolled.
75+
&:focus,
76+
&:not(:placeholder-shown) {
77+
padding-top: $form-floating-textarea-padding-t;
78+
padding-bottom: $form-floating-textarea-padding-b;
79+
}
80+
// Duplicated because `:-webkit-autofill` invalidates other selectors when grouped
81+
&:-webkit-autofill {
82+
padding-top: $form-floating-textarea-padding-t;
83+
padding-bottom: $form-floating-textarea-padding-b;
84+
}
85+
86+
// set textarea label background so it will remain legible when text is scrolled
87+
~ label::after {
88+
background-color: $input-bg;
89+
}
90+
}
7391
// Duplicated because `:-webkit-autofill` invalidates other selectors when grouped
7492
> .form-control:-webkit-autofill {
7593
~ label {

0 commit comments

Comments
 (0)