@mui/x-data-grid
Version:
The Community plan edition of the MUI X Data Grid components.
24 lines (23 loc) • 704 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.focusElement = focusElement;
var _doesSupportPreventScroll = require("./doesSupportPreventScroll");
/**
* 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.
*/
function focusElement(element, apiRef) {
if ((0, _doesSupportPreventScroll.doesSupportPreventScroll)()) {
element.focus({
preventScroll: true
});
} else {
const scrollPosition = apiRef.current.getScrollPosition();
element.focus();
apiRef.current.scroll(scrollPosition);
}
}