@shopify/polaris
Version:
Shopify’s product component library
30 lines (23 loc) • 627 B
JavaScript
import React$1, { memo, useEffect } from 'react';
import { focusFirstFocusableNode } from '../../utilities/focus.js';
var Focus = /*#__PURE__*/memo(function Focus({
children,
disabled,
root
}) {
useEffect(() => {
if (disabled || !root) {
return;
}
var node = isRef(root) ? root.current : root;
if (!node || node.querySelector('[autofocus]')) {
return;
}
focusFirstFocusableNode(node, false);
}, [disabled, root]);
return /*#__PURE__*/React$1.createElement(React$1.Fragment, null, children);
});
function isRef(ref) {
return ref.current !== undefined;
}
export { Focus };