Compare commits

...

5 Commits

Author SHA1 Message Date
Mark Otto
09520f9d08
Merge 8446581c3d08c7ac0633e039aaf5e33084710925 into 380a1d738b221fecc964260add053997399be4d4 2025-09-27 16:38:36 +01:00
Julien Déramond
8446581c3d
Add new Sass mixins to the documentation 2025-09-04 22:34:24 +02:00
Julien Déramond
8915efae15
Fix docs compilation to avoid duplicate IDs 2025-09-04 22:30:39 +02:00
louismaxime.piton
72ee1af96a
Proposal 2025-09-04 22:25:14 +02:00
Mark Otto
f0700c7c3c
Add option for always visible floating labels 2025-09-04 22:22:03 +02:00
3 changed files with 70 additions and 8 deletions

View File

@ -36,21 +36,23 @@
color: transparent; color: transparent;
} }
&:focus::placeholder {
color: $input-placeholder-color;
}
&:focus, &:focus,
&:not(:placeholder-shown) { &:not(:placeholder-shown) {
padding-top: $form-floating-input-padding-t; @include form-floating-active-input-styles();
padding-bottom: $form-floating-input-padding-b;
} }
// Duplicated because `:-webkit-autofill` invalidates other selectors when grouped // Duplicated because `:-webkit-autofill` invalidates other selectors when grouped
&:-webkit-autofill { &:-webkit-autofill {
padding-top: $form-floating-input-padding-t; @include form-floating-active-input-styles();
padding-bottom: $form-floating-input-padding-b;
} }
} }
> .form-select { > .form-select {
padding-top: $form-floating-input-padding-t; @include form-floating-active-input-styles();
padding-bottom: $form-floating-input-padding-b;
padding-left: $form-floating-padding-x; padding-left: $form-floating-padding-x;
} }
@ -59,13 +61,23 @@
> .form-control-plaintext, > .form-control-plaintext,
> .form-select { > .form-select {
~ label { ~ label {
transform: $form-floating-label-transform; @include form-floating-active-label-styles();
&::after {
position: absolute;
inset: $form-floating-padding-y ($form-floating-padding-x * .5);
z-index: -1;
height: $form-floating-label-height;
content: "";
background-color: $input-bg;
@include border-radius($input-border-radius);
}
} }
} }
// Duplicated because `:-webkit-autofill` invalidates other selectors when grouped // Duplicated because `:-webkit-autofill` invalidates other selectors when grouped
> .form-control:-webkit-autofill { > .form-control:-webkit-autofill {
~ label { ~ label {
transform: $form-floating-label-transform; @include form-floating-active-label-styles();
} }
} }
> textarea:focus, > textarea:focus,
@ -95,3 +107,22 @@
color: $form-floating-label-disabled-color; color: $form-floating-label-disabled-color;
} }
} }
// Todo in v6: Consider combining this with the .form-control-plaintext rules to reduce some CSS?
.form-floating-always {
&.form-floating,
.form-floating {
.form-control {
@include form-floating-active-input-styles();
&::placeholder,
&:focus::placeholder {
color: $input-placeholder-color;
}
}
label {
@include form-floating-active-label-styles();
}
}
}

View File

@ -1,6 +1,18 @@
// This mixin uses an `if()` technique to be compatible with Dart Sass // This mixin uses an `if()` technique to be compatible with Dart Sass
// See https://github.com/sass/sass/issues/1873#issuecomment-152293725 for more details // See https://github.com/sass/sass/issues/1873#issuecomment-152293725 for more details
// scss-docs-start form-floating-mixins
@mixin form-floating-active-input-styles() {
padding-top: $form-floating-input-padding-t;
padding-bottom: $form-floating-input-padding-b;
}
@mixin form-floating-active-label-styles() {
color: rgba(var(--#{$prefix}body-color-rgb), #{$form-floating-label-opacity});
transform: $form-floating-label-transform;
}
// scss-docs-end form-floating-mixins
// scss-docs-start form-validation-mixins // scss-docs-start form-validation-mixins
@mixin form-validation-state-selector($state) { @mixin form-validation-state-selector($state) {
@if ($state == "valid" or $state == "invalid") { @if ($state == "valid" or $state == "invalid") {

View File

@ -129,6 +129,19 @@ When using `.input-group` and `.form-floating` along with form validation, the `
</div> </div>
</div>`} /> </div>`} />
## Always floating
Make any `.form-control` always use a floating label with visible placeholder with the `.form-floating-always` modifier class. Visible placeholders use the default input `color` and lighten to the placeholder color on focus. This matches them with other floating labels built with plaintext inputs and selects.
<Example code={`<div class="form-floating form-floating-always mb-3">
<input type="email" class="form-control" id="alwaysFloatingInput" placeholder="name@example.com">
<label for="alwaysFloatingInput">Email address</label>
</div>
<div class="form-floating form-floating-always">
<input type="password" class="form-control" id="alwaysFloatingPassword" placeholder="••••••••">
<label for="alwaysFloatingPassword">Password</label>
</div>`} />
## Layout ## Layout
When working with the Bootstrap grid system, be sure to place form elements within column classes. When working with the Bootstrap grid system, be sure to place form elements within column classes.
@ -158,3 +171,9 @@ When working with the Bootstrap grid system, be sure to place form elements with
### Sass variables ### Sass variables
<ScssDocs name="form-floating-variables" file="scss/_variables.scss" /> <ScssDocs name="form-floating-variables" file="scss/_variables.scss" />
### Sass mixins
<AddedIn version="5.4.0" />
<ScssDocs name="form-floating-mixins" file="scss/mixins/_forms.scss" removeIndentation={false} />