Skip to content

Commit 71cbb88

Browse files
mdo719media
andauthoredJul 18, 2022
Support input groups in floating forms (#36759)
* Support input groups in floating forms * Update bundlewatch Co-authored-by: 719media <ben@719media.com>
1 parent 6d101b1 commit 71cbb88

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed
 

‎.bundlewatch.config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
{
3232
"path": "./dist/css/bootstrap.min.css",
33-
"maxSize": "26.5 kB"
33+
"maxSize": "26.75 kB"
3434
},
3535
{
3636
"path": "./dist/js/bootstrap.bundle.js",

‎scss/forms/_input-group.scss

+15-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
width: 100%;
1111

1212
> .form-control,
13-
> .form-select {
13+
> .form-select,
14+
> .form-floating {
1415
position: relative; // For focus state's z-index
1516
flex: 1 1 auto;
1617
width: 1%;
@@ -19,7 +20,8 @@
1920

2021
// Bring the "active" form control to the top of surrounding elements
2122
> .form-control:focus,
22-
> .form-select:focus {
23+
> .form-select:focus,
24+
> .form-floating:focus-within {
2325
z-index: 3;
2426
}
2527

@@ -96,15 +98,19 @@
9698
// stylelint-disable-next-line no-duplicate-selectors
9799
.input-group {
98100
&:not(.has-validation) {
99-
> :not(:last-child):not(.dropdown-toggle):not(.dropdown-menu),
100-
> .dropdown-toggle:nth-last-child(n + 3) {
101+
> :not(:last-child):not(.dropdown-toggle):not(.dropdown-menu):not(.form-floating),
102+
> .dropdown-toggle:nth-last-child(n + 3),
103+
> .form-floating:not(:last-child) > .form-control,
104+
> .form-floating:not(:last-child) > .form-select {
101105
@include border-end-radius(0);
102106
}
103107
}
104108

105109
&.has-validation {
106-
> :nth-last-child(n + 3):not(.dropdown-toggle):not(.dropdown-menu),
107-
> .dropdown-toggle:nth-last-child(n + 4) {
110+
> :nth-last-child(n + 3):not(.dropdown-toggle):not(.dropdown-menu):not(.form-floating),
111+
> .dropdown-toggle:nth-last-child(n + 4),
112+
> .form-floating:nth-last-child(n + 3) > .form-control,
113+
> .form-floating:nth-last-child(n + 3) > .form-select {
108114
@include border-end-radius(0);
109115
}
110116
}
@@ -114,7 +120,9 @@
114120
$validation-messages: $validation-messages + ":not(." + unquote($state) + "-tooltip)" + ":not(." + unquote($state) + "-feedback)";
115121
}
116122

117-
> :not(:first-child):not(.dropdown-menu)#{$validation-messages} {
123+
> :not(:first-child):not(.dropdown-menu):not(.form-floating)#{$validation-messages},
124+
> .form-floating:not(:first-child) > .form-control,
125+
> .form-floating:not(:first-child) > .form-select {
118126
margin-left: -$input-border-width;
119127
@include border-start-radius(0);
120128
}

‎site/content/docs/5.2/forms/floating-labels.md

+29
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,35 @@ Floating labels also support `.form-control-plaintext`, which can be helpful for
9090
</div>
9191
{{< /example >}}
9292

93+
## Input groups
94+
95+
Floating labels also support `.input-group`.
96+
97+
{{< example >}}
98+
<div class="input-group mb-3">
99+
<span class="input-group-text">@</span>
100+
<div class="form-floating">
101+
<input type="text" class="form-control" id="floatingInputGroup1" placeholder="Username">
102+
<label for="floatingInputGroup1">Username</label>
103+
</div>
104+
</div>
105+
{{< /example >}}
106+
107+
When using `.input-group` and `.form-floating` along with form validation, the `-feedback` should be placed outside of the `.form-floating`, but inside of the `.input-group`. This means that the feedback will need to be shown using javascript.
108+
109+
{{< example >}}
110+
<div class="input-group has-validation">
111+
<span class="input-group-text">@</span>
112+
<div class="form-floating is-invalid">
113+
<input type="text" class="form-control is-invalid" id="floatingInputGroup2" placeholder="Username" required>
114+
<label for="floatingInputGroup2">Username</label>
115+
</div>
116+
<div class="invalid-feedback">
117+
Please choose a username.
118+
</div>
119+
</div>
120+
{{< /example >}}
121+
93122
## Layout
94123

95124
When working with the Bootstrap grid system, be sure to place form elements within column classes.

0 commit comments

Comments
 (0)
Please sign in to comment.