UNPKG

@wordpress/components

Version:
68 lines (67 loc) • 2.04 kB
import deprecated from "@wordpress/deprecated"; import { forwardRef } from "@wordpress/element"; import NavigableContainer from "./container.mjs"; import { jsx } from "react/jsx-runtime"; // packages/components/src/navigable-container/tabbable.tsx function UnforwardedTabbableContainer({ eventToOffset, ...props }, ref) { deprecated("wp.components.TabbableContainer", { since: "7.3", version: "7.5", hint: "For focus trapping, consider the useConstrainedTabbing hook from @wordpress/compose." }); const innerEventToOffset = (evt) => { const { code, shiftKey } = evt; if ("Tab" === code) return shiftKey ? -1 : 1; if (eventToOffset) return eventToOffset(evt); }; return /* @__PURE__ */ jsx(NavigableContainer, { ref, stopNavigationEvents: true, onlyBrowserTabstops: true, eventToOffset: innerEventToOffset, ...props }); } /** * A container for tabbable elements. * * This component is deprecated. For focus trapping, consider the * `useConstrainedTabbing` hook from `@wordpress/compose`. * * @deprecated * * ```jsx * import { * TabbableContainer, * Button, * } from '@wordpress/components'; * * function onNavigate( index, target ) { * console.log( `Navigates to ${ index }`, target ); * } * * const MyTabbableContainer = () => ( * <div> * <span>Tabbable Container:</span> * <TabbableContainer onNavigate={ onNavigate }> * <Button variant="secondary" tabIndex="0"> * Section 1 * </Button> * <Button variant="secondary" tabIndex="0"> * Section 2 * </Button> * <Button variant="secondary" tabIndex="0"> * Section 3 * </Button> * <Button variant="secondary" tabIndex="0"> * Section 4 * </Button> * </TabbableContainer> * </div> * ); * ``` */ const TabbableContainer = forwardRef(UnforwardedTabbableContainer); TabbableContainer.displayName = "TabbableContainer"; export { TabbableContainer, TabbableContainer as default, UnforwardedTabbableContainer }; //# sourceMappingURL=tabbable.mjs.map