@mui/material
Version:
Material UI is an open-source React component library that implements Google's Material Design. It's comprehensive and can be used in production out of the box.
19 lines (18 loc) • 446 B
JavaScript
'use client';
/**
* If `focusSource` is present, attempt to pass `focusVisible` through `focus()` options.
* Fall back to a plain focus call when the browser does not support it.
*/
export default function focusWithVisible(element, focusSource) {
if (focusSource == null) {
element.focus();
return;
}
try {
element.focus({
focusVisible: focusSource === 'keyboard'
});
} catch (error) {
element.focus();
}
}