UNPKG

@mui/x-data-grid

Version:

The Community plan edition of the MUI X Data Grid components.

19 lines (18 loc) 568 B
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); } }