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

19 lines
568 B
JavaScript

import { doesSupportPreventScroll } from "./doesSupportPreventScroll.mjs";
/**
* Focuses an element while preserving the grid scroll position.
*
* Uses the native `preventScroll` focus option when supported, and otherwise
* restores the scroll position manually after focusing.
*/
export function focusElement(element, apiRef) {
if (doesSupportPreventScroll()) {
element.focus({
preventScroll: true
});
} else {
const scrollPosition = apiRef.current.getScrollPosition();
element.focus();
apiRef.current.scroll(scrollPosition);
}
}