@gechiui/components
Version:
UI components for GeChiUI.
45 lines (38 loc) • 983 B
JavaScript
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