UNPKG

843 BJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.useActiveDescendant = exports.setActiveDescendant = void 0;
5
6var _react = require("react");
7
8/**
9 * Do a "hard" set on the aria, so that it's always announced
10 * even if the id hasn't changed, this saves us from having to have a different id
11 * per item.
12 */
13const setActiveDescendant = (ref, activeId) => {
14 if (!ref) return;
15 ref.removeAttribute('aria-activedescendant');
16 if (activeId) ref.setAttribute('aria-activedescendant', activeId);
17};
18
19exports.setActiveDescendant = setActiveDescendant;
20
21const useActiveDescendant = (ref, id, visible, deps) => {
22 (0, _react.useEffect)(() => {
23 setActiveDescendant(ref.current, visible ? id : ''); // eslint-disable-next-line react-hooks/exhaustive-deps
24 }, [ref, id, visible, ...deps]);
25};
26
27exports.useActiveDescendant = useActiveDescendant;
\No newline at end of file