Skip to content

Commit 00a77a1

Browse files
authored
Revamp focus ring helper and docs (#42350)
* Revamp focus ring helper and docs * remove util
1 parent c23e913 commit 00a77a1

3 files changed

Lines changed: 11 additions & 42 deletions

File tree

scss/_utilities.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,6 @@ $utilities: map.merge(
114114
)
115115
),
116116
// scss-docs-end utils-shadow
117-
// scss-docs-start utils-focus-ring
118-
"focus-ring": (
119-
// css-var: true,
120-
property: --focus-ring-color,
121-
class: focus-ring,
122-
values: theme-color-values("focus-ring"),
123-
),
124-
// scss-docs-end utils-focus-ring
125117
// scss-docs-start utils-position
126118
"position": (
127119
property: position,

scss/helpers/_focus-ring.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@layer helpers {
22
.focus-ring:focus-visible {
3-
outline: var(--focus-ring);
3+
// outline: var(--focus-ring);
4+
outline: var(--focus-ring-width) solid var(--theme-focus-ring, var(--focus-ring-color));
45
}
56
}

site/src/content/docs/helpers/focus-ring.mdx

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,26 @@ toc: true
66

77
import { getData } from '@libs/data'
88

9-
The `.focus-ring` helper modifies the default `outline` for focus states with one that can be more easily customized. The new focus ring is made up of a series of CSS variables, inherited from the `:root` level, that can be modified for any element or component.
9+
The `.focus-ring` helper modifies the default `outline` for focus states with one that can be more easily customized. Focus ring is made up of a series of CSS variables, inherited from the `:root` level, that can be modified for any element or component.
1010

1111
## Example
1212

13-
Click directly on the link below to see the focus ring in action, or into the example below and then press <kbd>Tab</kbd>.
13+
Tab into the example below to see the focus ring in action, or into the example below and then press <kbd>Tab</kbd>.
1414

1515
<Example code={`<a href="#" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2">
1616
Custom focus ring
1717
</a>`} />
1818

19-
## Customize
19+
## Variants
2020

21-
Modify the styling of a focus ring with our CSS variables, Sass variables, utilities, or custom styles.
21+
Change the color of the focus ring with the [theme color]([[docsref:/customize/theme#theme-colors]]) utility classes. The helper class pulls in the `--bs-theme-focus-ring` CSS variable for the given theme color.
2222

23-
### CSS variables
23+
<Example class="vstack gap-2 align-items-start" code={getData('theme-colors').map((themeColor) => `<a href="#" class="d-inline-flex focus-ring theme-${themeColor.name} py-1 px-2 text-decoration-none border rounded-2">${themeColor.title} focus</a>`)} />
2424

25-
Modify the `--bs-focus-ring-*` CSS variables as needed to change the default appearance.
25+
## Custom colors
2626

27-
<Example code={`<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)">
28-
Green focus ring
29-
</a>`} />
30-
31-
`.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.
32-
33-
<ScssDocs name="root-focus-variables" file="scss/_root.scss" />
27+
Modify the `--bs-focus-ring-color` CSS variable as needed to change the default appearance. Use existing theme variables or your own colors. When using your own colors, we recommend using `light-dark()` for color mode support and `color-mix()` to ensure colors deviate slightly for more contrast on different backgrounds.
3428

35-
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. Modify them to change the default appearance.
36-
37-
<Example code={`<a href="#" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-x: 10px; --bs-focus-ring-y: 10px; --bs-focus-ring-blur: 4px">
38-
Blurry offset focus ring
29+
<Example code={`<a href="#" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-color: var(--bs-success-focus-ring)">
30+
Green focus ring
3931
</a>`} />
40-
41-
### Sass variables
42-
43-
Customize the focus ring Sass variables to modify all usage of the focus ring styles across your Bootstrap-powered project.
44-
45-
{/* <ScssDocs name="focus-ring-variables" file="scss/_config.scss" /> */}
46-
47-
### Sass utilities API
48-
49-
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.
50-
51-
<Example code={getData('theme-colors').map((themeColor) => `<p><a href="#" class="d-inline-flex focus-ring focus-ring-${themeColor.name} py-1 px-2 text-decoration-none border rounded-2">${themeColor.title} focus</a></p>`)} />
52-
53-
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]])
54-
55-
<ScssDocs name="utils-focus-ring" file="scss/_utilities.scss" />

0 commit comments

Comments
 (0)