@wordpress/components
Version:
UI components for WordPress.
1 lines • 3.43 kB
Source Map (JSON)
{"version":3,"file":"tabbable.cjs","names":["NavigableContainer","forwardRef"],"sources":["../../src/navigable-container/tabbable.tsx"],"sourcesContent":["import type { ForwardedRef } from 'react';\nimport deprecated from '@wordpress/deprecated';\nimport { forwardRef } from '@wordpress/element';\nimport NavigableContainer from './container';\nimport type { TabbableContainerProps } from './types';\n\nexport function UnforwardedTabbableContainer(\n\t{ eventToOffset, ...props }: TabbableContainerProps,\n\tref: ForwardedRef< any >\n) {\n\tdeprecated( 'wp.components.TabbableContainer', {\n\t\tsince: '7.3',\n\t\tversion: '7.5',\n\t\thint: 'For focus trapping, consider the useConstrainedTabbing hook from @wordpress/compose.',\n\t} );\n\n\tconst innerEventToOffset = ( evt: KeyboardEvent ) => {\n\t\tconst { code, shiftKey } = evt;\n\t\tif ( 'Tab' === code ) {\n\t\t\treturn shiftKey ? -1 : 1;\n\t\t}\n\n\t\t// Allow custom handling of keys besides Tab.\n\t\t//\n\t\t// By default, TabbableContainer will move focus forward on Tab and\n\t\t// backward on Shift+Tab. The handler below will be used for all other\n\t\t// events. The semantics for `eventToOffset`'s return\n\t\t// values are the following:\n\t\t//\n\t\t// - +1: move focus forward\n\t\t// - -1: move focus backward\n\t\t// - 0: don't move focus, but acknowledge event and thus stop it\n\t\t// - undefined: do nothing, let the event propagate.\n\t\tif ( eventToOffset ) {\n\t\t\treturn eventToOffset( evt );\n\t\t}\n\n\t\treturn undefined;\n\t};\n\n\treturn (\n\t\t<NavigableContainer\n\t\t\tref={ ref }\n\t\t\tstopNavigationEvents\n\t\t\tonlyBrowserTabstops\n\t\t\teventToOffset={ innerEventToOffset }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n}\n\n/**\n * A container for tabbable elements.\n *\n * This component is deprecated. For focus trapping, consider the\n * `useConstrainedTabbing` hook from `@wordpress/compose`.\n *\n * @deprecated\n *\n * ```jsx\n * import {\n * TabbableContainer,\n * Button,\n * } from '@wordpress/components';\n *\n * function onNavigate( index, target ) {\n * console.log( `Navigates to ${ index }`, target );\n * }\n *\n * const MyTabbableContainer = () => (\n * <div>\n * <span>Tabbable Container:</span>\n * <TabbableContainer onNavigate={ onNavigate }>\n * <Button variant=\"secondary\" tabIndex=\"0\">\n * Section 1\n * </Button>\n * <Button variant=\"secondary\" tabIndex=\"0\">\n * Section 2\n * </Button>\n * <Button variant=\"secondary\" tabIndex=\"0\">\n * Section 3\n * </Button>\n * <Button variant=\"secondary\" tabIndex=\"0\">\n * Section 4\n * </Button>\n * </TabbableContainer>\n * </div>\n * );\n * ```\n */\nexport const TabbableContainer = forwardRef( UnforwardedTabbableContainer );\nTabbableContainer.displayName = 'TabbableContainer';\n\nexport default TabbableContainer;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,SAAgB,6BACf,EAAE,eAAe,GAAG,SACpB,KACC;CACD,CAAA,GAAA,sBAAA,QAAA,CAAY,mCAAmC;EAC9C,OAAO;EACP,SAAS;EACT,MAAM;CACP,CAAE;CAEF,MAAM,sBAAuB,QAAwB;EACpD,MAAM,EAAE,MAAM,aAAa;EAC3B,IAAK,UAAU,MACd,OAAO,WAAW,KAAK;EAcxB,IAAK,eACJ,OAAO,cAAe,GAAI;CAI5B;CAEA,OACC,iBAAA,GAAA,kBAAA,IAAA,CAACA,gBAAAA,SAAD;EACO;EACN,sBAAA;EACA,qBAAA;EACA,eAAgB;EAChB,GAAK;CACL,CAAA;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,qBAAA,GAAoBC,mBAAAA,WAAAA,CAAY,4BAA6B;AAC1E,kBAAkB,cAAc"}