Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended Form validation states capabilities #31757

Merged
merged 2 commits into from Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion scss/forms/_validation.scss
Expand Up @@ -7,6 +7,6 @@

// scss-docs-start form-validation-states-loop
@each $state, $data in $form-validation-states {
@include form-validation-state($state, map-get($data, color), map-get($data, icon));
@include form-validation-state($state, $data...);
}
// scss-docs-end form-validation-states-loop
19 changes: 13 additions & 6 deletions scss/mixins/_forms.scss
Expand Up @@ -13,7 +13,14 @@
}
}

@mixin form-validation-state($state, $color, $icon) {
@mixin form-validation-state(
$state,
$color,
$icon,
$tooltip-color: color-contrast($color),
$tooltip-bg-color: rgba($color, $form-feedback-tooltip-opacity),
$focus-box-shadow: 0 0 0 $input-focus-width rgba($color, $input-btn-focus-color-opacity)
) {
.#{$state}-feedback {
display: none;
width: 100%;
Expand All @@ -33,8 +40,8 @@
margin-top: .1rem;
@include font-size($form-feedback-tooltip-font-size);
line-height: $form-feedback-tooltip-line-height;
color: color-contrast($color);
background-color: rgba($color, $form-feedback-tooltip-opacity);
color: $tooltip-color;
background-color: $tooltip-bg-color;
@include border-radius($form-feedback-tooltip-border-radius);
}

Expand All @@ -59,7 +66,7 @@

&:focus {
border-color: $color;
box-shadow: 0 0 0 $input-focus-width rgba($color, $input-btn-focus-color-opacity);
box-shadow: $focus-box-shadow;
}
}
}
Expand Down Expand Up @@ -87,7 +94,7 @@

&:focus {
border-color: $color;
box-shadow: 0 0 0 $input-focus-width rgba($color, .25);
box-shadow: $focus-box-shadow;
}
}
}
Expand All @@ -101,7 +108,7 @@
}

&:focus {
box-shadow: 0 0 0 $input-focus-width rgba($color, .25);
box-shadow: $focus-box-shadow;
}

~ .form-check-label {
Expand Down
4 changes: 3 additions & 1 deletion site/content/docs/5.0/forms/validation.md
Expand Up @@ -351,14 +351,16 @@ If your form layout allows it, you can swap the `.{valid|invalid}-feedback` clas

## Customizing

Validation states can be customized via Sass with the `$form-validation-states` map. Located in our `_variables.scss` file, this Sass map is looped over to generate the default `valid`/`invalid` validation states. Included is a nested map for customizing each state's color and icon. While no other states are supported by browsers, those using custom styles can easily add more complex form feedback.
Validation states can be customized via Sass with the `$form-validation-states` map. Located in our `_variables.scss` file, this Sass map is how we generate the default `valid`/`invalid` validation states. Included is a nested map for customizing each state's color, icon, tooltip color, and focus shadow. While no other states are supported by browsers, those using custom styles can easily add more complex form feedback.

Please note that we do not recommend customizing these values without also modifying the `form-validation-state` mixin.
ydmitry marked this conversation as resolved.
Show resolved Hide resolved

This is the Sass map from `_variables.scss`. Override this and recompile your Sass to generate different states:

{{< scss-docs name="form-validation-states" file="scss/_variables.scss" >}}

Maps of `$form-validation-states` can contain three optional parameters to override tooltips and focus styles.

This is the loop from `forms/_validation.scss`. Any modifications to the above Sass map will be reflected in your compiled CSS via this loop:

{{< scss-docs name="form-validation-states-loop" file="scss/forms/_validation.scss" >}}
1 change: 1 addition & 0 deletions site/content/docs/5.0/migration.md
Expand Up @@ -12,6 +12,7 @@ toc: true
### Sass

- Extended the `.visually-hidden-focusable` helper to also work on containers, using `:focus-within`.
- Extended form validation states customization capabilities. Added three new optional parameters to the `form-validation-state` mixin: `tooltip-color`, `tooltip-bg-color`, `focus-box-shadow`. These parameters can be set in the `$form-validation-states` map. [See #31757](https://github.com/twbs/bootstrap/pull/31757).

### JavaScript

Expand Down