UNPKG

@gechiui/components

Version:
45 lines (38 loc) 983 B
import { createElement } from "@gechiui/element"; /** * GeChiUI dependencies */ import { useRef, forwardRef } from '@gechiui/element'; /** * Internal dependencies */ import { useRovingTabIndexContext } from './roving-tab-index-context'; export default forwardRef(function RovingTabIndexItem(_ref, forwardedRef) { let { children, as: Component, ...props } = _ref; const localRef = useRef(); const ref = forwardedRef || localRef; const { lastFocusedElement, setLastFocusedElement } = useRovingTabIndexContext(); let tabIndex; if (lastFocusedElement) { tabIndex = lastFocusedElement === ref.current ? 0 : -1; } const onFocus = event => setLastFocusedElement(event.target); const allProps = { ref, tabIndex, onFocus, ...props }; if (typeof children === 'function') { return children(allProps); } return createElement(Component, allProps, children); }); //# sourceMappingURL=roving-tab-index-item.js.map