@allxsmith/bestax-bulma 5.40.0 → 5.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bestax.css +1 -1
- package/dist/bestax.css.map +1 -1
- package/dist/esm/components/Menu.js +77 -2
- package/dist/esm/components/Menu.js.map +1 -1
- package/dist/esm/components/Modal.js +3 -3
- package/dist/esm/components/Modal.js.map +1 -1
- package/dist/esm/components/Popover.js +2 -2
- package/dist/esm/components/Popover.js.map +1 -1
- package/dist/esm/components/Sidebar.js +2 -2
- package/dist/esm/components/Sidebar.js.map +1 -1
- package/dist/esm/elements/Image.js +4 -12
- package/dist/esm/elements/Image.js.map +1 -1
- package/dist/esm/helpers/useFocusTrap.js +60 -41
- package/dist/esm/helpers/useFocusTrap.js.map +1 -1
- package/dist/extras.css +1 -1
- package/dist/extras.css.map +1 -1
- package/dist/index.cjs +162 -78
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/types/components/Menu.d.ts +49 -0
- package/dist/types/elements/Image.d.ts +6 -1
- package/dist/types/helpers/useFocusTrap.d.ts +16 -8
- package/dist/types-cjs/components/Menu.d.ts +49 -0
- package/dist/types-cjs/elements/Image.d.ts +6 -1
- package/dist/types-cjs/helpers/useFocusTrap.d.ts +16 -8
- package/dist/versions/bestax-no-dark-mode.css +1 -1
- package/dist/versions/bestax-no-dark-mode.css.map +1 -1
- package/dist/versions/bestax-no-helpers-prefixed.css +1 -1
- package/dist/versions/bestax-no-helpers-prefixed.css.map +1 -1
- package/dist/versions/bestax-no-helpers.css +1 -1
- package/dist/versions/bestax-no-helpers.css.map +1 -1
- package/dist/versions/bestax-prefixed.css +1 -1
- package/dist/versions/bestax-prefixed.css.map +1 -1
- package/package.json +1 -1
- package/src/scss/components/_menu.scss +130 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sidebar.js","sources":["../../../src/components/Sidebar.tsx"],"sourcesContent":["import React, { forwardRef, useEffect, useCallback, useRef } from 'react';\nimport { createPortal } from 'react-dom';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { withSubComponents } from '../helpers/withSubComponents';\nimport { useScrollLock } from '../helpers/scrollLock';\nimport { usePortalContainer } from '../helpers/portal';\nimport { useConfig } from '../helpers/Config';\nimport { buttonType } from '../helpers/buttonType';\nimport { useLatestRef } from '../helpers/useLatestRef';\nimport { isModalOverlayOpen, useOverlayStack } from '../helpers/overlayStack';\nimport { firstTabStop, trapTab } from '../helpers/useFocusTrap';\nimport { inertProps } from '../helpers/inertProps';\nimport {\n getActiveElementInTree,\n getDeepestActiveElement,\n} from '../helpers/shadowDom';\n\n/** Position of the sidebar relative to the viewport. */\nexport type SidebarPosition = 'left' | 'right';\n\n/**\n * Props for the Sidebar component.\n * @extraProp {string} [className] - Additional CSS classes.\n * @extraProp {React.Ref<HTMLElement>} [ref] - Ref forwarded to the sidebar element.\n */\nexport interface SidebarProps\n extends\n Omit<React.HTMLAttributes<HTMLElement>, 'children' | 'color'>,\n BulmaClassesProps {\n /**\n * Whether the sidebar is open (required). Opening moves focus into the\n * sidebar, to its first tab stop or the sidebar itself, except for a sidebar\n * without an overlay opened while a modal overlay, such as a Modal, is open:\n * that one leaves focus where it is. That's decided as it opens, and\n * changing `overlay` while it's open doesn't move focus. Closing hands\n * focus back to whatever had it when the sidebar opened, unless focus has\n * already left the sidebar, as it does for an overlay opened over it. A\n * closed sidebar stays in the page, so it can slide out, and is `inert` and\n * `aria-hidden` there: Tab passes over its content and assistive\n * technology doesn't read it.\n */\n isOpen: boolean;\n /** Callback when sidebar should close. */\n onClose?: () => void;\n /** Which side the sidebar appears from. Default: 'left'. */\n position?: SidebarPosition;\n /** Custom width of the sidebar. */\n width?: string;\n /** Sidebar takes full width (mobile-style). */\n isFullwidth?: boolean;\n /** Sidebar takes full width (mobile-style). @deprecated Use `isFullwidth` instead — `isFullwidth` wins if both are set. */\n fullWidth?: boolean;\n /**\n * Show an overlay behind the sidebar, which makes it modal: it gets\n * `aria-modal=\"true\"`, locks body scroll, and keeps Tab and Shift+Tab\n * inside it while it is the topmost modal overlay. A Modal or Dialog opened\n * over it, even one rendered inside it, holds Tab until it closes. Without\n * an overlay the sidebar isn't modal and holds no Tab: on the page, Tab\n * moves in and out of it freely, and opened over a Modal, it leaves the\n * Modal holding Tab, and focus, while still taking Escape first. Whether\n * the sidebar takes focus is decided as it opens: changing this while it's\n * open moves the Tab trap, not focus. Default: true.\n */\n overlay?: boolean;\n /** Close sidebar when overlay is clicked. Default: true. */\n overlayClose?: boolean;\n /**\n * Close sidebar on Escape key. Only the topmost open overlay responds,\n * whichever Modal, Dialog, Sidebar or full-page Loading opened last, so\n * Escape closes one layer at a time. The sidebar marks the Escape it closes\n * on as used with `preventDefault()`, and a Toast waits until no overlay is\n * open. Turned off, a sidebar on top still keeps Escape from the layers\n * under it. A popup inside it, such as a Dropdown's menu or a date picker's\n * calendar, takes its own Escape first, and so does content that calls\n * `preventDefault()` on it. Default: true.\n */\n escapeClose?: boolean;\n /** Allow closing the sidebar. Default: true. */\n canCancel?: boolean;\n /** Content to display in the sidebar. */\n children?: React.ReactNode;\n /** Renders inline instead of using a portal. */\n inline?: boolean;\n}\n\n/**\n * The `Sidebar` component provides a slide-out navigation panel that appears from the left or right side of the screen.\n *\n * @function\n * @param {SidebarProps} props - Props for the Sidebar component.\n * @param {React.Ref<HTMLElement>} ref - Forwarded ref to the sidebar element.\n * @returns {JSX.Element | null} The rendered sidebar component.\n *\n * @example\n * // Basic sidebar\n * const [isOpen, setIsOpen] = useState(false);\n * <Sidebar isOpen={isOpen} onClose={() => setIsOpen(false)}>\n * <Menu>...</Menu>\n * </Sidebar>\n *\n * @example\n * // Right-side sidebar with custom width\n * <Sidebar\n * isOpen={isOpen}\n * onClose={() => setIsOpen(false)}\n * position=\"right\"\n * width=\"320px\"\n * >\n * <div>Panel content</div>\n * </Sidebar>\n */\nconst SidebarComponent = forwardRef<HTMLElement, SidebarProps>(\n (\n {\n isOpen,\n onClose,\n position = 'left',\n width = '260px',\n isFullwidth,\n fullWidth,\n overlay = true,\n overlayClose = true,\n escapeClose = true,\n canCancel = true,\n children,\n inline = false,\n className,\n style,\n ...props\n },\n ref\n ) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n const resolveContainer = usePortalContainer();\n const { portalContainer } = useConfig();\n // Where the configured default puts the sidebar. An `inline` one doesn't\n // portal, so a change to the default moves nothing.\n const defaultTarget = inline ? undefined : portalContainer;\n const sidebarRef = useRef<HTMLElement>(null);\n // Cleanup returned by a consumer's callback ref on attach, held until detach.\n const consumerCleanupRef = useRef<(() => void) | null>(null);\n const resolvedFullwidth = isFullwidth ?? fullWidth ?? false;\n\n // Close handler\n const handleClose = useCallback(() => {\n if (canCancel && onClose) {\n onClose();\n }\n }, [canCancel, onClose]);\n\n // Handle overlay click\n const handleOverlayClick = useCallback(() => {\n if (overlayClose) {\n handleClose();\n }\n }, [overlayClose, handleClose]);\n\n // Read when Escape arrives, so the key listener stays put while\n // `onClose` changes identity, as an inline one does on every render of\n // the parent.\n const handleCloseRef = useLatestRef(handleClose);\n\n // Joins the stack of open overlays, so the sidebar answers Escape only\n // while it's the topmost overlay, and keeps it from those under it. It's\n // modal with an overlay: without one it leaves Tab to a modal overlay\n // under it.\n const isTopmost = useOverlayStack(isOpen, overlay);\n const closesOnEscape = escapeClose && canCancel && Boolean(onClose);\n\n // Handle escape key. On `window`, as in `Modal`, so everything inside the\n // sidebar has had the key first, and an Escape it used is left to it. One\n // the sidebar closes on is marked used, so nothing under it acts on it.\n useEffect(() => {\n if (!isOpen || !closesOnEscape) return;\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (e.key !== 'Escape' || e.defaultPrevented || !isTopmost()) return;\n e.preventDefault();\n handleCloseRef.current();\n };\n\n window.addEventListener('keydown', handleKeyDown);\n return () => window.removeEventListener('keydown', handleKeyDown);\n }, [isOpen, closesOnEscape, handleCloseRef, isTopmost]);\n\n // Keep Tab inside while there's an overlay, as `Modal` does:\n // `aria-modal` hides the rest of the page from assistive technology, so\n // the keyboard order has to agree. Only while it's the topmost modal\n // overlay, so a Modal or Dialog opened over the sidebar, even one\n // rendered inside it, holds Tab instead until it closes, and a sidebar\n // without an overlay opened over it doesn't. On `window` for the same\n // reason as Escape: a trap inside, such as a portaled popup's, has had\n // the Tab first, and one it used is left where it put focus. It's the trap\n // `useFocusTrap` sets, so a Tab the browser still takes out, as Safari\n // does past links, is sent back in. It reads the aside as each key\n // arrives, so one remounted while the sidebar is open, by a new portal\n // target or by switching `inline`, stays trapped.\n useEffect(() => {\n if (!isOpen || !overlay) return undefined;\n return trapTab(\n () => sidebarRef.current,\n window,\n () => isTopmost('modal')\n );\n }, [isOpen, overlay, isTopmost]);\n\n // Prevent body scroll when sidebar is open. Ref-counted through the shared\n // helper so an overlapping Modal/Dialog/Loading doesn't unlock underneath.\n useScrollLock(isOpen && overlay);\n\n // Move focus into the sidebar on open, to the first stop Tab wraps to or\n // the sidebar itself, and hand it back on close, as `Modal` does. A\n // different `defaultTarget` remounts the portaled sidebar: the cleanup\n // hands focus back from the old nodes, which left it on <body>, and the\n // re-run records the same opener and focuses the new nodes. Whether it\n // takes focus is decided as it opens, so `overlay` changing while it's\n // open leaves focus where the user has it.\n useEffect(() => {\n if (!isOpen) return undefined;\n const element = sidebarRef.current;\n /* istanbul ignore if: the aside renders whenever the sidebar is open, so its ref is set before this runs */\n if (!element) return undefined;\n\n // The element that had focus, wherever it sits: a portaled sidebar\n // renders under `document.body` while its opener can be inside a\n // shadow root.\n const opener = getDeepestActiveElement() as HTMLElement | null;\n // Without an overlay the sidebar holds no Tab, so with a modal overlay\n // open under it, the first Tab would take focus back there and leave\n // the sidebar's other controls out of reach. It leaves focus alone\n // then, and the cleanup below finds focus outside and leaves it too.\n if (overlay || !isModalOverlayOpen()) {\n (firstTabStop(element) ?? element).focus();\n }\n\n return () => {\n // Only while the sidebar still holds focus: closing one under another\n // overlay mustn't pull focus out of the one on top, and focus moved\n // out to the page stays there. A removed subtree leaves focus on\n // <body>, which still counts as held.\n const active = getActiveElementInTree(element);\n if (active === document.body || element.contains(active)) {\n opener?.focus();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- `overlay` is read as the sidebar opens, on purpose\n }, [isOpen, defaultTarget]);\n\n // Use combined ref\n const combinedRef = useCallback(\n (node: HTMLElement | null) => {\n (sidebarRef as React.MutableRefObject<HTMLElement | null>).current =\n node;\n if (typeof ref === 'function') {\n // React 19 lets a callback ref return a cleanup function and detaches by\n // running it instead of calling the ref with `null`; React 18 discards the\n // return value entirely. Returning it from here would be a React-19-only\n // contract, so we hold the cleanup and run it ourselves on detach — the\n // same shape as `Dropdown`, `Modal`, `Dialog`, `Toast` and `Carousel`.\n // The form controls that merge a forwarded ref still discard the cleanup\n // and detach with `ref(null)`, so this is not yet library-wide — grep\n // `typeof ref === 'function'` for the current split.\n if (node === null) {\n const consumerCleanup = consumerCleanupRef.current;\n consumerCleanupRef.current = null;\n if (consumerCleanup) {\n consumerCleanup();\n } else {\n ref(null);\n }\n return;\n }\n const cleanup: unknown = ref(node);\n consumerCleanupRef.current =\n typeof cleanup === 'function' ? (cleanup as () => void) : null;\n } else if (ref) {\n (ref as React.MutableRefObject<HTMLElement | null>).current = node;\n }\n },\n [ref]\n );\n\n // Generate classes\n const sidebarClasses = usePrefixedClassNames('sidebar', {\n 'is-active': isOpen,\n [`is-${position}`]: position,\n 'is-fullwidth': resolvedFullwidth,\n });\n const backgroundClass = usePrefixedClassNames('sidebar-background', {\n 'is-active': isOpen,\n });\n const contentClass = usePrefixedClassNames('sidebar-content');\n\n const combinedClasses = classNames(\n sidebarClasses,\n bulmaHelperClasses,\n className\n );\n\n // Custom style for width\n const sidebarStyle: React.CSSProperties = {\n ...style,\n '--bulma-sidebar-width': resolvedFullwidth ? '100%' : width,\n } as React.CSSProperties;\n\n const sidebarContent = (\n <>\n {overlay && (\n <div\n className={backgroundClass}\n onClick={handleOverlayClick}\n aria-hidden=\"true\"\n />\n )}\n <aside\n ref={combinedRef}\n className={combinedClasses}\n style={sidebarStyle}\n role=\"dialog\"\n aria-modal={overlay ? 'true' : undefined}\n aria-hidden={!isOpen}\n // React commits this before the effect that moves focus in runs, so\n // an opening sidebar is no longer inert by then.\n {...inertProps(!isOpen)}\n tabIndex={-1}\n {...rest}\n >\n <div className={contentClass}>{children}</div>\n </aside>\n </>\n );\n\n if (inline) {\n return sidebarContent;\n }\n\n // Render to portal for proper stacking\n if (typeof document !== 'undefined') {\n return createPortal(sidebarContent, resolveContainer());\n }\n\n return null;\n }\n);\n\n// Sub-components\n\n/**\n * Props for the SidebarHeader component.\n */\ninterface SidebarHeaderProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Header content. */\n children?: React.ReactNode;\n}\n\n/**\n * Container for the sidebar header.\n *\n * @function\n * @param {SidebarHeaderProps} props - Props for the SidebarHeader component.\n * @returns {JSX.Element} The rendered sidebar header.\n */\nconst SidebarHeader: React.FC<SidebarHeaderProps> = ({\n className,\n children,\n ...props\n}) => {\n const headerClass = usePrefixedClassNames('sidebar-header');\n return (\n <div className={classNames(headerClass, className)} {...props}>\n {children}\n </div>\n );\n};\n\n/**\n * Props for the SidebarTitle component.\n */\ninterface SidebarTitleProps extends React.HTMLAttributes<HTMLParagraphElement> {\n /** Title content. */\n children?: React.ReactNode;\n}\n\n/**\n * Title text inside the header.\n *\n * @function\n * @param {SidebarTitleProps} props - Props for the SidebarTitle component.\n * @returns {JSX.Element} The rendered sidebar title.\n */\nconst SidebarTitle: React.FC<SidebarTitleProps> = ({\n className,\n children,\n ...props\n}) => {\n const titleClass = usePrefixedClassNames('sidebar-title');\n return (\n <p className={classNames(titleClass, className)} {...props}>\n {children}\n </p>\n );\n};\n\n/**\n * Props for the SidebarClose component.\n * Extends standard button attributes.\n * @extraProp {'button' | 'submit' | 'reset'} [type='button'] - Button type. Defaults to `'button'`, so a close button inside a form does not submit it. Pass `'submit'` or `'reset'` and yours is used; any other value, or a spread carrying `type: undefined`, renders `'button'`.\n * @extraProp {string} [aria-label='Close'] - Accessible name. Pass your own to replace it. An empty one, or a spread carrying `'aria-label': undefined`, keeps the default rather than leaving the button unnamed.\n */\ntype SidebarCloseProps = React.ButtonHTMLAttributes<HTMLButtonElement>;\n\n/**\n * Close button for the sidebar.\n *\n * @function\n * @param {SidebarCloseProps} props - Props for the SidebarClose component.\n * @returns {JSX.Element} The rendered close button.\n */\nconst SidebarClose: React.FC<SidebarCloseProps> = ({\n className,\n children,\n ...props\n}) => {\n const closeClass = usePrefixedClassNames('sidebar-close');\n return (\n <button\n className={classNames(closeClass, className)}\n {...props}\n // After the spread, reading through it: a key the spread carries with no\n // value would otherwise erase the default, leaving a nameless button\n // that submits the form around it. An empty label falls back too: the\n // button is drawn as an icon, so `''` would leave it unnamed. A caller's\n // own value still wins; `buttonType` says more.\n aria-label={props['aria-label'] || 'Close'}\n type={buttonType(props.type)}\n >\n {children}\n </button>\n );\n};\n\n/**\n * Props for the SidebarBody component.\n */\ninterface SidebarBodyProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Body content. */\n children?: React.ReactNode;\n}\n\n/**\n * Main content area of the sidebar.\n *\n * @function\n * @param {SidebarBodyProps} props - Props for the SidebarBody component.\n * @returns {JSX.Element} The rendered sidebar body.\n */\nconst SidebarBody: React.FC<SidebarBodyProps> = ({\n className,\n children,\n ...props\n}) => {\n const bodyClass = usePrefixedClassNames('sidebar-body');\n return (\n <div className={classNames(bodyClass, className)} {...props}>\n {children}\n </div>\n );\n};\n\n/**\n * Props for the SidebarFooter component.\n */\ninterface SidebarFooterProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Footer content. */\n children?: React.ReactNode;\n}\n\n/**\n * Footer area of the sidebar.\n *\n * @function\n * @param {SidebarFooterProps} props - Props for the SidebarFooter component.\n * @returns {JSX.Element} The rendered sidebar footer.\n */\nconst SidebarFooter: React.FC<SidebarFooterProps> = ({\n className,\n children,\n ...props\n}) => {\n const footerClass = usePrefixedClassNames('sidebar-footer');\n return (\n <div className={classNames(footerClass, className)} {...props}>\n {children}\n </div>\n );\n};\n\n// Attach static subcomponents\nexport const Sidebar = withSubComponents(\n SidebarComponent,\n {\n Header: SidebarHeader,\n Title: SidebarTitle,\n Close: SidebarClose,\n Body: SidebarBody,\n Footer: SidebarFooter,\n },\n 'Sidebar'\n);\n\nexport default Sidebar;\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;;;;;;;;;AAsFA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AACH,MAAM,gBAAgB,GAAG,UAAU,CACjC,CACE,EACE,MAAM,EACN,OAAO,EACP,QAAQ,GAAG,MAAM,EACjB,KAAK,GAAG,OAAO,EACf,WAAW,EACX,SAAS,EACT,OAAO,GAAG,IAAI,EACd,YAAY,GAAG,IAAI,EACnB,WAAW,GAAG,IAAI,EAClB,SAAS,GAAG,IAAI,EAChB,QAAQ,EACR,MAAM,GAAG,KAAK,EACd,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EACD,GAAG,KACD;IACF,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC;AAC3D,IAAA,MAAM,gBAAgB,GAAG,kBAAkB,EAAE;AAC7C,IAAA,MAAM,EAAE,eAAe,EAAE,GAAG,SAAS,EAAE;;;IAGvC,MAAM,aAAa,GAAG,MAAM,GAAG,SAAS,GAAG,eAAe;AAC1D,IAAA,MAAM,UAAU,GAAG,MAAM,CAAc,IAAI,CAAC;;AAE5C,IAAA,MAAM,kBAAkB,GAAG,MAAM,CAAsB,IAAI,CAAC;AAC5D,IAAA,MAAM,iBAAiB,GAAG,WAAW,IAAI,SAAS,IAAI,KAAK;;AAG3D,IAAA,MAAM,WAAW,GAAG,WAAW,CAAC,MAAK;AACnC,QAAA,IAAI,SAAS,IAAI,OAAO,EAAE;AACxB,YAAA,OAAO,E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xC,KAAK,EAAA,YAAA,EAMG,KAAK,CAAC,YAAY,CAAC,IAAI,OAAO,EAC1C,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,EAAA,QAAA,EAE3B,QAAQ,EAAA,CACF;AAEb,CAAC;AAUD;;;;;;AAMG;AACH,MAAM,WAAW,GAA+B,CAAC,EAC/C,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,KAAI;AACH,IAAA,MAAM,SAAS,GAAG,qBAAqB,CAAC,cAAc,CAAC;AACvD,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,SAAS,CAAC,KAAM,KAAK,EAAA,QAAA,EACxD,QAAQ,EAAA,CACL;AAEV,CAAC;AAUD;;;;;;AAMG;AACH,MAAM,aAAa,GAAiC,CAAC,EACnD,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,KAAI;AACH,IAAA,MAAM,WAAW,GAAG,qBAAqB,CAAC,gBAAgB,CAAC;AAC3D,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,UAAU,CAAC,WAAW,EAAE,SAAS,CAAC,KAAM,KAAK,EAAA,QAAA,EAC1D,QAAQ,EAAA,CACL;AAEV,CAAC;AAED;AACO,MAAM,OAAO,GAAG,iBAAiB,CACtC,gBAAgB,EAChB;AACE,IAAA,MAAM,EAAE,aAAa;AACrB,IAAA,KAAK,EAAE,YAAY;AACnB,IAAA,KAAK,EAAE,YAAY;AACnB,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,MAAM,EAAE,aAAa;CACtB,EACD,SAAS;;"}
|
|
1
|
+
{"version":3,"file":"Sidebar.js","sources":["../../../src/components/Sidebar.tsx"],"sourcesContent":["import React, { forwardRef, useEffect, useCallback, useRef } from 'react';\nimport { createPortal } from 'react-dom';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { withSubComponents } from '../helpers/withSubComponents';\nimport { useScrollLock } from '../helpers/scrollLock';\nimport { usePortalContainer } from '../helpers/portal';\nimport { useConfig } from '../helpers/Config';\nimport { buttonType } from '../helpers/buttonType';\nimport { useLatestRef } from '../helpers/useLatestRef';\nimport { isModalOverlayOpen, useOverlayStack } from '../helpers/overlayStack';\nimport { focusTabStop, trapTab } from '../helpers/useFocusTrap';\nimport { inertProps } from '../helpers/inertProps';\nimport {\n getActiveElementInTree,\n getDeepestActiveElement,\n} from '../helpers/shadowDom';\n\n/** Position of the sidebar relative to the viewport. */\nexport type SidebarPosition = 'left' | 'right';\n\n/**\n * Props for the Sidebar component.\n * @extraProp {string} [className] - Additional CSS classes.\n * @extraProp {React.Ref<HTMLElement>} [ref] - Ref forwarded to the sidebar element.\n */\nexport interface SidebarProps\n extends\n Omit<React.HTMLAttributes<HTMLElement>, 'children' | 'color'>,\n BulmaClassesProps {\n /**\n * Whether the sidebar is open (required). Opening moves focus into the\n * sidebar, to its first tab stop or the sidebar itself, except for a sidebar\n * without an overlay opened while a modal overlay, such as a Modal, is open:\n * that one leaves focus where it is. That's decided as it opens, and\n * changing `overlay` while it's open doesn't move focus. Closing hands\n * focus back to whatever had it when the sidebar opened, unless focus has\n * already left the sidebar, as it does for an overlay opened over it. A\n * closed sidebar stays in the page, so it can slide out, and is `inert` and\n * `aria-hidden` there: Tab passes over its content and assistive\n * technology doesn't read it.\n */\n isOpen: boolean;\n /** Callback when sidebar should close. */\n onClose?: () => void;\n /** Which side the sidebar appears from. Default: 'left'. */\n position?: SidebarPosition;\n /** Custom width of the sidebar. */\n width?: string;\n /** Sidebar takes full width (mobile-style). */\n isFullwidth?: boolean;\n /** Sidebar takes full width (mobile-style). @deprecated Use `isFullwidth` instead — `isFullwidth` wins if both are set. */\n fullWidth?: boolean;\n /**\n * Show an overlay behind the sidebar, which makes it modal: it gets\n * `aria-modal=\"true\"`, locks body scroll, and keeps Tab and Shift+Tab\n * inside it while it is the topmost modal overlay. A Modal or Dialog opened\n * over it, even one rendered inside it, holds Tab until it closes. Without\n * an overlay the sidebar isn't modal and holds no Tab: on the page, Tab\n * moves in and out of it freely, and opened over a Modal, it leaves the\n * Modal holding Tab, and focus, while still taking Escape first. Whether\n * the sidebar takes focus is decided as it opens: changing this while it's\n * open moves the Tab trap, not focus. Default: true.\n */\n overlay?: boolean;\n /** Close sidebar when overlay is clicked. Default: true. */\n overlayClose?: boolean;\n /**\n * Close sidebar on Escape key. Only the topmost open overlay responds,\n * whichever Modal, Dialog, Sidebar or full-page Loading opened last, so\n * Escape closes one layer at a time. The sidebar marks the Escape it closes\n * on as used with `preventDefault()`, and a Toast waits until no overlay is\n * open. Turned off, a sidebar on top still keeps Escape from the layers\n * under it. A popup inside it, such as a Dropdown's menu or a date picker's\n * calendar, takes its own Escape first, and so does content that calls\n * `preventDefault()` on it. Default: true.\n */\n escapeClose?: boolean;\n /** Allow closing the sidebar. Default: true. */\n canCancel?: boolean;\n /** Content to display in the sidebar. */\n children?: React.ReactNode;\n /** Renders inline instead of using a portal. */\n inline?: boolean;\n}\n\n/**\n * The `Sidebar` component provides a slide-out navigation panel that appears from the left or right side of the screen.\n *\n * @function\n * @param {SidebarProps} props - Props for the Sidebar component.\n * @param {React.Ref<HTMLElement>} ref - Forwarded ref to the sidebar element.\n * @returns {JSX.Element | null} The rendered sidebar component.\n *\n * @example\n * // Basic sidebar\n * const [isOpen, setIsOpen] = useState(false);\n * <Sidebar isOpen={isOpen} onClose={() => setIsOpen(false)}>\n * <Menu>...</Menu>\n * </Sidebar>\n *\n * @example\n * // Right-side sidebar with custom width\n * <Sidebar\n * isOpen={isOpen}\n * onClose={() => setIsOpen(false)}\n * position=\"right\"\n * width=\"320px\"\n * >\n * <div>Panel content</div>\n * </Sidebar>\n */\nconst SidebarComponent = forwardRef<HTMLElement, SidebarProps>(\n (\n {\n isOpen,\n onClose,\n position = 'left',\n width = '260px',\n isFullwidth,\n fullWidth,\n overlay = true,\n overlayClose = true,\n escapeClose = true,\n canCancel = true,\n children,\n inline = false,\n className,\n style,\n ...props\n },\n ref\n ) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n const resolveContainer = usePortalContainer();\n const { portalContainer } = useConfig();\n // Where the configured default puts the sidebar. An `inline` one doesn't\n // portal, so a change to the default moves nothing.\n const defaultTarget = inline ? undefined : portalContainer;\n const sidebarRef = useRef<HTMLElement>(null);\n // Cleanup returned by a consumer's callback ref on attach, held until detach.\n const consumerCleanupRef = useRef<(() => void) | null>(null);\n const resolvedFullwidth = isFullwidth ?? fullWidth ?? false;\n\n // Close handler\n const handleClose = useCallback(() => {\n if (canCancel && onClose) {\n onClose();\n }\n }, [canCancel, onClose]);\n\n // Handle overlay click\n const handleOverlayClick = useCallback(() => {\n if (overlayClose) {\n handleClose();\n }\n }, [overlayClose, handleClose]);\n\n // Read when Escape arrives, so the key listener stays put while\n // `onClose` changes identity, as an inline one does on every render of\n // the parent.\n const handleCloseRef = useLatestRef(handleClose);\n\n // Joins the stack of open overlays, so the sidebar answers Escape only\n // while it's the topmost overlay, and keeps it from those under it. It's\n // modal with an overlay: without one it leaves Tab to a modal overlay\n // under it.\n const isTopmost = useOverlayStack(isOpen, overlay);\n const closesOnEscape = escapeClose && canCancel && Boolean(onClose);\n\n // Handle escape key. On `window`, as in `Modal`, so everything inside the\n // sidebar has had the key first, and an Escape it used is left to it. One\n // the sidebar closes on is marked used, so nothing under it acts on it.\n useEffect(() => {\n if (!isOpen || !closesOnEscape) return;\n\n const handleKeyDown = (e: KeyboardEvent) => {\n if (e.key !== 'Escape' || e.defaultPrevented || !isTopmost()) return;\n e.preventDefault();\n handleCloseRef.current();\n };\n\n window.addEventListener('keydown', handleKeyDown);\n return () => window.removeEventListener('keydown', handleKeyDown);\n }, [isOpen, closesOnEscape, handleCloseRef, isTopmost]);\n\n // Keep Tab inside while there's an overlay, as `Modal` does:\n // `aria-modal` hides the rest of the page from assistive technology, so\n // the keyboard order has to agree. Only while it's the topmost modal\n // overlay, so a Modal or Dialog opened over the sidebar, even one\n // rendered inside it, holds Tab instead until it closes, and a sidebar\n // without an overlay opened over it doesn't. On `window` for the same\n // reason as Escape: a trap inside, such as a portaled popup's, has had\n // the Tab first, and one it used is left where it put focus. It's the trap\n // `useFocusTrap` sets, so a Tab the browser still takes out, as Safari\n // does past links, is sent back in. It reads the aside as each key\n // arrives, so one remounted while the sidebar is open, by a new portal\n // target or by switching `inline`, stays trapped.\n useEffect(() => {\n if (!isOpen || !overlay) return undefined;\n return trapTab(\n () => sidebarRef.current,\n window,\n () => isTopmost('modal')\n );\n }, [isOpen, overlay, isTopmost]);\n\n // Prevent body scroll when sidebar is open. Ref-counted through the shared\n // helper so an overlapping Modal/Dialog/Loading doesn't unlock underneath.\n useScrollLock(isOpen && overlay);\n\n // Move focus into the sidebar on open, to the first stop Tab wraps to or\n // the sidebar itself, and hand it back on close, as `Modal` does. A\n // different `defaultTarget` remounts the portaled sidebar: the cleanup\n // hands focus back from the old nodes, which left it on <body>, and the\n // re-run records the same opener and focuses the new nodes. Whether it\n // takes focus is decided as it opens, so `overlay` changing while it's\n // open leaves focus where the user has it.\n useEffect(() => {\n if (!isOpen) return undefined;\n const element = sidebarRef.current;\n /* istanbul ignore if: the aside renders whenever the sidebar is open, so its ref is set before this runs */\n if (!element) return undefined;\n\n // The element that had focus, wherever it sits: a portaled sidebar\n // renders under `document.body` while its opener can be inside a\n // shadow root.\n const opener = getDeepestActiveElement() as HTMLElement | null;\n // Without an overlay the sidebar holds no Tab, so with a modal overlay\n // open under it, the first Tab would take focus back there and leave\n // the sidebar's other controls out of reach. It leaves focus alone\n // then, and the cleanup below finds focus outside and leaves it too.\n if (overlay || !isModalOverlayOpen()) {\n focusTabStop(element);\n }\n\n return () => {\n // Only while the sidebar still holds focus: closing one under another\n // overlay mustn't pull focus out of the one on top, and focus moved\n // out to the page stays there. A removed subtree leaves focus on\n // <body>, which still counts as held.\n const active = getActiveElementInTree(element);\n if (active === document.body || element.contains(active)) {\n opener?.focus();\n }\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- `overlay` is read as the sidebar opens, on purpose\n }, [isOpen, defaultTarget]);\n\n // Use combined ref\n const combinedRef = useCallback(\n (node: HTMLElement | null) => {\n (sidebarRef as React.MutableRefObject<HTMLElement | null>).current =\n node;\n if (typeof ref === 'function') {\n // React 19 lets a callback ref return a cleanup function and detaches by\n // running it instead of calling the ref with `null`; React 18 discards the\n // return value entirely. Returning it from here would be a React-19-only\n // contract, so we hold the cleanup and run it ourselves on detach — the\n // same shape as `Dropdown`, `Modal`, `Dialog`, `Toast` and `Carousel`.\n // The form controls that merge a forwarded ref still discard the cleanup\n // and detach with `ref(null)`, so this is not yet library-wide — grep\n // `typeof ref === 'function'` for the current split.\n if (node === null) {\n const consumerCleanup = consumerCleanupRef.current;\n consumerCleanupRef.current = null;\n if (consumerCleanup) {\n consumerCleanup();\n } else {\n ref(null);\n }\n return;\n }\n const cleanup: unknown = ref(node);\n consumerCleanupRef.current =\n typeof cleanup === 'function' ? (cleanup as () => void) : null;\n } else if (ref) {\n (ref as React.MutableRefObject<HTMLElement | null>).current = node;\n }\n },\n [ref]\n );\n\n // Generate classes\n const sidebarClasses = usePrefixedClassNames('sidebar', {\n 'is-active': isOpen,\n [`is-${position}`]: position,\n 'is-fullwidth': resolvedFullwidth,\n });\n const backgroundClass = usePrefixedClassNames('sidebar-background', {\n 'is-active': isOpen,\n });\n const contentClass = usePrefixedClassNames('sidebar-content');\n\n const combinedClasses = classNames(\n sidebarClasses,\n bulmaHelperClasses,\n className\n );\n\n // Custom style for width\n const sidebarStyle: React.CSSProperties = {\n ...style,\n '--bulma-sidebar-width': resolvedFullwidth ? '100%' : width,\n } as React.CSSProperties;\n\n const sidebarContent = (\n <>\n {overlay && (\n <div\n className={backgroundClass}\n onClick={handleOverlayClick}\n aria-hidden=\"true\"\n />\n )}\n <aside\n ref={combinedRef}\n className={combinedClasses}\n style={sidebarStyle}\n role=\"dialog\"\n aria-modal={overlay ? 'true' : undefined}\n aria-hidden={!isOpen}\n // React commits this before the effect that moves focus in runs, so\n // an opening sidebar is no longer inert by then.\n {...inertProps(!isOpen)}\n tabIndex={-1}\n {...rest}\n >\n <div className={contentClass}>{children}</div>\n </aside>\n </>\n );\n\n if (inline) {\n return sidebarContent;\n }\n\n // Render to portal for proper stacking\n if (typeof document !== 'undefined') {\n return createPortal(sidebarContent, resolveContainer());\n }\n\n return null;\n }\n);\n\n// Sub-components\n\n/**\n * Props for the SidebarHeader component.\n */\ninterface SidebarHeaderProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Header content. */\n children?: React.ReactNode;\n}\n\n/**\n * Container for the sidebar header.\n *\n * @function\n * @param {SidebarHeaderProps} props - Props for the SidebarHeader component.\n * @returns {JSX.Element} The rendered sidebar header.\n */\nconst SidebarHeader: React.FC<SidebarHeaderProps> = ({\n className,\n children,\n ...props\n}) => {\n const headerClass = usePrefixedClassNames('sidebar-header');\n return (\n <div className={classNames(headerClass, className)} {...props}>\n {children}\n </div>\n );\n};\n\n/**\n * Props for the SidebarTitle component.\n */\ninterface SidebarTitleProps extends React.HTMLAttributes<HTMLParagraphElement> {\n /** Title content. */\n children?: React.ReactNode;\n}\n\n/**\n * Title text inside the header.\n *\n * @function\n * @param {SidebarTitleProps} props - Props for the SidebarTitle component.\n * @returns {JSX.Element} The rendered sidebar title.\n */\nconst SidebarTitle: React.FC<SidebarTitleProps> = ({\n className,\n children,\n ...props\n}) => {\n const titleClass = usePrefixedClassNames('sidebar-title');\n return (\n <p className={classNames(titleClass, className)} {...props}>\n {children}\n </p>\n );\n};\n\n/**\n * Props for the SidebarClose component.\n * Extends standard button attributes.\n * @extraProp {'button' | 'submit' | 'reset'} [type='button'] - Button type. Defaults to `'button'`, so a close button inside a form does not submit it. Pass `'submit'` or `'reset'` and yours is used; any other value, or a spread carrying `type: undefined`, renders `'button'`.\n * @extraProp {string} [aria-label='Close'] - Accessible name. Pass your own to replace it. An empty one, or a spread carrying `'aria-label': undefined`, keeps the default rather than leaving the button unnamed.\n */\ntype SidebarCloseProps = React.ButtonHTMLAttributes<HTMLButtonElement>;\n\n/**\n * Close button for the sidebar.\n *\n * @function\n * @param {SidebarCloseProps} props - Props for the SidebarClose component.\n * @returns {JSX.Element} The rendered close button.\n */\nconst SidebarClose: React.FC<SidebarCloseProps> = ({\n className,\n children,\n ...props\n}) => {\n const closeClass = usePrefixedClassNames('sidebar-close');\n return (\n <button\n className={classNames(closeClass, className)}\n {...props}\n // After the spread, reading through it: a key the spread carries with no\n // value would otherwise erase the default, leaving a nameless button\n // that submits the form around it. An empty label falls back too: the\n // button is drawn as an icon, so `''` would leave it unnamed. A caller's\n // own value still wins; `buttonType` says more.\n aria-label={props['aria-label'] || 'Close'}\n type={buttonType(props.type)}\n >\n {children}\n </button>\n );\n};\n\n/**\n * Props for the SidebarBody component.\n */\ninterface SidebarBodyProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Body content. */\n children?: React.ReactNode;\n}\n\n/**\n * Main content area of the sidebar.\n *\n * @function\n * @param {SidebarBodyProps} props - Props for the SidebarBody component.\n * @returns {JSX.Element} The rendered sidebar body.\n */\nconst SidebarBody: React.FC<SidebarBodyProps> = ({\n className,\n children,\n ...props\n}) => {\n const bodyClass = usePrefixedClassNames('sidebar-body');\n return (\n <div className={classNames(bodyClass, className)} {...props}>\n {children}\n </div>\n );\n};\n\n/**\n * Props for the SidebarFooter component.\n */\ninterface SidebarFooterProps extends React.HTMLAttributes<HTMLDivElement> {\n /** Footer content. */\n children?: React.ReactNode;\n}\n\n/**\n * Footer area of the sidebar.\n *\n * @function\n * @param {SidebarFooterProps} props - Props for the SidebarFooter component.\n * @returns {JSX.Element} The rendered sidebar footer.\n */\nconst SidebarFooter: React.FC<SidebarFooterProps> = ({\n className,\n children,\n ...props\n}) => {\n const footerClass = usePrefixedClassNames('sidebar-footer');\n return (\n <div className={classNames(footerClass, className)} {...props}>\n {children}\n </div>\n );\n};\n\n// Attach static subcomponents\nexport const Sidebar = withSubComponents(\n SidebarComponent,\n {\n Header: SidebarHeader,\n Title: SidebarTitle,\n Close: SidebarClose,\n Body: SidebarBody,\n Footer: SidebarFooter,\n },\n 'Sidebar'\n);\n\nexport default Sidebar;\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;;;;;;;;;AAsFA;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;AACH,MAAM,gBAAgB,GAAG,UAAU,CACjC,CACE,EACE,MAAM,EACN,OAAO,EACP,QAAQ,GAAG,MAAM,EACjB,KAAK,GAAG,OAAO,EACf,WAAW,EACX,SAAS,EACT,OAAO,GAAG,IAAI,EACd,YAAY,GAAG,IAAI,EACnB,WAAW,GAAG,IAAI,EAClB,SAAS,GAAG,IAAI,EAChB,QAAQ,EACR,MAAM,GAAG,KAAK,EACd,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EACD,GAAG,KACD;IACF,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC;AAC3D,IAAA,MAAM,gBAAgB,GAAG,kBAAkB,EAAE;AAC7C,IAAA,MAAM,EAAE,eAAe,EAAE,GAAG,SAAS,EAAE;;;IAGvC,MAAM,aAAa,GAAG,MAAM,GAAG,SAAS,GAAG,eAAe;AAC1D,IAAA,MAAM,UAAU,GAAG,MAAM,CAAc,IAAI,CAAC;;AAE5C,IAAA,MAAM,kBAAkB,GAAG,MAAM,CAAsB,IAAI,CAAC;AAC5D,IAAA,MAAM,iBAAiB,GAAG,WAAW,IAAI,SAAS,IAAI,KAAK;;AAG3D,IAAA,MAAM,WAAW,GAAG,WAAW,CAAC,MAAK;AACnC,QAAA,IAAI,SAAS,IAAI,OAAO,EAAE;AACxB,YAAA,OAAO,EAAE;QACX;AACF,IAAA,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;;AAGxB,IAAA,MAAM,kBAAkB,GAAG,WAAW,CAAC,MAAK;QAC1C,IAAI,YAAY,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;;AAMG;AACH,MAAM,WAAW,GAA+B,CAAC,EAC/C,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,KAAI;AACH,IAAA,MAAM,SAAS,GAAG,qBAAqB,CAAC,cAAc,CAAC;AACvD,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,SAAS,CAAC,KAAM,KAAK,EAAA,QAAA,EACxD,QAAQ,EAAA,CACL;AAEV,CAAC;AAUD;;;;;;AAMG;AACH,MAAM,aAAa,GAAiC,CAAC,EACnD,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,KAAI;AACH,IAAA,MAAM,WAAW,GAAG,qBAAqB,CAAC,gBAAgB,CAAC;AAC3D,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,UAAU,CAAC,WAAW,EAAE,SAAS,CAAC,KAAM,KAAK,EAAA,QAAA,EAC1D,QAAQ,EAAA,CACL;AAEV,CAAC;AAED;AACO,MAAM,OAAO,GAAG,iBAAiB,CACtC,gBAAgB,EAChB;AACE,IAAA,MAAM,EAAE,aAAa;AACrB,IAAA,KAAK,EAAE,YAAY;AACnB,IAAA,KAAK,EAAE,YAAY;AACnB,IAAA,IAAI,EAAE,WAAW;AACjB,IAAA,MAAM,EAAE,aAAa;CACtB,EACD,SAAS;;"}
|
|
@@ -20,23 +20,15 @@ const Image = ({ as, className, textColor, color, bgColor, size, isRounded, isRe
|
|
|
20
20
|
backgroundColor: bgColor,
|
|
21
21
|
...props,
|
|
22
22
|
});
|
|
23
|
+
// Bulma reads `.has-ratio` only on a child of the ratio container, so the
|
|
24
|
+
// container carries just its `is-<ratio>` class.
|
|
23
25
|
const bulmaClasses = usePrefixedClassNames('image', {
|
|
24
26
|
[`is-${size}`]: size,
|
|
25
|
-
'has-ratio': size && typeof size === 'string' && size.includes('by'),
|
|
26
27
|
});
|
|
27
28
|
const imageClasses = classNames(bulmaClasses, bulmaHelperClasses, className);
|
|
28
29
|
// Default tag logic: if "as" is provided, use it.
|
|
29
|
-
// If not, use <figure> for aspect ratios
|
|
30
|
-
|
|
31
|
-
if (as) {
|
|
32
|
-
Tag = as;
|
|
33
|
-
}
|
|
34
|
-
else if (size && typeof size === 'string' && size.includes('by')) {
|
|
35
|
-
Tag = 'figure';
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
Tag = 'div';
|
|
39
|
-
}
|
|
30
|
+
// If not, use <figure> for aspect ratios, <div> otherwise.
|
|
31
|
+
const Tag = as ?? (size?.includes('by') ? 'figure' : 'div');
|
|
40
32
|
const roundedClass = usePrefixedClassNames('is-rounded');
|
|
41
33
|
const content = children ? (children) : (jsx("img", { className: classNames({ [roundedClass]: isRounded }) || undefined, src: src, alt: alt, ...(isRetina && src ? { srcSet: `${src} 2x` } : {}) }));
|
|
42
34
|
return (jsx(Tag, { className: imageClasses, ...rest, children: content }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Image.js","sources":["../../../src/elements/Image.tsx"],"sourcesContent":["import React from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport {\n useBulmaClasses,\n BulmaClassesProps,\n validColors,\n} from '../helpers/useBulmaClasses';\n\n/**\n * Props for the Image component.\n */\nexport interface ImageProps\n extends\n React.HTMLAttributes<HTMLElement>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /** Additional CSS classes to apply. */\n className?: string;\n /** Text color helper for the container. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /**\n * Text color alias: renders `has-text-<color>`, exactly like `textColor`.\n * Not a filled variant (no `.image.is-<color>` CSS exists). Prefer\n * `textColor`, which takes precedence when both are set; use `bgColor` for\n * a colored surface.\n */\n color?: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n /** Background color helper for the container. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n
|
|
1
|
+
{"version":3,"file":"Image.js","sources":["../../../src/elements/Image.tsx"],"sourcesContent":["import React from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport {\n useBulmaClasses,\n BulmaClassesProps,\n validColors,\n} from '../helpers/useBulmaClasses';\n\n/**\n * Props for the Image component.\n */\nexport interface ImageProps\n extends\n React.HTMLAttributes<HTMLElement>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /** Additional CSS classes to apply. */\n className?: string;\n /** Text color helper for the container. */\n textColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /**\n * Text color alias: renders `has-text-<color>`, exactly like `textColor`.\n * Not a filled variant (no `.image.is-<color>` CSS exists). Prefer\n * `textColor`, which takes precedence when both are set; use `bgColor` for\n * a colored surface.\n */\n color?: 'primary' | 'link' | 'info' | 'success' | 'warning' | 'danger';\n /** Background color helper for the container. */\n bgColor?: (typeof validColors)[number] | 'inherit' | 'current';\n /**\n * Fixed size or aspect ratio modifier for the image container. A ratio\n * (`16by9` and the rest) renders only its `is-<ratio>` class there. Bulma\n * stretches an `<img>` inside to fill the ratio, but any other child, such\n * as an `iframe`, fills it only with `className=\"has-ratio\"` of its own.\n */\n size?:\n | '16x16'\n | '24x24'\n | '32x32'\n | '48x48'\n | '64x64'\n | '96x96'\n | '128x128'\n | 'square'\n | '1by1'\n | '5by4'\n | '4by3'\n | '3by2'\n | '5by3'\n | '16by9'\n | '2by1'\n | '3by1'\n | '4by5'\n | '3by4'\n | '2by3'\n | '3by5'\n | '9by16'\n | '1by2'\n | '1by3';\n /** Renders the image with rounded corners. */\n isRounded?: boolean;\n /** Uses retina (2x) image source. */\n isRetina?: boolean;\n /** Image source URL. */\n src?: string;\n /** Alternate text for the image. */\n alt?: string;\n /** Arbitrary content (e.g., iframe, custom HTML) inside the image container. */\n children?: React.ReactNode;\n /** Container element tag. Defaults to `'figure'` when using aspect-ratio sizes, `'div'` otherwise. */\n as?: 'figure' | 'div' | 'p';\n}\n\n/**\n * The `Image` component wraps images, iframes, or custom content in a Bulma-styled container, supporting fixed sizes, aspect ratios, rounded corners, retina images, and all Bulma helper props for color and spacing.\n *\n * @function\n * @param {ImageProps} props - Props for the Image component.\n * @returns {JSX.Element} The rendered image element.\n * @see {@link https://bulma.io/documentation/elements/image/ | Bulma Image documentation}\n */\nexport const Image: React.FC<ImageProps> = ({\n as,\n className,\n textColor,\n color,\n bgColor,\n size,\n isRounded,\n isRetina,\n src,\n alt,\n children,\n ...props\n}) => {\n /**\n * Generates Bulma helper classes and separates out remaining props.\n */\n const { bulmaHelperClasses, rest } = useBulmaClasses({\n color: textColor ?? color,\n backgroundColor: bgColor,\n ...props,\n });\n\n // Bulma reads `.has-ratio` only on a child of the ratio container, so the\n // container carries just its `is-<ratio>` class.\n const bulmaClasses = usePrefixedClassNames('image', {\n [`is-${size}`]: size,\n });\n\n const imageClasses = classNames(bulmaClasses, bulmaHelperClasses, className);\n\n // Default tag logic: if \"as\" is provided, use it.\n // If not, use <figure> for aspect ratios, <div> otherwise.\n const Tag: 'figure' | 'div' | 'p' =\n as ?? (size?.includes('by') ? 'figure' : 'div');\n\n const roundedClass = usePrefixedClassNames('is-rounded');\n\n const content = children ? (\n children\n ) : (\n <img\n className={classNames({ [roundedClass]: isRounded }) || undefined}\n src={src}\n alt={alt}\n {...(isRetina && src ? { srcSet: `${src} 2x` } : {})}\n />\n );\n\n return (\n <Tag className={imageClasses} {...rest}>\n {content}\n </Tag>\n );\n};\n\nexport default Image;\n"],"names":["_jsx"],"mappings":";;;;;AAwEA;;;;;;;AAOG;AACI,MAAM,KAAK,GAAyB,CAAC,EAC1C,EAAE,EACF,SAAS,EACT,SAAS,EACT,KAAK,EACL,OAAO,EACP,IAAI,EACJ,SAAS,EACT,QAAQ,EACR,GAAG,EACH,GAAG,EACH,QAAQ,EACR,GAAG,KAAK,EACT,KAAI;AACH;;AAEG;AACH,IAAA,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC;QACnD,KAAK,EAAE,SAAS,IAAI,KAAK;AACzB,QAAA,eAAe,EAAE,OAAO;AACxB,QAAA,GAAG,KAAK;AACT,KAAA,CAAC;;;AAIF,IAAA,MAAM,YAAY,GAAG,qBAAqB,CAAC,OAAO,EAAE;AAClD,QAAA,CAAC,CAAA,GAAA,EAAM,IAAI,CAAA,CAAE,GAAG,IAAI;AACrB,KAAA,CAAC;IAEF,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,EAAE,kBAAkB,EAAE,SAAS,CAAC;;;IAI5E,MAAM,GAAG,GACP,EAAE,KAAK,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEjD,IAAA,MAAM,YAAY,GAAG,qBAAqB,CAAC,YAAY,CAAC;IAExD,MAAM,OAAO,GAAG,QAAQ,IACtB,QAAQ,KAERA,GAAA,CAAA,KAAA,EAAA,EACE,SAAS,EAAE,UAAU,CAAC,EAAE,CAAC,YAAY,GAAG,SAAS,EAAE,CAAC,IAAI,SAAS,EACjE,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EAAA,IACH,QAAQ,IAAI,GAAG,GAAG,EAAE,MAAM,EAAE,CAAA,EAAG,GAAG,CAAA,GAAA,CAAK,EAAE,GAAG,EAAE,CAAC,EAAA,CACpD,CACH;AAED,IAAA,QACEA,GAAA,CAAC,GAAG,EAAA,EAAC,SAAS,EAAE,YAAY,EAAA,GAAM,IAAI,EAAA,QAAA,EACnC,OAAO,EAAA,CACJ;AAEV;;"}
|
|
@@ -36,7 +36,7 @@ const isDetailsSummary = (el) => el.parentElement?.localName === 'details' &&
|
|
|
36
36
|
* can read `-1` for an editable region or an `<embed>` that Tab still visits,
|
|
37
37
|
* and `0` for a `<video>` without controls that it doesn't. So a valid
|
|
38
38
|
* `tabindex` attribute decides, and otherwise the element's kind does.
|
|
39
|
-
* Internal like `
|
|
39
|
+
* Internal like `focusTabStop`: `src/index.ts` names what it takes from here.
|
|
40
40
|
*/
|
|
41
41
|
function isTabbableKind(el) {
|
|
42
42
|
const tabindex = el.getAttribute('tabindex');
|
|
@@ -269,31 +269,25 @@ function findTabStops(container) {
|
|
|
269
269
|
return stop;
|
|
270
270
|
};
|
|
271
271
|
const isStop = (el) => usable(el) && (!isGroupedRadio(el) || groupStop(el) === el);
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
break;
|
|
272
|
+
// Checked only as they're reached, and the checks are kept, so finding
|
|
273
|
+
// both ends costs what it did when only the ends were looked for.
|
|
274
|
+
function* from(fromLast) {
|
|
275
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
276
|
+
const el = candidates[fromLast ? candidates.length - 1 - i : i];
|
|
277
|
+
if (isStop(el))
|
|
278
|
+
yield el;
|
|
280
279
|
}
|
|
281
280
|
}
|
|
281
|
+
const first = from(false).next().value;
|
|
282
|
+
if (!first)
|
|
283
|
+
return null;
|
|
282
284
|
return {
|
|
283
285
|
first,
|
|
284
|
-
last,
|
|
286
|
+
last: from(true).next().value,
|
|
285
287
|
stopFor: node => (isGroupedRadio(node) && groupStop(node)) || node,
|
|
288
|
+
from,
|
|
286
289
|
};
|
|
287
290
|
}
|
|
288
|
-
/**
|
|
289
|
-
* The first tab stop inside `container`, found the way the trap finds it, or
|
|
290
|
-
* `null` when there is none. For a component that moves focus into a panel
|
|
291
|
-
* itself rather than through the hook. `src/index.ts` names its exports from
|
|
292
|
-
* this module, so this one stays internal.
|
|
293
|
-
*/
|
|
294
|
-
function firstTabStop(container) {
|
|
295
|
-
return findTabStops(container)?.first ?? null;
|
|
296
|
-
}
|
|
297
291
|
/**
|
|
298
292
|
* The element that has focus in the container's own document (an iframe's,
|
|
299
293
|
* when it renders into one), inside open shadow roots too. Focus inside a
|
|
@@ -303,24 +297,47 @@ function firstTabStop(container) {
|
|
|
303
297
|
* was inside a shadow root that was removed, so this falls back for it.
|
|
304
298
|
*/
|
|
305
299
|
const focusedElement = (doc) => getDeepestActiveElement(doc) ?? doc.body;
|
|
300
|
+
/**
|
|
301
|
+
* Moves focus to the first tab stop inside `container`, or the last when
|
|
302
|
+
* `fromLast`, and to the container when there is none. Every move a trap
|
|
303
|
+
* makes goes through here: into the container as it opens, to the other end
|
|
304
|
+
* on a wrap, and back in after a Tab the browser carried out.
|
|
305
|
+
*
|
|
306
|
+
* A stop that doesn't take focus is passed over for the next one in. An
|
|
307
|
+
* `<object>` or `<embed>` with nothing to show is one: it counts as a stop by
|
|
308
|
+
* its kind, but browsers refuse to focus it, and which ones they refuse
|
|
309
|
+
* depends on the browser and on what has loaded, so only trying tells. A
|
|
310
|
+
* stop took focus when focus moved, wherever it went (a stop can hand focus
|
|
311
|
+
* on), or when focus was on it already. `src/index.ts` names its exports from
|
|
312
|
+
* this module, so this one stays internal.
|
|
313
|
+
*/
|
|
314
|
+
function focusTabStop(container, fromLast = false) {
|
|
315
|
+
const doc = container.ownerDocument;
|
|
316
|
+
for (const stop of findTabStops(container)?.from(fromLast) ?? []) {
|
|
317
|
+
const before = focusedElement(doc);
|
|
318
|
+
stop.focus();
|
|
319
|
+
const now = focusedElement(doc);
|
|
320
|
+
if (now !== before || inside(stop, now))
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
container.focus();
|
|
324
|
+
}
|
|
306
325
|
/**
|
|
307
326
|
* Handles a Tab for a trap on `container`. When the browser has no tab stop
|
|
308
327
|
* left in that direction inside the container, focus goes to the stop at the
|
|
309
328
|
* other end and the key is marked used, and with no stops at all the
|
|
310
329
|
* container takes focus. Focus outside the container goes in at that end
|
|
311
|
-
* too.
|
|
312
|
-
* to should that Tab take it out anyway.
|
|
330
|
+
* too. Returns whether it moved focus; otherwise the browser does.
|
|
313
331
|
*/
|
|
314
332
|
function wrapTab(e, container) {
|
|
315
333
|
const stops = findTabStops(container);
|
|
316
334
|
if (!stops) {
|
|
317
335
|
e.preventDefault();
|
|
318
336
|
container.focus();
|
|
319
|
-
return
|
|
337
|
+
return true;
|
|
320
338
|
}
|
|
321
339
|
const focused = focusedElement(container.ownerDocument);
|
|
322
340
|
const current = stops.stopFor(focused);
|
|
323
|
-
const end = e.shiftKey ? stops.last : stops.first;
|
|
324
341
|
// Wrap whenever the browser has no stop left in that direction inside the
|
|
325
342
|
// container. Comparing positions rather than testing `=== first` also
|
|
326
343
|
// covers focus resting on the container or on an element outside the tab
|
|
@@ -330,10 +347,10 @@ function wrapTab(e, container) {
|
|
|
330
347
|
? !follows(container, stops.first, current)
|
|
331
348
|
: !follows(container, current, stops.last))) {
|
|
332
349
|
e.preventDefault();
|
|
333
|
-
|
|
334
|
-
return
|
|
350
|
+
focusTabStop(container, e.shiftKey);
|
|
351
|
+
return true;
|
|
335
352
|
}
|
|
336
|
-
return
|
|
353
|
+
return false;
|
|
337
354
|
}
|
|
338
355
|
/**
|
|
339
356
|
* Holds Tab inside the element `container` returns until the returned
|
|
@@ -345,7 +362,7 @@ function wrapTab(e, container) {
|
|
|
345
362
|
* overlay whose nodes are remounted while it's open, as moving to another
|
|
346
363
|
* portal target does, stays trapped without attaching again. `holds` is asked
|
|
347
364
|
* on every Tab, and the trap leaves the key alone while it says no. Internal
|
|
348
|
-
* like `
|
|
365
|
+
* like `focusTabStop`. It's for an overlay that holds Tab from a listener of
|
|
349
366
|
* its own on `window` and asks the overlay stack first, so it stands aside
|
|
350
367
|
* while another overlay is open over it, which a trap listening on the
|
|
351
368
|
* container can't do.
|
|
@@ -356,9 +373,10 @@ function trapTab(container, keyTarget, holds = () => true) {
|
|
|
356
373
|
// A window and an element type their listeners differently, so the trap
|
|
357
374
|
// listens through the base type both share.
|
|
358
375
|
const keys = keyTarget;
|
|
359
|
-
//
|
|
360
|
-
// held until that Tab has finished
|
|
361
|
-
|
|
376
|
+
// The end focus goes back to if a Tab the trap let the browser handle
|
|
377
|
+
// takes it out (the last for Shift+Tab), held until that Tab has finished
|
|
378
|
+
// moving focus, and `null` otherwise.
|
|
379
|
+
let wrapFromLast = null;
|
|
362
380
|
let wrapTimer;
|
|
363
381
|
// `keyTarget` is any target, so the listener takes the base event type.
|
|
364
382
|
const handleKeyDown = (event) => {
|
|
@@ -367,24 +385,25 @@ function trapTab(container, keyTarget, holds = () => true) {
|
|
|
367
385
|
// A trap nested inside this one has already wrapped focus.
|
|
368
386
|
if (e.key !== 'Tab' || e.defaultPrevented || !box || !holds())
|
|
369
387
|
return;
|
|
370
|
-
|
|
371
|
-
if (!end)
|
|
388
|
+
if (wrapTab(e, box))
|
|
372
389
|
return;
|
|
373
|
-
|
|
390
|
+
wrapFromLast = e.shiftKey;
|
|
374
391
|
clearTimeout(wrapTimer);
|
|
375
392
|
wrapTimer = setTimeout(() => {
|
|
376
|
-
|
|
393
|
+
wrapFromLast = null;
|
|
377
394
|
});
|
|
378
395
|
};
|
|
379
396
|
// The browser moves focus as soon as the keydown is over, so focus that
|
|
380
|
-
// lands outside while `
|
|
397
|
+
// lands outside while `wrapFromLast` is set got there by that Tab.
|
|
381
398
|
const handleFocusIn = (e) => {
|
|
382
399
|
const box = container();
|
|
383
|
-
if (
|
|
400
|
+
if (wrapFromLast === null || !box)
|
|
401
|
+
return;
|
|
402
|
+
if (inside(box, e.composedPath()[0]))
|
|
384
403
|
return;
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
|
|
404
|
+
const fromLast = wrapFromLast;
|
|
405
|
+
wrapFromLast = null;
|
|
406
|
+
focusTabStop(box, fromLast);
|
|
388
407
|
};
|
|
389
408
|
keys.addEventListener('keydown', handleKeyDown);
|
|
390
409
|
doc.addEventListener('focusin', handleFocusIn, true);
|
|
@@ -470,7 +489,7 @@ function useFocusTrap(containerRef, options = {}) {
|
|
|
470
489
|
const inTrap = initial && inside(container, initial) ? initial : null;
|
|
471
490
|
inTrap?.focus();
|
|
472
491
|
if (!inTrap || !inside(container, focusedElement(doc))) {
|
|
473
|
-
(
|
|
492
|
+
focusTabStop(container);
|
|
474
493
|
}
|
|
475
494
|
const releaseTab = trapTab(() => container, container);
|
|
476
495
|
return () => {
|
|
@@ -514,5 +533,5 @@ function useFocusTrap(containerRef, options = {}) {
|
|
|
514
533
|
});
|
|
515
534
|
}
|
|
516
535
|
|
|
517
|
-
export {
|
|
536
|
+
export { focusTabStop, isTabbableKind, trapTab, useFocusTrap };
|
|
518
537
|
//# sourceMappingURL=useFocusTrap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusTrap.js","sources":["../../../src/helpers/useFocusTrap.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport type { RefObject } from 'react';\nimport { useIsHydrated } from './useIsHydrated';\nimport { getDeepestActiveElement } from './shadowDom';\n\n/**\n * Whether `el` is editable while its parent is not, which makes it an editing\n * host: the one tab stop an editable region gets. `contenteditable=\"false\"`\n * turns editing off, and a missing or unknown value inherits the parent's.\n */\nfunction isEditingHost(el: Element): boolean {\n const editable = (node: Element): boolean | null => {\n const value = node.getAttribute('contenteditable')?.toLowerCase();\n if (value === undefined) return null;\n if (value === '' || value === 'true' || value === 'plaintext-only') {\n return true;\n }\n return value === 'false' ? false : null;\n };\n if (editable(el) !== true) return false;\n for (let node = el.parentElement; node; node = node.parentElement) {\n const state = editable(node);\n if (state !== null) return !state;\n }\n return true;\n}\n\n/** Whether `el` is the summary of its `<details>`: the first one, not a stray. */\nconst isDetailsSummary = (el: Element): boolean =>\n el.parentElement?.localName === 'details' &&\n Array.from(el.parentElement.children).find(\n child => child.localName === 'summary'\n ) === el;\n\n/**\n * Whether the browser puts `el` in the tab order, before anything that hides\n * or disables it. The `tabIndex` property can't answer this on its own: it\n * can read `-1` for an editable region or an `<embed>` that Tab still visits,\n * and `0` for a `<video>` without controls that it doesn't. So a valid\n * `tabindex` attribute decides, and otherwise the element's kind does.\n * Internal like `firstTabStop`: `src/index.ts` names what it takes from here.\n */\nexport function isTabbableKind(el: Element): boolean {\n const tabindex = el.getAttribute('tabindex');\n if (tabindex !== null && /^\\s*[+-]?\\d/.test(tabindex)) {\n return (el as HTMLElement).tabIndex >= 0;\n }\n switch (el.localName) {\n case 'a':\n case 'area':\n return el.hasAttribute('href');\n case 'input':\n return (el as HTMLInputElement).type !== 'hidden';\n case 'button':\n case 'select':\n case 'textarea':\n case 'iframe':\n case 'embed':\n case 'object':\n return true;\n case 'audio':\n case 'video':\n return el.hasAttribute('controls');\n case 'summary':\n return isDetailsSummary(el);\n default:\n return isEditingHost(el);\n }\n}\n\n/**\n * The node's parent in the flattened tree, the one the browser renders and\n * tabs through: the slot it is assigned to, else its parent, else the host of\n * the shadow root it tops, and nothing above the document. A closed shadow\n * root hides its slots (`assignedSlot` reads `null` under one), so a child of\n * its host goes straight to the host, whether a slot takes it or not.\n */\nconst flatParent = (node: Node): Node | null =>\n (node as Element).assignedSlot ??\n node.parentElement ??\n (node.parentNode as ShadowRoot | null)?.host ??\n null;\n\n/**\n * The element's children in the flattened tree, in the order they render: a\n * host's shadow root content, a slot's assigned elements (or its fallback\n * content when nothing is assigned), anything else's own children. A host\n * whose shadow root is closed has no root to read, so its own children stand\n * in, including any that no slot takes and that aren't rendered.\n */\nfunction flatChildren(el: Element): Element[] {\n if (el.shadowRoot) return Array.from(el.shadowRoot.children);\n if (el.localName === 'slot') {\n const assigned = (el as HTMLSlotElement).assignedNodes();\n if (assigned.length > 0) {\n return assigned.filter(\n (node): node is Element => node.nodeType === Node.ELEMENT_NODE\n );\n }\n }\n return Array.from(el.children);\n}\n\nconst isShown = (el: Element): boolean =>\n !el.hasAttribute('inert') && getComputedStyle(el).display !== 'none';\n\nconst isVisible = (el: Element): boolean => {\n const { visibility } = getComputedStyle(el);\n return visibility !== 'hidden' && visibility !== 'collapse';\n};\n\n/**\n * Whether nothing from `el` up to `top` hides it: `inert`, `display: none`\n * (not inherited, so each element is checked) or a closed `<details>` it\n * isn't the summary of. `top` itself isn't checked, and `null` walks to the\n * top of the page.\n */\nfunction isShownUpTo(el: Element, top: Node | null): boolean {\n let below: Element | null = null;\n for (\n let node: Element | null = el;\n node && node !== top;\n node = flatParent(node) as Element | null\n ) {\n if (!isShown(node)) return false;\n if (\n below &&\n node.localName === 'details' &&\n !node.hasAttribute('open') &&\n !isDetailsSummary(below)\n ) {\n return false;\n }\n below = node;\n }\n return true;\n}\n\n/**\n * The images that use the image map `area` belongs to. An image names its\n * map with `usemap=\"#…\"`, matching the map's `name` or `id`.\n */\nfunction imagesUsingMapOf(area: Element): Element[] {\n const map = area.closest('map');\n if (!map) return [];\n const names = [map.getAttribute('name'), map.id].filter(name => name);\n return Array.from(\n (area.getRootNode() as ParentNode).querySelectorAll('img[usemap]')\n ).filter(img => {\n const ref = img.getAttribute('usemap') as string;\n return ref.startsWith('#') && names.includes(ref.slice(1));\n });\n}\n\n/**\n * Whether an image map area is shown. An area has no box of its own: the\n * HTML rendering rules give it `display: none`, though a browser may not\n * report that. So it counts where an image using its map is shown, as long\n * as nothing makes it inert.\n */\nfunction isAreaShown(area: Element, container: Element): boolean {\n for (\n let node: Element | null = area;\n node && node !== container;\n node = flatParent(node) as Element | null\n ) {\n if (node.hasAttribute('inert')) return false;\n }\n return imagesUsingMapOf(area).some(\n img => isShownUpTo(img, null) && isVisible(img)\n );\n}\n\n/**\n * Whether Tab can land on `el`, one of the kinds it visits. A disabled control\n * (including one inside a disabled `<fieldset>`), an inert subtree and\n * anything not rendered are skipped. `visibility` is inherited, so the\n * element's own computed value covers its ancestors.\n */\nfunction isRenderedAndEnabled(el: Element, container: Element): boolean {\n if (el.matches(':disabled')) return false;\n if (el.localName === 'area') return isAreaShown(el, container);\n return isShownUpTo(el, container) && isVisible(el);\n}\n\n/** A radio button with a name, which shares one tab stop with its group. */\nconst isGroupedRadio = (el: Element): el is HTMLInputElement =>\n el.localName === 'input' &&\n (el as HTMLInputElement).type === 'radio' &&\n (el as HTMLInputElement).name !== '';\n\n/** Whether two radio buttons are in one group: same name, form owner and tree. */\nconst sameGroup = (a: HTMLInputElement, b: Element): b is HTMLInputElement =>\n isGroupedRadio(b) &&\n b.name === a.name &&\n b.form === a.form &&\n b.getRootNode() === a.getRootNode();\n\n/**\n * The checked button of `radio`'s group. The group isn't bounded by the trap,\n * so this looks through the radio's whole tree.\n */\nconst checkedInGroup = (radio: HTMLInputElement): Element | undefined =>\n Array.from(\n (radio.getRootNode() as ParentNode).querySelectorAll('input:checked')\n ).find(el => sameGroup(radio, el));\n\n/** The flattened-tree ancestors of `node` below the container, outermost first, then `node`. */\nfunction flatChain(node: Node, container: Node): Node[] {\n const chain: Node[] = [];\n for (let n: Node | null = node; n && n !== container; n = flatParent(n)) {\n chain.unshift(n);\n }\n return chain;\n}\n\n/**\n * Whether `node` is inside the container in the flattened tree: in it, in a\n * shadow root it holds, or slotted into it. A child of a closed-root host\n * counts as inside wherever the host is, as its slot can't be seen.\n */\nfunction inside(container: Node, node: Node): boolean {\n for (let n: Node | null = node; n; n = flatParent(n)) {\n if (n === container) return true;\n }\n return false;\n}\n\n/**\n * `true` when Tab reaches `b` after `a`, which is their order in the\n * flattened tree: a shadow host comes before its shadow root's content, and\n * slotted content comes where its slot is. A closed root's slots can't be\n * seen, so its host's children keep their place in the light DOM. Two\n * flattened-tree siblings are always in one DOM tree, so their document\n * position decides between them.\n */\nfunction follows(container: Element, a: Node, b: Node): boolean {\n const chainA = flatChain(a, container);\n const chainB = flatChain(b, container);\n for (let i = 0; i < Math.max(chainA.length, chainB.length); i++) {\n const [x, y] = [chainA[i], chainB[i]];\n if (x === y) continue;\n if (!x) return true;\n if (!y) return false;\n return Boolean(\n x.compareDocumentPosition(y) & Node.DOCUMENT_POSITION_FOLLOWING\n );\n }\n return false;\n}\n\n/**\n * Every element of a tabbable kind under `el` in the flattened tree, depth\n * first, which is the order Tab visits them. Under a host whose shadow root\n * is closed, that takes in the host's own children instead, rendered or not.\n */\nfunction collectCandidates(\n el: Element,\n out: HTMLElement[] = []\n): HTMLElement[] {\n for (const child of flatChildren(el)) {\n if (isTabbableKind(child)) out.push(child as HTMLElement);\n collectCandidates(child, out);\n }\n return out;\n}\n\ninterface TabStops {\n first: HTMLElement;\n last: HTMLElement;\n /** The stop that stands for `node`: its group's stop for a radio button. */\n stopFor(node: Element): Element;\n}\n\n/**\n * The first and last tab stops inside `container`, or `null` when there are\n * none. Only the ends matter for wrapping, so the style checks run from each\n * end until they find a stop rather than over every candidate.\n *\n * A radio group is one stop, the way the browser treats it: its checked\n * button, or its first when none is checked. Counting every button would make\n * the group's last one an end, and Tab from the checked one would leave. The\n * group goes by name, form owner and tree, not by the trap, so a checked\n * button outside the container that Tab can land on leaves the group no stop\n * inside. One that Tab can't land on leaves the group as if none were checked.\n */\nfunction findTabStops(container: HTMLElement): TabStops | null {\n const candidates = collectCandidates(container);\n const checked = new Map<Element, boolean>();\n const usable = (el: Element): boolean => {\n let ok = checked.get(el);\n if (ok === undefined) {\n ok = isRenderedAndEnabled(el, container);\n checked.set(el, ok);\n }\n return ok;\n };\n // Resolved once per group, filed under each of its buttons, since finding\n // the checked one scans the radio's whole tree.\n const groupStops = new Map<Element, HTMLElement | undefined>();\n const groupStop = (radio: HTMLInputElement): HTMLElement | undefined => {\n if (groupStops.has(radio)) return groupStops.get(radio);\n const group = candidates.filter(el => sameGroup(radio, el));\n const on = checkedInGroup(radio);\n const stop =\n on && isTabbableKind(on) && usable(on)\n ? group.find(el => el === on)\n : group.find(usable);\n for (const el of [radio, ...group]) groupStops.set(el, stop);\n return stop;\n };\n const isStop = (el: HTMLElement): boolean =>\n usable(el) && (!isGroupedRadio(el) || groupStop(el) === el);\n\n const first = candidates.find(isStop);\n if (!first) return null;\n let last = first;\n for (let i = candidates.length - 1; candidates[i] !== first; i--) {\n if (isStop(candidates[i])) {\n last = candidates[i];\n break;\n }\n }\n return {\n first,\n last,\n stopFor: node => (isGroupedRadio(node) && groupStop(node)) || node,\n };\n}\n\n/**\n * The first tab stop inside `container`, found the way the trap finds it, or\n * `null` when there is none. For a component that moves focus into a panel\n * itself rather than through the hook. `src/index.ts` names its exports from\n * this module, so this one stays internal.\n */\nexport function firstTabStop(container: HTMLElement): HTMLElement | null {\n return findTabStops(container)?.first ?? null;\n}\n\n/**\n * The element that has focus in the container's own document (an iframe's,\n * when it renders into one), inside open shadow roots too. Focus inside a\n * closed one reads as its host, which the comparisons above place like any\n * other element. Browsers fall back to <body> when nothing has\n * focus. jsdom, where consumers run their tests, reports nothing once focus\n * was inside a shadow root that was removed, so this falls back for it.\n */\nconst focusedElement = (doc: Document): Element =>\n getDeepestActiveElement(doc) ?? doc.body;\n\n/**\n * Handles a Tab for a trap on `container`. When the browser has no tab stop\n * left in that direction inside the container, focus goes to the stop at the\n * other end and the key is marked used, and with no stops at all the\n * container takes focus. Focus outside the container goes in at that end\n * too. Otherwise the browser moves focus, and this returns the end to send it\n * to should that Tab take it out anyway.\n */\nfunction wrapTab(e: KeyboardEvent, container: HTMLElement): HTMLElement | null {\n const stops = findTabStops(container);\n if (!stops) {\n e.preventDefault();\n container.focus();\n return null;\n }\n const focused = focusedElement(container.ownerDocument);\n const current = stops.stopFor(focused);\n const end = e.shiftKey ? stops.last : stops.first;\n // Wrap whenever the browser has no stop left in that direction inside the\n // container. Comparing positions rather than testing `=== first` also\n // covers focus resting on the container or on an element outside the tab\n // order, which the browser would otherwise walk straight out of.\n if (\n !inside(container, focused) ||\n (e.shiftKey\n ? !follows(container, stops.first, current)\n : !follows(container, current, stops.last))\n ) {\n e.preventDefault();\n end.focus();\n return null;\n }\n return end;\n}\n\n/**\n * Holds Tab inside the element `container` returns until the returned\n * function is called. Tab and Shift+Tab heard on `keyTarget` wrap at the\n * ends, unless something already marked the key used, and if a Tab the trap\n * let through still takes focus out, it sends focus back to the other end.\n *\n * `container` is read each time a key or a focus change arrives, so an\n * overlay whose nodes are remounted while it's open, as moving to another\n * portal target does, stays trapped without attaching again. `holds` is asked\n * on every Tab, and the trap leaves the key alone while it says no. Internal\n * like `firstTabStop`. It's for an overlay that holds Tab from a listener of\n * its own on `window` and asks the overlay stack first, so it stands aside\n * while another overlay is open over it, which a trap listening on the\n * container can't do.\n */\nexport function trapTab(\n container: () => HTMLElement | null,\n keyTarget: HTMLElement | Window,\n holds: () => boolean = () => true\n): () => void {\n // The document focus moves in: the window's own, or the element's.\n const doc =\n 'document' in keyTarget ? keyTarget.document : keyTarget.ownerDocument;\n // A window and an element type their listeners differently, so the trap\n // listens through the base type both share.\n const keys: EventTarget = keyTarget;\n // Where focus goes if a Tab the trap let the browser handle takes it out,\n // held until that Tab has finished moving focus.\n let wrapTo: HTMLElement | null = null;\n let wrapTimer: ReturnType<typeof setTimeout> | undefined;\n\n // `keyTarget` is any target, so the listener takes the base event type.\n const handleKeyDown = (event: Event) => {\n const e = event as KeyboardEvent;\n const box = container();\n // A trap nested inside this one has already wrapped focus.\n if (e.key !== 'Tab' || e.defaultPrevented || !box || !holds()) return;\n const end = wrapTab(e, box);\n if (!end) return;\n wrapTo = end;\n clearTimeout(wrapTimer);\n wrapTimer = setTimeout(() => {\n wrapTo = null;\n });\n };\n\n // The browser moves focus as soon as the keydown is over, so focus that\n // lands outside while `wrapTo` is set got there by that Tab.\n const handleFocusIn = (e: FocusEvent) => {\n const box = container();\n if (!wrapTo || !box || inside(box, e.composedPath()[0] as Node)) return;\n const target = wrapTo;\n wrapTo = null;\n target.focus();\n };\n\n keys.addEventListener('keydown', handleKeyDown);\n doc.addEventListener('focusin', handleFocusIn, true);\n return () => {\n keys.removeEventListener('keydown', handleKeyDown);\n doc.removeEventListener('focusin', handleFocusIn, true);\n clearTimeout(wrapTimer);\n };\n}\n\n/**\n * Options for `useFocusTrap`.\n */\nexport interface UseFocusTrapOptions {\n /**\n * Whether the trap is on. Turning it on moves focus into the container;\n * turning it off (or unmounting) releases Tab and restores focus.\n * @defaultValue true\n */\n active?: boolean;\n /**\n * The element inside the container to focus when the trap turns on. It has\n * to be one that can take focus, so a heading needs `tabIndex={-1}`. When\n * focusing it doesn't put focus inside the container (the ref is empty, or\n * its element is outside, disabled, hidden or can't take focus), focus goes\n * to the first tab stop inside the container, and to the container itself\n * when there is none.\n */\n initialFocusRef?: RefObject<HTMLElement | null>;\n /**\n * Where focus goes when the trap turns off. `true` returns it to the element\n * that had focus when the trap turned on; a ref sends it to that element\n * instead; `false` leaves it alone. Focus is only moved while the trap still\n * holds it, so a click that already put focus somewhere else outside the\n * container keeps it there.\n *\n * `true` reads focus after the container's content has mounted, so content\n * that focuses itself as it mounts (an `autoFocus` input) hides the element\n * that opened it. And some browsers don't focus a button when it is\n * clicked. For a panel opened from a button, pass the button's ref.\n * @defaultValue true\n */\n restoreFocus?: boolean | RefObject<HTMLElement | null>;\n}\n\n/**\n * Keeps keyboard focus inside a container while it is active: focus moves in\n * when the trap turns on, Tab and Shift+Tab wrap between the first and last\n * tab stops, and focus goes back where it came from when the trap turns off.\n *\n * Tab stops are what the browser's Tab visits, in document order: links,\n * form controls, frames, media with controls, a `<details>` summary, editable\n * regions, anything with `tabIndex={0}`, and the content of open shadow\n * roots. Hidden, disabled, inert and `tabIndex={-1}` elements are skipped,\n * and a radio group counts once. Give the container `tabIndex={-1}` so it can\n * hold focus itself when nothing inside can. The trap listens on the\n * container, so a trap nested inside another handles Tab first and the outer\n * one stands aside.\n *\n * The trap is about Tab. If a Tab it let through still takes focus out (a\n * browser can leave out a stop the page has, such as links when its settings\n * say to), it sends focus back to the other end. A pointer or a script moving\n * focus out is left alone, because pulling focus back from a click is modal\n * behaviour, and a modal also has to block the page behind it, which `Modal`\n * does. Content the container renders through a portal lives elsewhere in\n * the DOM, so it is outside the trap: render nested overlays inside the\n * container, or give them a trap of their own. To trap content a `Portal`\n * renders, pass a ref to the element inside the `Portal` as `containerRef`.\n *\n * The trap looks at `containerRef` again each time the component calling it\n * renders. A container that mounts after the trap turns on, such as a panel\n * waiting for a `Portal` target held in state, has it attach once that\n * component renders with the container in the DOM. When the container leaves\n * or is replaced, the trap lets go of it as it would turning off, handing\n * focus back, and attaches to the next one.\n * A child that mounts the container in a render of its own (from its own\n * state, or as a `Suspense` boundary resolves) goes unseen until the\n * component calling the hook renders again. The trap waits for hydration, so\n * that component renders again when the page hydrates, and portaled content,\n * which first appears then, is found.\n *\n * @function useFocusTrap\n * @param containerRef - Ref to the element focus stays inside.\n * @param options - When the trap is on, and where focus starts and ends.\n *\n * @example\n * const panelRef = useRef<HTMLDivElement>(null);\n * useFocusTrap(panelRef, { active: isOpen });\n * return isOpen ? (\n * <div ref={panelRef} role=\"dialog\" aria-label=\"Filters\" tabIndex={-1}>\n * …\n * </div>\n * ) : null;\n */\nexport function useFocusTrap(\n containerRef: RefObject<HTMLElement | null>,\n options: UseFocusTrapOptions = {}\n): void {\n const { active = true, initialFocusRef, restoreFocus = true } = options;\n // Portaled content has no server-rendered counterpart, so a portaled\n // container only exists from the commit after hydration.\n const hydrated = useIsHydrated();\n // The container the trap is attached to, or `null` while it has none.\n const heldRef = useRef<HTMLElement | null>(null);\n // Bumped to run the trap again when the container in the ref changes.\n const [refChanges, setRefChanges] = useState(0);\n\n useEffect(() => {\n heldRef.current = null;\n if (!active || !hydrated) return undefined;\n const container = containerRef.current;\n if (!container) return undefined;\n heldRef.current = container;\n const doc = container.ownerDocument;\n\n const opener = focusedElement(doc) as HTMLElement;\n\n // `initialFocusRef` counts only when focusing it puts focus inside. Focus\n // put outside would stay out, as Tab there never reaches the container's\n // listener, and focusing something that can't take focus (a heading\n // without `tabIndex`, a disabled control) leaves focus where it was.\n const initial = initialFocusRef?.current;\n const inTrap = initial && inside(container, initial) ? initial : null;\n inTrap?.focus();\n if (!inTrap || !inside(container, focusedElement(doc))) {\n (findTabStops(container)?.first ?? container).focus();\n }\n\n const releaseTab = trapTab(() => container, container);\n return () => {\n releaseTab();\n let target = restoreFocus ? opener : null;\n // `null` is an object too, and a caller without types can pass it.\n if (restoreFocus && typeof restoreFocus === 'object') {\n // Read now rather than when the trap turned on: a trigger that\n // re-mounted in between has a new node.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n target = restoreFocus.current;\n }\n // Hand focus back only while the trap still holds it: inside the\n // container, or dropped to <body> because the container left the page.\n const now = focusedElement(doc);\n if (target && (now === doc.body || inside(container, now))) {\n target.focus();\n }\n };\n }, [\n active,\n hydrated,\n containerRef,\n initialFocusRef,\n restoreFocus,\n refChanges,\n ]);\n\n // Nothing says when a ref is set, so after every render, a ref that no\n // longer matches what the trap holds (a container that mounted, left or was\n // replaced) runs it again. Effects run in order, so whenever the effect\n // above ran in this commit, it read the ref just before this does, and a\n // mismatch means the ref changed in a render it didn't run for. The render\n // a bump asks for runs it, so the two match and the trap settles. An empty\n // ref matches a trap holding nothing, so a container that never mounts\n // costs no render.\n // eslint-disable-next-line react-hooks/exhaustive-deps -- after every render on purpose\n useEffect(() => {\n if (active && hydrated && containerRef.current !== heldRef.current) {\n setRefChanges(n => n + 1);\n }\n });\n}\n"],"names":[],"mappings":";;;;;AAKA;;;;AAIG;AACH,SAAS,aAAa,CAAC,EAAW,EAAA;AAChC,IAAA,MAAM,QAAQ,GAAG,CAAC,IAAa,KAAoB;QACjD,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,EAAE,WAAW,EAAE;QACjE,IAAI,KAAK,KAAK,SAAS;AAAE,YAAA,OAAO,IAAI;AACpC,QAAA,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,gBAAgB,EAAE;AAClE,YAAA,OAAO,IAAI;QACb;QACA,OAAO,KAAK,KAAK,OAAO,GAAG,KAAK,GAAG,IAAI;AACzC,IAAA,CAAC;AACD,IAAA,IAAI,QAAQ,CAAC,EAAE,CAAC,KAAK,IAAI;AAAE,QAAA,OAAO,KAAK;AACvC,IAAA,KAAK,IAAI,IAAI,GAAG,EAAE,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE;AACjE,QAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC;QAC5B,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,CAAC,KAAK;IACnC;AACA,IAAA,OAAO,IAAI;AACb;AAEA;AACA,MAAM,gBAAgB,GAAG,CAAC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EAAE,GAAG,CAAC,CAAC,EAAE;gBAC1D,MAAM,CAAC,KAAK,EAAE;YAChB;AACF,QAAA,CAAC;AACH,IAAA,CAAC,EAAE;QACD,MAAM;QACN,QAAQ;QACR,YAAY;QACZ,eAAe;QACf,YAAY;QACZ,UAAU;AACX,KAAA,CAAC;;;;;;;;;;IAWF,SAAS,CAAC,MAAK;AACb,QAAA,IAAI,MAAM,IAAI,QAAQ,IAAI,YAAY,CAAC,OAAO,KAAK,OAAO,CAAC,OAAO,EAAE;YAClE,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC3B;AACF,IAAA,CAAC,CAAC;AACJ;;"}
|
|
1
|
+
{"version":3,"file":"useFocusTrap.js","sources":["../../../src/helpers/useFocusTrap.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\nimport type { RefObject } from 'react';\nimport { useIsHydrated } from './useIsHydrated';\nimport { getDeepestActiveElement } from './shadowDom';\n\n/**\n * Whether `el` is editable while its parent is not, which makes it an editing\n * host: the one tab stop an editable region gets. `contenteditable=\"false\"`\n * turns editing off, and a missing or unknown value inherits the parent's.\n */\nfunction isEditingHost(el: Element): boolean {\n const editable = (node: Element): boolean | null => {\n const value = node.getAttribute('contenteditable')?.toLowerCase();\n if (value === undefined) return null;\n if (value === '' || value === 'true' || value === 'plaintext-only') {\n return true;\n }\n return value === 'false' ? false : null;\n };\n if (editable(el) !== true) return false;\n for (let node = el.parentElement; node; node = node.parentElement) {\n const state = editable(node);\n if (state !== null) return !state;\n }\n return true;\n}\n\n/** Whether `el` is the summary of its `<details>`: the first one, not a stray. */\nconst isDetailsSummary = (el: Element): boolean =>\n el.parentElement?.localName === 'details' &&\n Array.from(el.parentElement.children).find(\n child => child.localName === 'summary'\n ) === el;\n\n/**\n * Whether the browser puts `el` in the tab order, before anything that hides\n * or disables it. The `tabIndex` property can't answer this on its own: it\n * can read `-1` for an editable region or an `<embed>` that Tab still visits,\n * and `0` for a `<video>` without controls that it doesn't. So a valid\n * `tabindex` attribute decides, and otherwise the element's kind does.\n * Internal like `focusTabStop`: `src/index.ts` names what it takes from here.\n */\nexport function isTabbableKind(el: Element): boolean {\n const tabindex = el.getAttribute('tabindex');\n if (tabindex !== null && /^\\s*[+-]?\\d/.test(tabindex)) {\n return (el as HTMLElement).tabIndex >= 0;\n }\n switch (el.localName) {\n case 'a':\n case 'area':\n return el.hasAttribute('href');\n case 'input':\n return (el as HTMLInputElement).type !== 'hidden';\n case 'button':\n case 'select':\n case 'textarea':\n case 'iframe':\n case 'embed':\n case 'object':\n return true;\n case 'audio':\n case 'video':\n return el.hasAttribute('controls');\n case 'summary':\n return isDetailsSummary(el);\n default:\n return isEditingHost(el);\n }\n}\n\n/**\n * The node's parent in the flattened tree, the one the browser renders and\n * tabs through: the slot it is assigned to, else its parent, else the host of\n * the shadow root it tops, and nothing above the document. A closed shadow\n * root hides its slots (`assignedSlot` reads `null` under one), so a child of\n * its host goes straight to the host, whether a slot takes it or not.\n */\nconst flatParent = (node: Node): Node | null =>\n (node as Element).assignedSlot ??\n node.parentElement ??\n (node.parentNode as ShadowRoot | null)?.host ??\n null;\n\n/**\n * The element's children in the flattened tree, in the order they render: a\n * host's shadow root content, a slot's assigned elements (or its fallback\n * content when nothing is assigned), anything else's own children. A host\n * whose shadow root is closed has no root to read, so its own children stand\n * in, including any that no slot takes and that aren't rendered.\n */\nfunction flatChildren(el: Element): Element[] {\n if (el.shadowRoot) return Array.from(el.shadowRoot.children);\n if (el.localName === 'slot') {\n const assigned = (el as HTMLSlotElement).assignedNodes();\n if (assigned.length > 0) {\n return assigned.filter(\n (node): node is Element => node.nodeType === Node.ELEMENT_NODE\n );\n }\n }\n return Array.from(el.children);\n}\n\nconst isShown = (el: Element): boolean =>\n !el.hasAttribute('inert') && getComputedStyle(el).display !== 'none';\n\nconst isVisible = (el: Element): boolean => {\n const { visibility } = getComputedStyle(el);\n return visibility !== 'hidden' && visibility !== 'collapse';\n};\n\n/**\n * Whether nothing from `el` up to `top` hides it: `inert`, `display: none`\n * (not inherited, so each element is checked) or a closed `<details>` it\n * isn't the summary of. `top` itself isn't checked, and `null` walks to the\n * top of the page.\n */\nfunction isShownUpTo(el: Element, top: Node | null): boolean {\n let below: Element | null = null;\n for (\n let node: Element | null = el;\n node && node !== top;\n node = flatParent(node) as Element | null\n ) {\n if (!isShown(node)) return false;\n if (\n below &&\n node.localName === 'details' &&\n !node.hasAttribute('open') &&\n !isDetailsSummary(below)\n ) {\n return false;\n }\n below = node;\n }\n return true;\n}\n\n/**\n * The images that use the image map `area` belongs to. An image names its\n * map with `usemap=\"#…\"`, matching the map's `name` or `id`.\n */\nfunction imagesUsingMapOf(area: Element): Element[] {\n const map = area.closest('map');\n if (!map) return [];\n const names = [map.getAttribute('name'), map.id].filter(name => name);\n return Array.from(\n (area.getRootNode() as ParentNode).querySelectorAll('img[usemap]')\n ).filter(img => {\n const ref = img.getAttribute('usemap') as string;\n return ref.startsWith('#') && names.includes(ref.slice(1));\n });\n}\n\n/**\n * Whether an image map area is shown. An area has no box of its own: the\n * HTML rendering rules give it `display: none`, though a browser may not\n * report that. So it counts where an image using its map is shown, as long\n * as nothing makes it inert.\n */\nfunction isAreaShown(area: Element, container: Element): boolean {\n for (\n let node: Element | null = area;\n node && node !== container;\n node = flatParent(node) as Element | null\n ) {\n if (node.hasAttribute('inert')) return false;\n }\n return imagesUsingMapOf(area).some(\n img => isShownUpTo(img, null) && isVisible(img)\n );\n}\n\n/**\n * Whether Tab can land on `el`, one of the kinds it visits. A disabled control\n * (including one inside a disabled `<fieldset>`), an inert subtree and\n * anything not rendered are skipped. `visibility` is inherited, so the\n * element's own computed value covers its ancestors.\n */\nfunction isRenderedAndEnabled(el: Element, container: Element): boolean {\n if (el.matches(':disabled')) return false;\n if (el.localName === 'area') return isAreaShown(el, container);\n return isShownUpTo(el, container) && isVisible(el);\n}\n\n/** A radio button with a name, which shares one tab stop with its group. */\nconst isGroupedRadio = (el: Element): el is HTMLInputElement =>\n el.localName === 'input' &&\n (el as HTMLInputElement).type === 'radio' &&\n (el as HTMLInputElement).name !== '';\n\n/** Whether two radio buttons are in one group: same name, form owner and tree. */\nconst sameGroup = (a: HTMLInputElement, b: Element): b is HTMLInputElement =>\n isGroupedRadio(b) &&\n b.name === a.name &&\n b.form === a.form &&\n b.getRootNode() === a.getRootNode();\n\n/**\n * The checked button of `radio`'s group. The group isn't bounded by the trap,\n * so this looks through the radio's whole tree.\n */\nconst checkedInGroup = (radio: HTMLInputElement): Element | undefined =>\n Array.from(\n (radio.getRootNode() as ParentNode).querySelectorAll('input:checked')\n ).find(el => sameGroup(radio, el));\n\n/** The flattened-tree ancestors of `node` below the container, outermost first, then `node`. */\nfunction flatChain(node: Node, container: Node): Node[] {\n const chain: Node[] = [];\n for (let n: Node | null = node; n && n !== container; n = flatParent(n)) {\n chain.unshift(n);\n }\n return chain;\n}\n\n/**\n * Whether `node` is inside the container in the flattened tree: in it, in a\n * shadow root it holds, or slotted into it. A child of a closed-root host\n * counts as inside wherever the host is, as its slot can't be seen.\n */\nfunction inside(container: Node, node: Node): boolean {\n for (let n: Node | null = node; n; n = flatParent(n)) {\n if (n === container) return true;\n }\n return false;\n}\n\n/**\n * `true` when Tab reaches `b` after `a`, which is their order in the\n * flattened tree: a shadow host comes before its shadow root's content, and\n * slotted content comes where its slot is. A closed root's slots can't be\n * seen, so its host's children keep their place in the light DOM. Two\n * flattened-tree siblings are always in one DOM tree, so their document\n * position decides between them.\n */\nfunction follows(container: Element, a: Node, b: Node): boolean {\n const chainA = flatChain(a, container);\n const chainB = flatChain(b, container);\n for (let i = 0; i < Math.max(chainA.length, chainB.length); i++) {\n const [x, y] = [chainA[i], chainB[i]];\n if (x === y) continue;\n if (!x) return true;\n if (!y) return false;\n return Boolean(\n x.compareDocumentPosition(y) & Node.DOCUMENT_POSITION_FOLLOWING\n );\n }\n return false;\n}\n\n/**\n * Every element of a tabbable kind under `el` in the flattened tree, depth\n * first, which is the order Tab visits them. Under a host whose shadow root\n * is closed, that takes in the host's own children instead, rendered or not.\n */\nfunction collectCandidates(\n el: Element,\n out: HTMLElement[] = []\n): HTMLElement[] {\n for (const child of flatChildren(el)) {\n if (isTabbableKind(child)) out.push(child as HTMLElement);\n collectCandidates(child, out);\n }\n return out;\n}\n\ninterface TabStops {\n first: HTMLElement;\n last: HTMLElement;\n /** The stop that stands for `node`: its group's stop for a radio button. */\n stopFor(node: Element): Element;\n /** The stops from one end inward, the last first when `fromLast`. */\n from(fromLast: boolean): Generator<HTMLElement>;\n}\n\n/**\n * The first and last tab stops inside `container`, or `null` when there are\n * none. Only the ends matter for wrapping, so the style checks run from each\n * end until they find a stop rather than over every candidate.\n *\n * A radio group is one stop, the way the browser treats it: its checked\n * button, or its first when none is checked. Counting every button would make\n * the group's last one an end, and Tab from the checked one would leave. The\n * group goes by name, form owner and tree, not by the trap, so a checked\n * button outside the container that Tab can land on leaves the group no stop\n * inside. One that Tab can't land on leaves the group as if none were checked.\n */\nfunction findTabStops(container: HTMLElement): TabStops | null {\n const candidates = collectCandidates(container);\n const checked = new Map<Element, boolean>();\n const usable = (el: Element): boolean => {\n let ok = checked.get(el);\n if (ok === undefined) {\n ok = isRenderedAndEnabled(el, container);\n checked.set(el, ok);\n }\n return ok;\n };\n // Resolved once per group, filed under each of its buttons, since finding\n // the checked one scans the radio's whole tree.\n const groupStops = new Map<Element, HTMLElement | undefined>();\n const groupStop = (radio: HTMLInputElement): HTMLElement | undefined => {\n if (groupStops.has(radio)) return groupStops.get(radio);\n const group = candidates.filter(el => sameGroup(radio, el));\n const on = checkedInGroup(radio);\n const stop =\n on && isTabbableKind(on) && usable(on)\n ? group.find(el => el === on)\n : group.find(usable);\n for (const el of [radio, ...group]) groupStops.set(el, stop);\n return stop;\n };\n const isStop = (el: HTMLElement): boolean =>\n usable(el) && (!isGroupedRadio(el) || groupStop(el) === el);\n // Checked only as they're reached, and the checks are kept, so finding\n // both ends costs what it did when only the ends were looked for.\n function* from(fromLast: boolean): Generator<HTMLElement> {\n for (let i = 0; i < candidates.length; i++) {\n const el = candidates[fromLast ? candidates.length - 1 - i : i];\n if (isStop(el)) yield el;\n }\n }\n\n const first = from(false).next().value;\n if (!first) return null;\n return {\n first,\n last: from(true).next().value as HTMLElement,\n stopFor: node => (isGroupedRadio(node) && groupStop(node)) || node,\n from,\n };\n}\n\n/**\n * The element that has focus in the container's own document (an iframe's,\n * when it renders into one), inside open shadow roots too. Focus inside a\n * closed one reads as its host, which the comparisons above place like any\n * other element. Browsers fall back to <body> when nothing has\n * focus. jsdom, where consumers run their tests, reports nothing once focus\n * was inside a shadow root that was removed, so this falls back for it.\n */\nconst focusedElement = (doc: Document): Element =>\n getDeepestActiveElement(doc) ?? doc.body;\n\n/**\n * Moves focus to the first tab stop inside `container`, or the last when\n * `fromLast`, and to the container when there is none. Every move a trap\n * makes goes through here: into the container as it opens, to the other end\n * on a wrap, and back in after a Tab the browser carried out.\n *\n * A stop that doesn't take focus is passed over for the next one in. An\n * `<object>` or `<embed>` with nothing to show is one: it counts as a stop by\n * its kind, but browsers refuse to focus it, and which ones they refuse\n * depends on the browser and on what has loaded, so only trying tells. A\n * stop took focus when focus moved, wherever it went (a stop can hand focus\n * on), or when focus was on it already. `src/index.ts` names its exports from\n * this module, so this one stays internal.\n */\nexport function focusTabStop(container: HTMLElement, fromLast = false): void {\n const doc = container.ownerDocument;\n for (const stop of findTabStops(container)?.from(fromLast) ?? []) {\n const before = focusedElement(doc);\n stop.focus();\n const now = focusedElement(doc);\n if (now !== before || inside(stop, now)) return;\n }\n container.focus();\n}\n\n/**\n * Handles a Tab for a trap on `container`. When the browser has no tab stop\n * left in that direction inside the container, focus goes to the stop at the\n * other end and the key is marked used, and with no stops at all the\n * container takes focus. Focus outside the container goes in at that end\n * too. Returns whether it moved focus; otherwise the browser does.\n */\nfunction wrapTab(e: KeyboardEvent, container: HTMLElement): boolean {\n const stops = findTabStops(container);\n if (!stops) {\n e.preventDefault();\n container.focus();\n return true;\n }\n const focused = focusedElement(container.ownerDocument);\n const current = stops.stopFor(focused);\n // Wrap whenever the browser has no stop left in that direction inside the\n // container. Comparing positions rather than testing `=== first` also\n // covers focus resting on the container or on an element outside the tab\n // order, which the browser would otherwise walk straight out of.\n if (\n !inside(container, focused) ||\n (e.shiftKey\n ? !follows(container, stops.first, current)\n : !follows(container, current, stops.last))\n ) {\n e.preventDefault();\n focusTabStop(container, e.shiftKey);\n return true;\n }\n return false;\n}\n\n/**\n * Holds Tab inside the element `container` returns until the returned\n * function is called. Tab and Shift+Tab heard on `keyTarget` wrap at the\n * ends, unless something already marked the key used, and if a Tab the trap\n * let through still takes focus out, it sends focus back to the other end.\n *\n * `container` is read each time a key or a focus change arrives, so an\n * overlay whose nodes are remounted while it's open, as moving to another\n * portal target does, stays trapped without attaching again. `holds` is asked\n * on every Tab, and the trap leaves the key alone while it says no. Internal\n * like `focusTabStop`. It's for an overlay that holds Tab from a listener of\n * its own on `window` and asks the overlay stack first, so it stands aside\n * while another overlay is open over it, which a trap listening on the\n * container can't do.\n */\nexport function trapTab(\n container: () => HTMLElement | null,\n keyTarget: HTMLElement | Window,\n holds: () => boolean = () => true\n): () => void {\n // The document focus moves in: the window's own, or the element's.\n const doc =\n 'document' in keyTarget ? keyTarget.document : keyTarget.ownerDocument;\n // A window and an element type their listeners differently, so the trap\n // listens through the base type both share.\n const keys: EventTarget = keyTarget;\n // The end focus goes back to if a Tab the trap let the browser handle\n // takes it out (the last for Shift+Tab), held until that Tab has finished\n // moving focus, and `null` otherwise.\n let wrapFromLast: boolean | null = null;\n let wrapTimer: ReturnType<typeof setTimeout> | undefined;\n\n // `keyTarget` is any target, so the listener takes the base event type.\n const handleKeyDown = (event: Event) => {\n const e = event as KeyboardEvent;\n const box = container();\n // A trap nested inside this one has already wrapped focus.\n if (e.key !== 'Tab' || e.defaultPrevented || !box || !holds()) return;\n if (wrapTab(e, box)) return;\n wrapFromLast = e.shiftKey;\n clearTimeout(wrapTimer);\n wrapTimer = setTimeout(() => {\n wrapFromLast = null;\n });\n };\n\n // The browser moves focus as soon as the keydown is over, so focus that\n // lands outside while `wrapFromLast` is set got there by that Tab.\n const handleFocusIn = (e: FocusEvent) => {\n const box = container();\n if (wrapFromLast === null || !box) return;\n if (inside(box, e.composedPath()[0] as Node)) return;\n const fromLast = wrapFromLast;\n wrapFromLast = null;\n focusTabStop(box, fromLast);\n };\n\n keys.addEventListener('keydown', handleKeyDown);\n doc.addEventListener('focusin', handleFocusIn, true);\n return () => {\n keys.removeEventListener('keydown', handleKeyDown);\n doc.removeEventListener('focusin', handleFocusIn, true);\n clearTimeout(wrapTimer);\n };\n}\n\n/**\n * Options for `useFocusTrap`.\n */\nexport interface UseFocusTrapOptions {\n /**\n * Whether the trap is on. Turning it on moves focus into the container;\n * turning it off (or unmounting) releases Tab and restores focus.\n * @defaultValue true\n */\n active?: boolean;\n /**\n * The element inside the container to focus when the trap turns on. It has\n * to be one that can take focus, so a heading needs `tabIndex={-1}`. When\n * focusing it doesn't put focus inside the container (the ref is empty, or\n * its element is outside, disabled, hidden or can't take focus), focus goes\n * to the first tab stop inside the container that takes focus, and to the\n * container itself when none does.\n */\n initialFocusRef?: RefObject<HTMLElement | null>;\n /**\n * Where focus goes when the trap turns off. `true` returns it to the element\n * that had focus when the trap turned on; a ref sends it to that element\n * instead; `false` leaves it alone. Focus is only moved while the trap still\n * holds it, so a click that already put focus somewhere else outside the\n * container keeps it there.\n *\n * `true` reads focus after the container's content has mounted, so content\n * that focuses itself as it mounts (an `autoFocus` input) hides the element\n * that opened it. And some browsers don't focus a button when it is\n * clicked. For a panel opened from a button, pass the button's ref.\n * @defaultValue true\n */\n restoreFocus?: boolean | RefObject<HTMLElement | null>;\n}\n\n/**\n * Keeps keyboard focus inside a container while it is active: focus moves in\n * when the trap turns on, Tab and Shift+Tab wrap between the first and last\n * tab stops, and focus goes back where it came from when the trap turns off.\n *\n * Tab stops are what the browser's Tab visits, in document order: links,\n * form controls, frames, media with controls, a `<details>` summary, editable\n * regions, anything with `tabIndex={0}`, and the content of open shadow\n * roots. Hidden, disabled, inert and `tabIndex={-1}` elements are skipped,\n * and a radio group counts once. Give the container `tabIndex={-1}` so it can\n * hold focus itself when nothing inside can. The trap listens on the\n * container, so a trap nested inside another handles Tab first and the outer\n * one stands aside.\n *\n * The trap is about Tab. If a Tab it let through still takes focus out (a\n * browser can leave out a stop the page has, such as links when its settings\n * say to), it sends focus back to the other end. A pointer or a script moving\n * focus out is left alone, because pulling focus back from a click is modal\n * behaviour, and a modal also has to block the page behind it, which `Modal`\n * does. Content the container renders through a portal lives elsewhere in\n * the DOM, so it is outside the trap: render nested overlays inside the\n * container, or give them a trap of their own. To trap content a `Portal`\n * renders, pass a ref to the element inside the `Portal` as `containerRef`.\n *\n * The trap looks at `containerRef` again each time the component calling it\n * renders. A container that mounts after the trap turns on, such as a panel\n * waiting for a `Portal` target held in state, has it attach once that\n * component renders with the container in the DOM. When the container leaves\n * or is replaced, the trap lets go of it as it would turning off, handing\n * focus back, and attaches to the next one.\n * A child that mounts the container in a render of its own (from its own\n * state, or as a `Suspense` boundary resolves) goes unseen until the\n * component calling the hook renders again. The trap waits for hydration, so\n * that component renders again when the page hydrates, and portaled content,\n * which first appears then, is found.\n *\n * @function useFocusTrap\n * @param containerRef - Ref to the element focus stays inside.\n * @param options - When the trap is on, and where focus starts and ends.\n *\n * @example\n * const panelRef = useRef<HTMLDivElement>(null);\n * useFocusTrap(panelRef, { active: isOpen });\n * return isOpen ? (\n * <div ref={panelRef} role=\"dialog\" aria-label=\"Filters\" tabIndex={-1}>\n * …\n * </div>\n * ) : null;\n */\nexport function useFocusTrap(\n containerRef: RefObject<HTMLElement | null>,\n options: UseFocusTrapOptions = {}\n): void {\n const { active = true, initialFocusRef, restoreFocus = true } = options;\n // Portaled content has no server-rendered counterpart, so a portaled\n // container only exists from the commit after hydration.\n const hydrated = useIsHydrated();\n // The container the trap is attached to, or `null` while it has none.\n const heldRef = useRef<HTMLElement | null>(null);\n // Bumped to run the trap again when the container in the ref changes.\n const [refChanges, setRefChanges] = useState(0);\n\n useEffect(() => {\n heldRef.current = null;\n if (!active || !hydrated) return undefined;\n const container = containerRef.current;\n if (!container) return undefined;\n heldRef.current = container;\n const doc = container.ownerDocument;\n\n const opener = focusedElement(doc) as HTMLElement;\n\n // `initialFocusRef` counts only when focusing it puts focus inside. Focus\n // put outside would stay out, as Tab there never reaches the container's\n // listener, and focusing something that can't take focus (a heading\n // without `tabIndex`, a disabled control) leaves focus where it was.\n const initial = initialFocusRef?.current;\n const inTrap = initial && inside(container, initial) ? initial : null;\n inTrap?.focus();\n if (!inTrap || !inside(container, focusedElement(doc))) {\n focusTabStop(container);\n }\n\n const releaseTab = trapTab(() => container, container);\n return () => {\n releaseTab();\n let target = restoreFocus ? opener : null;\n // `null` is an object too, and a caller without types can pass it.\n if (restoreFocus && typeof restoreFocus === 'object') {\n // Read now rather than when the trap turned on: a trigger that\n // re-mounted in between has a new node.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n target = restoreFocus.current;\n }\n // Hand focus back only while the trap still holds it: inside the\n // container, or dropped to <body> because the container left the page.\n const now = focusedElement(doc);\n if (target && (now === doc.body || inside(container, now))) {\n target.focus();\n }\n };\n }, [\n active,\n hydrated,\n containerRef,\n initialFocusRef,\n restoreFocus,\n refChanges,\n ]);\n\n // Nothing says when a ref is set, so after every render, a ref that no\n // longer matches what the trap holds (a container that mounted, left or was\n // replaced) runs it again. Effects run in order, so whenever the effect\n // above ran in this commit, it read the ref just before this does, and a\n // mismatch means the ref changed in a render it didn't run for. The render\n // a bump asks for runs it, so the two match and the trap settles. An empty\n // ref matches a trap holding nothing, so a container that never mounts\n // costs no render.\n // eslint-disable-next-line react-hooks/exhaustive-deps -- after every render on purpose\n useEffect(() => {\n if (active && hydrated && containerRef.current !== heldRef.current) {\n setRefChanges(n => n + 1);\n }\n });\n}\n"],"names":[],"mappings":";;;;;AAKA;;;;AAIG;AACH,SAAS,aAAa,CAAC,EAAW,EAAA;AAChC,IAAA,MAAM,QAAQ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