diff --git a/scss/helpers/_visually-hidden.scss b/scss/helpers/_visually-hidden.scss index 0a843d383d..4760ff03d1 100644 --- a/scss/helpers/_visually-hidden.scss +++ b/scss/helpers/_visually-hidden.scss @@ -3,6 +3,6 @@ // .visually-hidden, -.visually-hidden-focusable:not(:focus) { +.visually-hidden-focusable:not(:focus):not(:focus-within) { @include visually-hidden(); } diff --git a/scss/mixins/_visually-hidden.scss b/scss/mixins/_visually-hidden.scss index d980696c80..ed7bc9c13a 100644 --- a/scss/mixins/_visually-hidden.scss +++ b/scss/mixins/_visually-hidden.scss @@ -17,12 +17,13 @@ border: 0 !important; } -// Use to only display content when it's focused. +// Use to only display content when it's focused, or one of its child elements is focused +// (i.e. when focus is within the element/container that the class was applied to) // // Useful for "Skip to main content" links; see https://www.w3.org/TR/2013/NOTE-WCAG20-TECHS-20130905/G1 @mixin visually-hidden-focusable() { - &:not(:focus) { + &:not(:focus):not(:focus-within) { @include visually-hidden(); } } diff --git a/site/content/docs/5.0/helpers/visually-hidden.md b/site/content/docs/5.0/helpers/visually-hidden.md index f80160edd6..d8148b3f3c 100644 --- a/site/content/docs/5.0/helpers/visually-hidden.md +++ b/site/content/docs/5.0/helpers/visually-hidden.md @@ -6,13 +6,16 @@ group: helpers aliases: "/docs/5.0/helpers/screen-readers/" --- -Visually hide an element while still allowing it to be exposed to assistive technologies (such as screen readers) with `.visually-hidden`. Use `.visually-hidden-focusable` to visually hide an element by default, but to display it when it's focused (e.g. by a keyboard-only user). Can also be used as mixins. +Visually hide an element while still allowing it to be exposed to assistive technologies (such as screen readers) with `.visually-hidden`. Use `.visually-hidden-focusable` to visually hide an element by default, but to display it when it's focused (e.g. by a keyboard-only user). `.visually-hidden-focusable` can also be applied to a container–thanks to `:focus-within`, the container will be displayed when any child element of the container receives focus. {{< example >}}