@wordpress/components
Version:
UI components for WordPress.
62 lines (57 loc) • 1.88 kB
JavaScript
/**
* External dependencies
*/
import * as Ariakit from '@ariakit/react';
/**
* WordPress dependencies
*/
import { forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import warning from '@wordpress/warning';
import { useTabsContext } from './context';
import { Tab as StyledTab, TabChildren as StyledTabChildren, TabChevron as StyledTabChevron } from './styles';
import { chevronRight } from '@wordpress/icons';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export const Tab = forwardRef(function Tab({
children,
tabId,
disabled,
render,
...otherProps
}, ref) {
var _useTabsContext;
const {
store,
instanceId
} = (_useTabsContext = useTabsContext()) !== null && _useTabsContext !== void 0 ? _useTabsContext : {};
// If the active item is not connected, the tablist may end up in a state
// where none of the tabs are tabbable. In this case, we force all tabs to
// be tabbable, so that as soon as an item received focus, it becomes active
// and Tablist goes back to working as expected.
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
const tabbable = Ariakit.useStoreState(store, state => {
return state?.activeId !== null && !store?.item(state?.activeId)?.element?.isConnected;
});
if (!store) {
globalThis.SCRIPT_DEBUG === true ? warning('`Tabs.Tab` must be wrapped in a `Tabs` component.') : void 0;
return null;
}
const instancedTabId = `${instanceId}-${tabId}`;
return /*#__PURE__*/_jsxs(StyledTab, {
ref: ref,
store: store,
id: instancedTabId,
disabled: disabled,
render: render,
tabbable: tabbable,
...otherProps,
children: [/*#__PURE__*/_jsx(StyledTabChildren, {
children: children
}), /*#__PURE__*/_jsx(StyledTabChevron, {
icon: chevronRight
})]
});
});
//# sourceMappingURL=tab.js.map