aria-hidden
Hides from ARIA everything, except provided node(s).
Helps to isolate modal dialogs and focused task - the content will be not accessible using
accessible tools.
Now with HTML inert support
API
Just call hideOthers
with DOM-node you want to keep, and it will hide everything else.
targetNode
could be placed anywhere - its siblings would be hidden, but it and its parents - not.
"hidden" in terms or aria-hidden
import { hideOthers } from 'aria-hidden';
const undo = hideOthers(exceptThisDOMnode);
undo();
you also may limit the effect spread by providing top level node as a second parameter
hideOthers(anotherNode, document.getElementById('app'));
parentNode
defaults to document.body
Inert
While aria-hidden
played important role in the past and will play in the future - the main
use case always was around isolating content and making elements "transparent" not only for aria, but for
user interaction as well.
This is why you might consider using inertOthers
import { hideOthers, inertOthers, supportsInert } from 'aria-hidden';
const focusOnElement = (node) => (supportsInert() ? inertOthers(node) : hideOthers(node));
the same function as above is already contructed and exported as
import { suppressOthers } from 'aria-hidden';
suppressOthers([keepThisNode, andThis]);
Inspiration
Based on smooth-ui modal dialogs.
See also
Size
Code is 30 lines long
Licence
MIT