1 | import { useEffect } from 'react';
|
2 | /**
|
3 | * Do a "hard" set on the aria, so that it's always announced
|
4 | * even if the id hasn't changed, this saves us from having to have a different id
|
5 | * per item.
|
6 | */
|
7 |
|
8 | export const setActiveDescendant = (ref, activeId) => {
|
9 | if (!ref) return;
|
10 | ref.removeAttribute('aria-activedescendant');
|
11 | if (activeId) ref.setAttribute('aria-activedescendant', activeId);
|
12 | };
|
13 | export const useActiveDescendant = (ref, id, visible, deps) => {
|
14 | useEffect(() => {
|
15 | setActiveDescendant(ref.current, visible ? id : ''); // eslint-disable-next-line react-hooks/exhaustive-deps
|
16 | }, [ref, id, visible, ...deps]);
|
17 | }; |
\ | No newline at end of file |