-
-
Notifications
You must be signed in to change notification settings - Fork 79.2k
Focus ring helper and utilities #33125
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
66f7fc4
Add global variables for box-shadow focus rings
mdo c6df3f1
Update instances of -btn-focus-box-shadow to use -ring-box-shadow, un…
mdo 0ad43c1
fix variable name
mdo 7bb0675
Add CSS variables for global focus styling, document it
mdo ec6ae54
Move to CSS vars section
mdo b7f60be
Update scss/_nav.scss
mdo aa9c24a
Helper and utils
mdo c89b4aa
Fix bundlewatch
julien-deramond cb65c7a
Change 'Focus ring' in sidebar so that the page can be visible
julien-deramond aa28a6a
Minor typo fix
julien-deramond 726e309
fix merge
mdo f1d1111
Revamp some more, improve docs
mdo 916ad4c
Merge branch 'main' into global-focus-vars
patrickhlauke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.focus-ring:focus { | ||
outline: 0; | ||
// By default, there is no `--bs-focus-ring-x`, `--bs-focus-ring-y`, or `--bs-focus-ring-blur`, but we provide CSS variables with fallbacks to initial `0` values | ||
box-shadow: var(--#{$prefix}focus-ring-x, 0) var(--#{$prefix}focus-ring-y, 0) var(--#{$prefix}focus-ring-blur, 0) var(--#{$prefix}focus-ring-width) var(--#{$prefix}focus-ring-color); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
layout: docs | ||
title: Focus ring | ||
description: Utility classes that allows you to add and modify custom focus ring styles to elements and components. | ||
group: helpers | ||
toc: true | ||
added: "5.3" | ||
--- | ||
|
||
The `.focus-ring` helper removes the default `outline` on `:focus`, replacing it with a `box-shadow` that can be more broadly customized. The new shadow is made up of a series of CSS variables, inherited from the `:root` level, that can be modified for any element or component. | ||
|
||
## Example | ||
|
||
Click into the example below and press <kbd>Tab</kbd> to see the focus ring in action. | ||
|
||
{{< example >}} | ||
<a href="#" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2"> | ||
Custom focus ring | ||
</a> | ||
{{< /example >}} | ||
|
||
## Customize | ||
|
||
Modify the styling of a focus ring with our CSS variables, Sass variables, utilities, or custom styles. | ||
|
||
### CSS variables | ||
|
||
Modify the `--bs-focus-ring-*` CSS variables as needed to change the default appearance. | ||
|
||
{{< example >}} | ||
<a href="#" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-color: rgba(var(--bs-success-rgb), .25)"> | ||
Green focus ring | ||
</a> | ||
{{< /example >}} | ||
|
||
`.focus-ring` sets styles via global CSS variables that can be overridden on any parent element, as shown above. These variables are generated from their Sass variable counterparts. | ||
|
||
{{< scss-docs name="root-focus-variables" file="scss/_root.scss" >}} | ||
|
||
### Sass | ||
|
||
Customize the focus ring Sass variables to modify all usage of the focus ring styles across your Bootstrap-powered project. | ||
|
||
{{< scss-docs name="focus-ring-variables" file="scss/_variables.scss" >}} | ||
|
||
### Utilities | ||
|
||
In addition to `.focus-ring`, we have several `.focus-ring-*` utilities to modify the helper class defaults. Modify the color with any of our [theme colors]({{< docsref "/customize/color#theme-colors" >}}). Note that the light and dark variants may not be visible on all background colors given current color mode support. | ||
|
||
{{< example >}} | ||
{{< focus-ring.inline >}} | ||
{{- range (index $.Site.Data "theme-colors") }} | ||
<p><a href="#" class="d-inline-flex focus-ring focus-ring-{{ .name }} py-1 px-2 text-decoration-none border rounded-2">{{ title .name }} focus</a></p> | ||
{{- end -}} | ||
{{< /focus-ring.inline >}} | ||
{{< /example >}} | ||
|
||
Focus ring utilities are declared in our utilities API in `scss/_utilities.scss`. [Learn how to use the utilities API.]({{< docsref "/utilities/api#using-the-api" >}}) | ||
|
||
{{< scss-docs name="utils-focus-ring" file="scss/_utilities.scss" >}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.