Files
2026-08-07 21:39:30 +02:00

13 lines
494 B
JavaScript

export const FOCUSABLE_ATTRIBUTE = 'data-mui-focusable';
/**
* Returns the element marked as the initial focus target inside a focus trap.
* The root element takes precedence over marked descendants so components can
* opt into focusing their own root surface directly.
*/
export function getFocusTarget(rootElement) {
if (!rootElement) {
return null;
}
return rootElement.hasAttribute(FOCUSABLE_ATTRIBUTE) ? rootElement : rootElement.querySelector(`[${FOCUSABLE_ATTRIBUTE}]`);
}