UNPKG

@wordpress/block-editor

Version:
48 lines (41 loc) 1.28 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import { createElement } from "@wordpress/element"; /** * WordPress dependencies */ import { Button, __unstableCompositeItem as CompositeItem } from '@wordpress/components'; import { forwardRef, useContext } from '@wordpress/element'; /** * Internal dependencies */ import InserterListboxContext from './context'; function InserterListboxItem({ isFirst, as: Component, children, ...props }, ref) { const state = useContext(InserterListboxContext); return createElement(CompositeItem, _extends({ ref: ref, state: state, role: "option" // Use the CompositeItem `focusable` prop over Button's // isFocusable. The latter was shown to cause an issue // with tab order in the inserter list. , focusable: true }, props), htmlProps => { const propsWithTabIndex = { ...htmlProps, tabIndex: isFirst ? 0 : htmlProps.tabIndex }; if (Component) { return createElement(Component, propsWithTabIndex, children); } if (typeof children === 'function') { return children(propsWithTabIndex); } return createElement(Button, propsWithTabIndex, children); }); } export default forwardRef(InserterListboxItem); //# sourceMappingURL=item.js.map