@funstack/ui 0.1.0-alpha.13 → 0.1.0-alpha.14
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/combobox/combobox-popup.d.mts +4 -2
- package/dist/combobox/combobox-popup.d.mts.map +1 -1
- package/dist/combobox/combobox-popup.mjs +19 -3
- package/dist/combobox/combobox-popup.mjs.map +1 -1
- package/dist/combobox/combobox-trigger.d.mts +13 -10
- package/dist/combobox/combobox-trigger.d.mts.map +1 -1
- package/dist/combobox/combobox-trigger.mjs +19 -14
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/dialog/dialog-popup.mjs +3 -2
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/internal/anchor-position.mjs.map +1 -1
- package/dist/internal/invoker-press.mjs +46 -0
- package/dist/internal/invoker-press.mjs.map +1 -0
- package/dist/internal/platform-attributes.d.mts +2 -1
- package/dist/internal/platform-attributes.d.mts.map +1 -1
- package/dist/internal/render-element.mjs.map +1 -1
- package/dist/internal/trigger-ref.mjs +2 -2
- package/dist/internal/trigger-ref.mjs.map +1 -1
- package/dist/internal/use-overlay-root.mjs +2 -1
- package/dist/internal/use-overlay-root.mjs.map +1 -1
- package/dist/internal/use-popover-popup.mjs +87 -11
- package/dist/internal/use-popover-popup.mjs.map +1 -1
- package/dist/internal/use-popover-trigger.mjs +14 -11
- package/dist/internal/use-popover-trigger.mjs.map +1 -1
- package/dist/internal/use-resolved-placement.mjs +1 -1
- package/dist/internal/use-resolved-placement.mjs.map +1 -1
- package/dist/menu/menu-context.mjs.map +1 -1
- package/dist/menu/menu-popup.d.mts +3 -1
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +14 -3
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-submenu-trigger.d.mts +7 -5
- package/dist/menu/menu-submenu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-submenu-trigger.mjs +6 -4
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +8 -6
- package/dist/menu/menu-trigger.d.mts.map +1 -1
- package/dist/menu/menu-trigger.mjs +6 -4
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/popover/index.d.mts +1 -1
- package/dist/popover/index.mjs +1 -1
- package/dist/popover/index.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts +3 -1
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +3 -1
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-popup.d.mts +1 -1
- package/dist/popover/popover-popup.mjs +1 -1
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.d.mts +1 -1
- package/dist/popover/popover-root.mjs +1 -1
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/popover/popover-trigger.d.mts +11 -10
- package/dist/popover/popover-trigger.d.mts.map +1 -1
- package/dist/popover/popover-trigger.mjs +10 -9
- package/dist/popover/popover-trigger.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -9,7 +9,7 @@ const toDirection = (value) => value === "rtl" ? "rtl" : "ltr";
|
|
|
9
9
|
/**
|
|
10
10
|
* Where the browser actually placed an anchored popup (design/conventions.md 13.2): the
|
|
11
11
|
* `position-try-fallbacks` option it applied, read from the computed `position-area` while the
|
|
12
|
-
* popup is shown. Observation only; runs whatever opened the popup (`interestfor` and
|
|
12
|
+
* popup is shown. Observation only; runs whatever opened the popup (`interestfor`, `popovertarget` and
|
|
13
13
|
* `commandfor` included). Read on a `ResizeObserver` (hidden to shown is a resize, delivered
|
|
14
14
|
* before paint), `toggle`, and while shown document `scroll` and window `resize` plus the next
|
|
15
15
|
* two frames. Written urgently (`flushSync`), and only when the rendered pair changes: an open
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-resolved-placement.mjs","names":[],"sources":["../../src/internal/use-resolved-placement.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, RefCallback } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { parsePositionArea, POSITION_TRY_FALLBACKS, positionArea } from \"./anchor-position.js\";\nimport type {\n AnchorAlign,\n AnchorSide,\n Direction,\n PhysicalSide,\n ResolvedPlacement,\n} from \"./anchor-position.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { resolveStateValue } from \"./render-element.js\";\nimport type { DataAttributes } from \"./render-element.js\";\nimport type { StateValue } from \"./types.js\";\n\nexport interface PlacementRequest<Side extends AnchorSide> {\n /** The requested side; `null` when the stylesheet owns placement (the hook is idle). */\n readonly side: Side | null;\n readonly align: AnchorAlign;\n}\n\nexport interface PlacementResult<Side extends AnchorSide> {\n /** The resolved physical side while the popup is shown, else the requested side. */\n readonly side: Side | PhysicalSide | null;\n /** The resolved alignment while shown, else the requested one. */\n readonly align: AnchorAlign;\n /** Merge into the popup element's ref. Stable. */\n readonly ref: RefCallback<HTMLElement>;\n}\n\nconst toDirection = (value: string): Direction => (value === \"rtl\" ? \"rtl\" : \"ltr\");\n\n/**\n * Where the browser actually placed an anchored popup (design/conventions.md 13.2): the\n * `position-try-fallbacks` option it applied, read from the computed `position-area` while the\n * popup is shown. Observation only; runs whatever opened the popup (`interestfor` and\n * `commandfor` included). Read on a `ResizeObserver` (hidden to shown is a resize, delivered\n * before paint), `toggle`, and while shown document `scroll` and window `resize` plus the next\n * two frames. Written urgently (`flushSync`), and only when the rendered pair changes: an open\n * where it was asked costs no render. Hidden again, it resets once the popup no longer renders\n * (an exit animation keeps the resolved side). Idle with `side: null`.\n */\nexport function useResolvedPlacement<Side extends AnchorSide>(\n request: PlacementRequest<Side>,\n): PlacementResult<Side> {\n const { side, align } = request;\n const [resolved, setResolved] = useState<ResolvedPlacement | null>(null);\n // What the state holds (or is about to hold), so an unchanged read schedules nothing.\n const written = useRef<ResolvedPlacement | null>(null);\n // The request the element is rendered with (kept by the layout effect below).\n const requested = useRef<PlacementRequest<Side>>(request);\n // The mounted element's read, for the layout effect below.\n const sync = useRef<((urgent: boolean) => void) | null>(null);\n\n const ref = useCallback((element: HTMLElement | null) => {\n if (element === null) return;\n const doc = element.ownerDocument;\n const win = doc.defaultView ?? window;\n\n const write = (value: ResolvedPlacement | null, urgent: boolean) => {\n // Where it was asked to be: the requested values say so already, no state needed.\n const next =\n value !== null &&\n value.side === requested.current.side &&\n value.align === requested.current.align\n ? null\n : value;\n const previous = written.current;\n if (\n previous === next ||\n (previous !== null &&\n next !== null &&\n previous.side === next.side &&\n previous.align === next.align)\n ) {\n return;\n }\n written.current = next;\n if (urgent) flushSync(() => setResolved(next));\n else setResolved(next);\n };\n\n let listening = false;\n const listen = (on: boolean) => {\n if (on === listening) return;\n listening = on;\n if (on) {\n doc.addEventListener(\"scroll\", onMove, { capture: true, passive: true });\n win.addEventListener(\"resize\", onMove);\n } else {\n doc.removeEventListener(\"scroll\", onMove, { capture: true });\n win.removeEventListener(\"resize\", onMove);\n cancelFrames();\n }\n };\n\n // Both engines (Chromium 156, Firefox 157) apply the scroll-dependent anchoring state, the\n // option and the scroll-compensated geometry alike, in the layout of the frame after the\n // `scroll` event: a read in the handler, or in a rAF registered from it (which runs before\n // that layout), sees the old option even after a forced layout. The timing is unspecified\n // (css-anchor-position-1 §3.3 issue), so read again in the next two frames; a scroll that\n // arrives while that is pending restarts it at the end, so the last scroll is always followed.\n // Separately, Chromium 156 keeps an overflowing option for a top-layer popover once the first\n // frames after the show have passed (a bug, §6.5; upstream item #92): then no frame reads a\n // new option, and `data-side` correctly keeps reporting the applied one. Do not drop the\n // frame reads \"because Chromium does not re-choose\": when it does, it lags like Firefox.\n let frame = 0;\n let again = false;\n const cancelFrames = () => {\n if (frame !== 0) win.cancelAnimationFrame(frame);\n frame = 0;\n again = false;\n };\n const readLater = () => {\n if (frame !== 0) {\n again = true;\n return;\n }\n frame = win.requestAnimationFrame(() => {\n read(true);\n // The popup was found hidden (or `side` turned null): `listen(false)` ended the pair.\n if (!listening) return;\n frame = win.requestAnimationFrame(() => {\n frame = 0;\n read(true);\n if (again && listening) {\n again = false;\n readLater();\n }\n });\n });\n };\n\n const read = (urgent: boolean) => {\n if (requested.current.side === null) {\n listen(false);\n write(null, urgent);\n return;\n }\n if (element.isConnected && isPopoverOpen(element)) {\n listen(true);\n const style = getComputedStyle(element);\n const placement = parsePositionArea(\n style.positionArea,\n toDirection(style.direction),\n () => toDirection(getComputedStyle(doc.documentElement).direction),\n style.writingMode || \"horizontal-tb\",\n );\n write(placement, urgent);\n return;\n }\n listen(false);\n // Hidden, but still rendered while an exit animation runs: keep the resolved side to the\n // end of it. The ResizeObserver sees the box go and resets then.\n // Nothing written, nothing to reset: skip the forced layout (every mount and request change\n // of a hidden popup comes through here).\n if (\n written.current !== null &&\n (!element.isConnected || element.getClientRects().length === 0)\n ) {\n write(null, urgent);\n }\n };\n\n function onEvent() {\n read(true);\n }\n function onMove() {\n // In every Chromium 156 / Firefox 157 probe this read still saw the old option (see the\n // frame reads above); kept as cover for WebKit, which was not probed, at the cost of one\n // style read per scroll event.\n read(true);\n if (listening) readLater();\n }\n\n sync.current = read;\n const observer = typeof ResizeObserver === \"function\" ? new ResizeObserver(onEvent) : null;\n observer?.observe(element);\n element.addEventListener(\"toggle\", onEvent);\n return () => {\n observer?.disconnect();\n element.removeEventListener(\"toggle\", onEvent);\n listen(false);\n if (sync.current === read) sync.current = null;\n };\n }, []);\n\n // A changed request while shown places the popup differently: read again (a layout effect, so\n // the corrected attribute is in the same frame). Also how `side={null}` turns the hook off.\n useLayoutEffect(() => {\n requested.current = { side, align };\n sync.current?.(false);\n }, [side, align]);\n\n if (side === null) return { side: null, align, ref };\n return resolved === null ? { side, align, ref } : { ...resolved, ref };\n}\n\nexport interface AnchoredPlacementRequest<Side extends AnchorSide> extends PlacementRequest<Side> {\n /** `position-try-fallbacks`. Default: flip on both axes. */\n readonly fallbacks?: string;\n}\n\nexport interface AnchoredPlacement<Side extends AnchorSide> extends PlacementResult<Side> {\n /** `data-side` / `data-align` (resolved); no keys when the side is `null` (not owned then). */\n readonly dataAttributes: DataAttributes;\n /**\n * The popup's `style`: the requested inline placement (the browser keeps choosing from it)\n * under the consumer's style, so the consumer wins. The consumer's style alone for `side: null`.\n */\n readonly style: <State>(\n consumer: StateValue<CSSProperties | undefined, State>,\n ) => StateValue<CSSProperties | undefined, State>;\n}\n\n/**\n * An anchored popup's placement (Popover, Tooltip and Menu Popup): `useResolvedPlacement` plus\n * the data attributes and the inline `position-area` / `position-try-fallbacks` it renders.\n */\nexport function useAnchoredPlacement<Side extends AnchorSide>(\n request: AnchoredPlacementRequest<Side>,\n): AnchoredPlacement<Side> {\n const {\n side: requestedSide,\n align: requestedAlign,\n fallbacks = POSITION_TRY_FALLBACKS,\n } = request;\n const placement = useResolvedPlacement({ side: requestedSide, align: requestedAlign });\n const { side, align } = placement;\n const dataAttributes: DataAttributes =\n side !== null ? { \"data-side\": side, \"data-align\": align } : {};\n const style = <State>(\n consumer: StateValue<CSSProperties | undefined, State>,\n ): StateValue<CSSProperties | undefined, State> =>\n requestedSide === null\n ? consumer\n : (s: State) => ({\n positionArea: positionArea(requestedSide, requestedAlign),\n positionTryFallbacks: fallbacks,\n ...resolveStateValue(consumer, s),\n });\n return { ...placement, dataAttributes, style };\n}\n"],"mappings":";;;;;;;AAgCA,MAAM,eAAe,UAA8B,UAAU,QAAQ,QAAQ;;;;;;;;;;;AAY7E,SAAgB,qBACd,SACuB;CACvB,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,CAAC,UAAU,eAAe,SAAmC,IAAI;CAEvE,MAAM,UAAU,OAAiC,IAAI;CAErD,MAAM,YAAY,OAA+B,OAAO;CAExD,MAAM,OAAO,OAA2C,IAAI;CAE5D,MAAM,MAAM,aAAa,YAAgC;EACvD,IAAI,YAAY,MAAM;EACtB,MAAM,MAAM,QAAQ;EACpB,MAAM,MAAM,IAAI,eAAe;EAE/B,MAAM,SAAS,OAAiC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SACJ,aAEA,kBAAkB,OACd,YACC,OAAc;EACb,cAAc,aAAa,eAAe,cAAc;EACxD,sBAAsB;EACtB,GAAG,kBAAkB,UAAU,CAAC;CAClC;CACN,OAAO;EAAE,GAAG;EAAW;EAAgB;CAAM;AAC/C"}
|
|
1
|
+
{"version":3,"file":"use-resolved-placement.mjs","names":[],"sources":["../../src/internal/use-resolved-placement.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, RefCallback } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { parsePositionArea, POSITION_TRY_FALLBACKS, positionArea } from \"./anchor-position.js\";\nimport type {\n AnchorAlign,\n AnchorSide,\n Direction,\n PhysicalSide,\n ResolvedPlacement,\n} from \"./anchor-position.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { resolveStateValue } from \"./render-element.js\";\nimport type { DataAttributes } from \"./render-element.js\";\nimport type { StateValue } from \"./types.js\";\n\nexport interface PlacementRequest<Side extends AnchorSide> {\n /** The requested side; `null` when the stylesheet owns placement (the hook is idle). */\n readonly side: Side | null;\n readonly align: AnchorAlign;\n}\n\nexport interface PlacementResult<Side extends AnchorSide> {\n /** The resolved physical side while the popup is shown, else the requested side. */\n readonly side: Side | PhysicalSide | null;\n /** The resolved alignment while shown, else the requested one. */\n readonly align: AnchorAlign;\n /** Merge into the popup element's ref. Stable. */\n readonly ref: RefCallback<HTMLElement>;\n}\n\nconst toDirection = (value: string): Direction => (value === \"rtl\" ? \"rtl\" : \"ltr\");\n\n/**\n * Where the browser actually placed an anchored popup (design/conventions.md 13.2): the\n * `position-try-fallbacks` option it applied, read from the computed `position-area` while the\n * popup is shown. Observation only; runs whatever opened the popup (`interestfor`, `popovertarget` and\n * `commandfor` included). Read on a `ResizeObserver` (hidden to shown is a resize, delivered\n * before paint), `toggle`, and while shown document `scroll` and window `resize` plus the next\n * two frames. Written urgently (`flushSync`), and only when the rendered pair changes: an open\n * where it was asked costs no render. Hidden again, it resets once the popup no longer renders\n * (an exit animation keeps the resolved side). Idle with `side: null`.\n */\nexport function useResolvedPlacement<Side extends AnchorSide>(\n request: PlacementRequest<Side>,\n): PlacementResult<Side> {\n const { side, align } = request;\n const [resolved, setResolved] = useState<ResolvedPlacement | null>(null);\n // What the state holds (or is about to hold), so an unchanged read schedules nothing.\n const written = useRef<ResolvedPlacement | null>(null);\n // The request the element is rendered with (kept by the layout effect below).\n const requested = useRef<PlacementRequest<Side>>(request);\n // The mounted element's read, for the layout effect below.\n const sync = useRef<((urgent: boolean) => void) | null>(null);\n\n const ref = useCallback((element: HTMLElement | null) => {\n if (element === null) return;\n const doc = element.ownerDocument;\n const win = doc.defaultView ?? window;\n\n const write = (value: ResolvedPlacement | null, urgent: boolean) => {\n // Where it was asked to be: the requested values say so already, no state needed.\n const next =\n value !== null &&\n value.side === requested.current.side &&\n value.align === requested.current.align\n ? null\n : value;\n const previous = written.current;\n if (\n previous === next ||\n (previous !== null &&\n next !== null &&\n previous.side === next.side &&\n previous.align === next.align)\n ) {\n return;\n }\n written.current = next;\n if (urgent) flushSync(() => setResolved(next));\n else setResolved(next);\n };\n\n let listening = false;\n const listen = (on: boolean) => {\n if (on === listening) return;\n listening = on;\n if (on) {\n doc.addEventListener(\"scroll\", onMove, { capture: true, passive: true });\n win.addEventListener(\"resize\", onMove);\n } else {\n doc.removeEventListener(\"scroll\", onMove, { capture: true });\n win.removeEventListener(\"resize\", onMove);\n cancelFrames();\n }\n };\n\n // Both engines (Chromium 156, Firefox 157) apply the scroll-dependent anchoring state, the\n // option and the scroll-compensated geometry alike, in the layout of the frame after the\n // `scroll` event: a read in the handler, or in a rAF registered from it (which runs before\n // that layout), sees the old option even after a forced layout. The timing is unspecified\n // (css-anchor-position-1 §3.3 issue), so read again in the next two frames; a scroll that\n // arrives while that is pending restarts it at the end, so the last scroll is always followed.\n // Separately, Chromium 156 keeps an overflowing option for a top-layer popover once the first\n // frames after the show have passed (a bug, §6.5; upstream item #92): then no frame reads a\n // new option, and `data-side` correctly keeps reporting the applied one. Do not drop the\n // frame reads \"because Chromium does not re-choose\": when it does, it lags like Firefox.\n let frame = 0;\n let again = false;\n const cancelFrames = () => {\n if (frame !== 0) win.cancelAnimationFrame(frame);\n frame = 0;\n again = false;\n };\n const readLater = () => {\n if (frame !== 0) {\n again = true;\n return;\n }\n frame = win.requestAnimationFrame(() => {\n read(true);\n // The popup was found hidden (or `side` turned null): `listen(false)` ended the pair.\n if (!listening) return;\n frame = win.requestAnimationFrame(() => {\n frame = 0;\n read(true);\n if (again && listening) {\n again = false;\n readLater();\n }\n });\n });\n };\n\n const read = (urgent: boolean) => {\n if (requested.current.side === null) {\n listen(false);\n write(null, urgent);\n return;\n }\n if (element.isConnected && isPopoverOpen(element)) {\n listen(true);\n const style = getComputedStyle(element);\n const placement = parsePositionArea(\n style.positionArea,\n toDirection(style.direction),\n () => toDirection(getComputedStyle(doc.documentElement).direction),\n style.writingMode || \"horizontal-tb\",\n );\n write(placement, urgent);\n return;\n }\n listen(false);\n // Hidden, but still rendered while an exit animation runs: keep the resolved side to the\n // end of it. The ResizeObserver sees the box go and resets then.\n // Nothing written, nothing to reset: skip the forced layout (every mount and request change\n // of a hidden popup comes through here).\n if (\n written.current !== null &&\n (!element.isConnected || element.getClientRects().length === 0)\n ) {\n write(null, urgent);\n }\n };\n\n function onEvent() {\n read(true);\n }\n function onMove() {\n // In every Chromium 156 / Firefox 157 probe this read still saw the old option (see the\n // frame reads above); kept as cover for WebKit, which was not probed, at the cost of one\n // style read per scroll event.\n read(true);\n if (listening) readLater();\n }\n\n sync.current = read;\n const observer = typeof ResizeObserver === \"function\" ? new ResizeObserver(onEvent) : null;\n observer?.observe(element);\n element.addEventListener(\"toggle\", onEvent);\n return () => {\n observer?.disconnect();\n element.removeEventListener(\"toggle\", onEvent);\n listen(false);\n if (sync.current === read) sync.current = null;\n };\n }, []);\n\n // A changed request while shown places the popup differently: read again (a layout effect, so\n // the corrected attribute is in the same frame). Also how `side={null}` turns the hook off.\n useLayoutEffect(() => {\n requested.current = { side, align };\n sync.current?.(false);\n }, [side, align]);\n\n if (side === null) return { side: null, align, ref };\n return resolved === null ? { side, align, ref } : { ...resolved, ref };\n}\n\nexport interface AnchoredPlacementRequest<Side extends AnchorSide> extends PlacementRequest<Side> {\n /** `position-try-fallbacks`. Default: flip on both axes. */\n readonly fallbacks?: string;\n}\n\nexport interface AnchoredPlacement<Side extends AnchorSide> extends PlacementResult<Side> {\n /** `data-side` / `data-align` (resolved); no keys when the side is `null` (not owned then). */\n readonly dataAttributes: DataAttributes;\n /**\n * The popup's `style`: the requested inline placement (the browser keeps choosing from it)\n * under the consumer's style, so the consumer wins. The consumer's style alone for `side: null`.\n */\n readonly style: <State>(\n consumer: StateValue<CSSProperties | undefined, State>,\n ) => StateValue<CSSProperties | undefined, State>;\n}\n\n/**\n * An anchored popup's placement (Popover, Tooltip and Menu Popup): `useResolvedPlacement` plus\n * the data attributes and the inline `position-area` / `position-try-fallbacks` it renders.\n */\nexport function useAnchoredPlacement<Side extends AnchorSide>(\n request: AnchoredPlacementRequest<Side>,\n): AnchoredPlacement<Side> {\n const {\n side: requestedSide,\n align: requestedAlign,\n fallbacks = POSITION_TRY_FALLBACKS,\n } = request;\n const placement = useResolvedPlacement({ side: requestedSide, align: requestedAlign });\n const { side, align } = placement;\n const dataAttributes: DataAttributes =\n side !== null ? { \"data-side\": side, \"data-align\": align } : {};\n const style = <State>(\n consumer: StateValue<CSSProperties | undefined, State>,\n ): StateValue<CSSProperties | undefined, State> =>\n requestedSide === null\n ? consumer\n : (s: State) => ({\n positionArea: positionArea(requestedSide, requestedAlign),\n positionTryFallbacks: fallbacks,\n ...resolveStateValue(consumer, s),\n });\n return { ...placement, dataAttributes, style };\n}\n"],"mappings":";;;;;;;AAgCA,MAAM,eAAe,UAA8B,UAAU,QAAQ,QAAQ;;;;;;;;;;;AAY7E,SAAgB,qBACd,SACuB;CACvB,MAAM,EAAE,MAAM,UAAU;CACxB,M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AACvE;;;;;AAuBA,SAAgB,qBACd,SACyB;CACzB,MAAM,EACJ,MAAM,eACN,OAAO,gBACP,YAAY,2BACV;CACJ,MAAM,YAAY,qBAAqB;EAAE,MAAM;EAAe,OAAO;CAAe,CAAC;CACrF,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,iBACJ,SAAS,OAAO;EAAE,aAAa;EAAM,cAAc;CAAM,IAAI,CAAC;CAChE,MAAM,SACJ,aAEA,kBAAkB,OACd,YACC,OAAc;EACb,cAAc,aAAa,eAAe,cAAc;EACxD,sBAAsB;EACtB,GAAG,kBAAkB,UAAU,CAAC;CAClC;CACN,OAAO;EAAE,GAAG;EAAW;EAAgB;CAAM;AAC/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-context.mjs","names":[],"sources":["../../src/menu/menu-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { DelayedPair } from \"../internal/use-delayed-pair.js\";\nimport type { PopoverRootValue } from \"../internal/use-overlay-root.js\";\n\n/**\n * Where focus goes when the menu opens (design/components/menu.md 6.1): the first enabled item,\n * the last one (ArrowUp on the Trigger), or nowhere (a hover-opened submenu keeps focus on its\n * SubmenuTrigger).\n */\nexport type MenuOpenCause = \"first\" | \"last\" | \"none\";\n\n/** How the open being shown should place focus (design 6.1). */\nexport interface MenuOpenFocus {\n readonly cause: MenuOpenCause;\n /**\n * The open came from a pointer click (`detail > 0`): the item is focused without the focus\n * ring where the engine supports `focus({ focusVisible: false })`.\n */\n readonly pointer: boolean;\n}\n\n/**\n * How the current open is placed (design/components/context-menu.md 3.1): against the Trigger\n * (`anchor`: a Menu.Trigger, a foreign invoker, a controlled or platform open), or at a point\n * (`point`: a Menu.ContextTrigger). `generation` grows with every point open or move, so a second\n * right-click at a new point is a state change while the menu is open (4.3).\n */\nexport type MenuPlacement =\n | { readonly kind: \"anchor\" }\n | {\n readonly kind: \"point\";\n readonly x: number;\n readonly y: number;\n readonly generation: number;\n /** The region that opened: the `source` of `showPopover({ source })` (nesting). */\n readonly source: HTMLElement;\n /** The pointer held down at the open, re-captured after a move's re-show (2.1). */\n readonly pointerId: number | undefined;\n /**\n * The popup's computed `direction` at this open or move (4.6): which edge of the menu\n * sits at the point. Read once by `openAt`, never during render.\n */\n readonly direction: \"ltr\" | \"rtl\";\n /**\n * A touch or pen open (4.7): the menu is placed above the point with\n * `--menu-point-gap`, so it does not open under the finger.\n */\n readonly offset: boolean;\n };\n\nexport const ANCHOR_PLACEMENT: MenuPlacement = { kind: \"anchor\" };\n\n/** What a ContextTrigger passes to `openAt`. */\nexport interface MenuOpenAtOptions {\n readonly source: HTMLElement;\n /** The `contextmenu` event, or the long-press `pointerdown` (`details.event`). */\n readonly event: Event;\n /** A pointer opened (quiet focus); `false` for the keyboard (focus ring). */\n readonly pointer: boolean;\n readonly pointerId: number | undefined;\n /** A touch or pen open: placed above the point (4.7). */\n readonly offset: boolean;\n}\n\n/** One menu level: what its Root provides to its Trigger, Popup and items. */\nexport interface MenuContextValue {\n /** The shared popover machinery (`useOverlayRoot`). */\n readonly popover: PopoverRootValue;\n /** This Root is nested in a `Menu.Popup`. */\n readonly submenu: boolean;\n /** The top-level menu: item activation closes the whole stack through it (design 2.2). */\n readonly root: MenuContextValue;\n /** The enclosing menu of a submenu; `null` at the top level. */\n readonly parent: MenuContextValue | null;\n readonly loop: boolean;\n readonly delay: number;\n readonly closeDelay: number;\n /** The Trigger's id (`aria-labelledby` of the Popup). */\n readonly triggerId: string;\n /** Record the focus target of the next open (and whether a pointer asked for it). */\n readonly setOpenCause: (cause: MenuOpenCause, pointer?: boolean) => void;\n /** Read and clear the focus target of the open being shown (default `\"first\"`, keyboard). */\n readonly takeOpenCause: () => MenuOpenFocus;\n /** Submenu hover-intent timers, shared by the SubmenuTrigger and the Popup. */\n readonly timers: DelayedPair;\n /** Placement of the current (or last) open (context-menu.md 3.1). */\n readonly placement: MenuPlacement;\n /**\n * A ContextTrigger opens the menu at `point`, or moves it there when it is already open (no\n * dispatch, 4.3).\n */\n readonly openAt: (\n point: { readonly x: number; readonly y: number },\n options: MenuOpenAtOptions,\n ) => void;\n /**\n * Back to the anchored placement once a point open has been shown and hidden (the popup is no\n * longer visible): the next open that is not a ContextTrigger's (controlled, platform, foreign\n * invoker) places against the Trigger. Ignored when a newer point was recorded meanwhile.\n */\n readonly resetPlacement: (generation: number) => void;\n}\n\nexport const MenuContext = createContext<MenuContextValue | null>(null);\n\n/**\n * `true` inside a `Menu.ContextTrigger`: a `Menu.Root` there is a nested context region's own\n * top-level menu (context-menu.md 2.4), not a misplaced submenu.\n */\nexport const MenuRegionContext = createContext(false);\n\n/**\n * `contextmenu` events a ContextTrigger handled (opened or moved its menu), with the top-level\n * menu they belong to: that menu's document listener leaves its menu open for them\n * (context-menu.md 5 and 14).\n */\nconst handledEvents = new WeakMap<Event, object>();\n\n/**\n * `pointerdown` events that are not a long-press of an enclosing region: claimed by the innermost\n * region that started its timer for them (nested regions), and by every `Menu.Popup` for the\n * presses inside it (a menu inside a region). As `contextmenu`'s `defaultPrevented`\n * rule (context-menu.md 2.4).\n */\nconst claimedPresses = new WeakSet<Event>();\n\nexport function claimPress(event: Event): void {\n claimedPresses.add(event);\n}\n\nexport function isPressClaimed(event: Event): boolean {\n return claimedPresses.has(event);\n}\n\n/**\n * What a hit on a `Menu.SubmenuTrigger` during a press-drag-release gesture does (context-menu.md\n * 2.6): the hover intent a real `pointerenter` / `pointerleave` would start. Registered by the\n * SubmenuTrigger on its element; the gesture runs under pointer capture, so the element never\n * receives boundary events itself.\n */\nexport interface SubmenuHover {\n readonly enter: (event: Event) => void;\n readonly leave: (event: Event) => void;\n /**\n * The submenu's popup, for the gesture's \"still over the submenu\" test (not `commandfor`: a\n * non-button SubmenuTrigger has none).\n */\n readonly popup: () => HTMLElement | null;\n}\n\nconst submenuHovers = new WeakMap<Element, SubmenuHover>();\n\nexport function registerSubmenuHover(element: Element, hover: SubmenuHover): () => void {\n submenuHovers.set(element, hover);\n return () => {\n if (submenuHovers.get(element) === hover) submenuHovers.delete(element);\n };\n}\n\nexport function submenuHover(element: Element): SubmenuHover | undefined {\n return submenuHovers.get(element);\n}\n\n/** The top-level menu's identity: its popup ref object, stable for the Root's lifetime. */\nconst menuKey = (menu: MenuContextValue): object => menu.root.popover.popupRef;\n\nexport function markHandled(event: Event, menu: MenuContextValue): void {\n handledEvents.set(event, menuKey(menu));\n}\n\nexport function isHandledBy(event: Event, menu: MenuContextValue): boolean {\n return handledEvents.get(event) === menuKey(menu);\n}\n\n/**\n * The close an activated item runs once its action settled: the whole stack, through the\n * top-level Root (design 2.2). Recorded at activation: if the menu was dismissed and opened again\n * meanwhile, the close belongs to the previous opening and does nothing (as `useActionTrigger`).\n */\nexport function closeStackLater(menu: MenuContextValue, event: Event): () => void {\n const { popover } = menu.root;\n const generation = popover.openGeneration();\n return () => {\n if (popover.openGeneration() === generation) popover.requestClose(event, \"activate\");\n };\n}\n\nexport function useMenuContext(part: string): MenuContextValue {\n const context = use(MenuContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Menu.Root.`);\n }\n return context;\n}\n\n/** What a `Menu.Popup` tells the items rendered in it. */\nexport interface MenuListContextValue {\n /** The menu this popup belongs to. */\n readonly menu: MenuContextValue;\n /**\n * `experimental_focusgroup` is on and the engine implements it: items render no `tabindex`\n * (Chromium leaves `tabindex=\"-1\"` elements out of a focusgroup) and the JS arrow keys step\n * aside.\n */\n readonly nativeFocusgroup: boolean;\n /** A typeahead buffer is active: Space is a character, not an activation (design 5.1). */\n readonly typingAhead: () => boolean;\n}\n\nexport const MenuListContext = createContext<MenuListContextValue | null>(null);\n\n/** `Menu.Group` / `Menu.RadioGroup`: the id their `Menu.GroupLabel` renders. */\nexport interface MenuGroupContextValue {\n readonly labelId: string;\n}\n\nexport const MenuGroupContext = createContext<MenuGroupContextValue | null>(null);\n\n/** `Menu.RadioGroup`'s state for its `Menu.RadioItem`s. */\nexport interface MenuRadioGroupContextValue {\n /** Optimistic value. */\n readonly value: string | null;\n readonly pending: boolean;\n /**\n * Dispatch `value` through the group's transition; `then` runs once the change action\n * resolved (an item's `closeOnActivate`).\n */\n readonly select: (value: string, event: Event, then: (() => void) | undefined) => void;\n}\n\nexport const MenuRadioGroupContext = createContext<MenuRadioGroupContextValue | null>(null);\n"],"mappings":";;;AAmDA,MAAa,mBAAkC,EAAE,MAAM,SAAS;AAqDhE,MAAa,cAAc,cAAuC,IAAI;;;;;AAMtE,MAAa,oBAAoB,cAAc,KAAK;;;;;;AAOpD,MAAM,gCAAgB,IAAI,QAAuB;;;;;;;AAQjD,MAAM,iCAAiB,IAAI,QAAe;AAE1C,SAAgB,WAAW,OAAoB;CAC7C,eAAe,IAAI,KAAK;AAC1B;AAEA,SAAgB,eAAe,OAAuB;CACpD,OAAO,eAAe,IAAI,KAAK;AACjC;AAkBA,MAAM,gCAAgB,IAAI,QAA+B;AAEzD,SAAgB,qBAAqB,SAAkB,OAAiC;CACtF,cAAc,IAAI,SAAS,KAAK;CAChC,aAAa;EACX,IAAI,cAAc,IAAI,OAAO,MAAM,OAAO,cAAc,OAAO,OAAO;CACxE;AACF;AAEA,SAAgB,aAAa,SAA4C;CACvE,OAAO,cAAc,IAAI,OAAO;AAClC;;AAGA,MAAM,WAAW,SAAmC,KAAK,KAAK,QAAQ;AAEtE,SAAgB,YAAY,OAAc,MAA8B;CACtE,cAAc,IAAI,OAAO,QAAQ,IAAI,CAAC;AACxC;AAEA,SAAgB,YAAY,OAAc,MAAiC;CACzE,OAAO,cAAc,IAAI,KAAK,MAAM,QAAQ,IAAI;AAClD;;;;;;AAOA,SAAgB,gBAAgB,MAAwB,OAA0B;CAChF,MAAM,EAAE,YAAY,KAAK;CACzB,MAAM,aAAa,QAAQ,eAAe;CAC1C,aAAa;EACX,IAAI,QAAQ,eAAe,MAAM,YAAY,QAAQ,aAAa,OAAO,UAAU;CACrF;AACF;AAEA,SAAgB,eAAe,MAAgC;CAC7D,MAAM,UAAU,IAAI,WAAW;CAC/B,IAAI,YAAY,MACd,MAAM,IAAI,MAAM,GAAG,KAAK,sCAAsC;CAEhE,OAAO;AACT;AAgBA,MAAa,kBAAkB,cAA2C,IAAI;AAO9E,MAAa,mBAAmB,cAA4C,IAAI;AAchF,MAAa,wBAAwB,cAAiD,IAAI"}
|
|
1
|
+
{"version":3,"file":"menu-context.mjs","names":[],"sources":["../../src/menu/menu-context.ts"],"sourcesContent":["\"use client\";\nimport { createContext, use } from \"react\";\nimport type { DelayedPair } from \"../internal/use-delayed-pair.js\";\nimport type { PopoverRootValue } from \"../internal/use-overlay-root.js\";\n\n/**\n * Where focus goes when the menu opens (design/components/menu.md 6.1): the first enabled item,\n * the last one (ArrowUp on the Trigger), or nowhere (a hover-opened submenu keeps focus on its\n * SubmenuTrigger).\n */\nexport type MenuOpenCause = \"first\" | \"last\" | \"none\";\n\n/** How the open being shown should place focus (design 6.1). */\nexport interface MenuOpenFocus {\n readonly cause: MenuOpenCause;\n /**\n * The open came from a pointer click (`detail > 0`): the item is focused without the focus\n * ring where the engine supports `focus({ focusVisible: false })`.\n */\n readonly pointer: boolean;\n}\n\n/**\n * How the current open is placed (design/components/context-menu.md 3.1): against the Trigger\n * (`anchor`: a Menu.Trigger, a foreign invoker, a controlled or platform open), or at a point\n * (`point`: a Menu.ContextTrigger). `generation` grows with every point open or move, so a second\n * right-click at a new point is a state change while the menu is open (4.3).\n */\nexport type MenuPlacement =\n | { readonly kind: \"anchor\" }\n | {\n readonly kind: \"point\";\n readonly x: number;\n readonly y: number;\n readonly generation: number;\n /** The region that opened: the `source` of `showPopover({ source })` (nesting). */\n readonly source: HTMLElement;\n /** The pointer held down at the open, re-captured after a move's re-show (2.1). */\n readonly pointerId: number | undefined;\n /**\n * The popup's computed `direction` at this open or move (4.6): which edge of the menu\n * sits at the point. Read once by `openAt`, never during render.\n */\n readonly direction: \"ltr\" | \"rtl\";\n /**\n * A touch or pen open (4.7): the menu is placed above the point with\n * `--menu-point-gap`, so it does not open under the finger.\n */\n readonly offset: boolean;\n };\n\nexport const ANCHOR_PLACEMENT: MenuPlacement = { kind: \"anchor\" };\n\n/** What a ContextTrigger passes to `openAt`. */\nexport interface MenuOpenAtOptions {\n readonly source: HTMLElement;\n /** The `contextmenu` event, or the long-press `pointerdown` (`details.event`). */\n readonly event: Event;\n /** A pointer opened (quiet focus); `false` for the keyboard (focus ring). */\n readonly pointer: boolean;\n readonly pointerId: number | undefined;\n /** A touch or pen open: placed above the point (4.7). */\n readonly offset: boolean;\n}\n\n/** One menu level: what its Root provides to its Trigger, Popup and items. */\nexport interface MenuContextValue {\n /** The shared popover machinery (`useOverlayRoot`). */\n readonly popover: PopoverRootValue;\n /** This Root is nested in a `Menu.Popup`. */\n readonly submenu: boolean;\n /** The top-level menu: item activation closes the whole stack through it (design 2.2). */\n readonly root: MenuContextValue;\n /** The enclosing menu of a submenu; `null` at the top level. */\n readonly parent: MenuContextValue | null;\n readonly loop: boolean;\n readonly delay: number;\n readonly closeDelay: number;\n /** The Trigger's id (`aria-labelledby` of the Popup). */\n readonly triggerId: string;\n /** Record the focus target of the next open (and whether a pointer asked for it). */\n readonly setOpenCause: (cause: MenuOpenCause, pointer?: boolean) => void;\n /** Read and clear the focus target of the open being shown (default `\"first\"`, keyboard). */\n readonly takeOpenCause: () => MenuOpenFocus;\n /** Submenu hover-intent timers, shared by the SubmenuTrigger and the Popup. */\n readonly timers: DelayedPair;\n /** Placement of the current (or last) open (context-menu.md 3.1). */\n readonly placement: MenuPlacement;\n /**\n * A ContextTrigger opens the menu at `point`, or moves it there when it is already open (no\n * dispatch, 4.3).\n */\n readonly openAt: (\n point: { readonly x: number; readonly y: number },\n options: MenuOpenAtOptions,\n ) => void;\n /**\n * Back to the anchored placement once a point open has been shown and hidden (the popup is no\n * longer visible): the next open that is not a ContextTrigger's (controlled, platform, foreign\n * invoker) places against the Trigger. Ignored when a newer point was recorded meanwhile.\n */\n readonly resetPlacement: (generation: number) => void;\n}\n\nexport const MenuContext = createContext<MenuContextValue | null>(null);\n\n/**\n * `true` inside a `Menu.ContextTrigger`: a `Menu.Root` there is a nested context region's own\n * top-level menu (context-menu.md 2.4), not a misplaced submenu.\n */\nexport const MenuRegionContext = createContext(false);\n\n/**\n * `contextmenu` events a ContextTrigger handled (opened or moved its menu), with the top-level\n * menu they belong to: that menu's document listener leaves its menu open for them\n * (context-menu.md 5 and 14).\n */\nconst handledEvents = new WeakMap<Event, object>();\n\n/**\n * `pointerdown` events that are not a long-press of an enclosing region: claimed by the innermost\n * region that started its timer for them (nested regions), and by every `Menu.Popup` for the\n * presses inside it (a menu inside a region). As `contextmenu`'s `defaultPrevented`\n * rule (context-menu.md 2.4).\n */\nconst claimedPresses = new WeakSet<Event>();\n\nexport function claimPress(event: Event): void {\n claimedPresses.add(event);\n}\n\nexport function isPressClaimed(event: Event): boolean {\n return claimedPresses.has(event);\n}\n\n/**\n * What a hit on a `Menu.SubmenuTrigger` during a press-drag-release gesture does (context-menu.md\n * 2.6): the hover intent a real `pointerenter` / `pointerleave` would start. Registered by the\n * SubmenuTrigger on its element; the gesture runs under pointer capture, so the element never\n * receives boundary events itself.\n */\nexport interface SubmenuHover {\n readonly enter: (event: Event) => void;\n readonly leave: (event: Event) => void;\n /**\n * The submenu's popup, for the gesture's \"still over the submenu\" test (not `popovertarget`: a\n * non-button SubmenuTrigger has none).\n */\n readonly popup: () => HTMLElement | null;\n}\n\nconst submenuHovers = new WeakMap<Element, SubmenuHover>();\n\nexport function registerSubmenuHover(element: Element, hover: SubmenuHover): () => void {\n submenuHovers.set(element, hover);\n return () => {\n if (submenuHovers.get(element) === hover) submenuHovers.delete(element);\n };\n}\n\nexport function submenuHover(element: Element): SubmenuHover | undefined {\n return submenuHovers.get(element);\n}\n\n/** The top-level menu's identity: its popup ref object, stable for the Root's lifetime. */\nconst menuKey = (menu: MenuContextValue): object => menu.root.popover.popupRef;\n\nexport function markHandled(event: Event, menu: MenuContextValue): void {\n handledEvents.set(event, menuKey(menu));\n}\n\nexport function isHandledBy(event: Event, menu: MenuContextValue): boolean {\n return handledEvents.get(event) === menuKey(menu);\n}\n\n/**\n * The close an activated item runs once its action settled: the whole stack, through the\n * top-level Root (design 2.2). Recorded at activation: if the menu was dismissed and opened again\n * meanwhile, the close belongs to the previous opening and does nothing (as `useActionTrigger`).\n */\nexport function closeStackLater(menu: MenuContextValue, event: Event): () => void {\n const { popover } = menu.root;\n const generation = popover.openGeneration();\n return () => {\n if (popover.openGeneration() === generation) popover.requestClose(event, \"activate\");\n };\n}\n\nexport function useMenuContext(part: string): MenuContextValue {\n const context = use(MenuContext);\n if (context === null) {\n throw new Error(`${part} must be rendered inside a Menu.Root.`);\n }\n return context;\n}\n\n/** What a `Menu.Popup` tells the items rendered in it. */\nexport interface MenuListContextValue {\n /** The menu this popup belongs to. */\n readonly menu: MenuContextValue;\n /**\n * `experimental_focusgroup` is on and the engine implements it: items render no `tabindex`\n * (Chromium leaves `tabindex=\"-1\"` elements out of a focusgroup) and the JS arrow keys step\n * aside.\n */\n readonly nativeFocusgroup: boolean;\n /** A typeahead buffer is active: Space is a character, not an activation (design 5.1). */\n readonly typingAhead: () => boolean;\n}\n\nexport const MenuListContext = createContext<MenuListContextValue | null>(null);\n\n/** `Menu.Group` / `Menu.RadioGroup`: the id their `Menu.GroupLabel` renders. */\nexport interface MenuGroupContextValue {\n readonly labelId: string;\n}\n\nexport const MenuGroupContext = createContext<MenuGroupContextValue | null>(null);\n\n/** `Menu.RadioGroup`'s state for its `Menu.RadioItem`s. */\nexport interface MenuRadioGroupContextValue {\n /** Optimistic value. */\n readonly value: string | null;\n readonly pending: boolean;\n /**\n * Dispatch `value` through the group's transition; `then` runs once the change action\n * resolved (an item's `closeOnActivate`).\n */\n readonly select: (value: string, event: Event, then: (() => void) | undefined) => void;\n}\n\nexport const MenuRadioGroupContext = createContext<MenuRadioGroupContextValue | null>(null);\n"],"mappings":";;;AAmDA,MAAa,mBAAkC,EAAE,MAAM,SAAS;AAqDhE,MAAa,cAAc,cAAuC,IAAI;;;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CSS Anchor Positioning. Owns the keyboard model (design 5):
|
|
74
74
|
* ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with
|
|
75
75
|
* `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft
|
|
76
|
-
* closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab)
|
|
76
|
+
* closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab);
|
|
77
|
+
* a press on a button of the consumer's that names it (`popovertarget`, `commandfor`) moves no
|
|
78
|
+
* focus, so that button's click closes the menu as `"activate"` (#126).
|
|
77
79
|
* Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While
|
|
78
80
|
* shown, those are where the browser placed it (conventions 13.2), otherwise the requested
|
|
79
81
|
* values.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-popup.d.mts","names":[],"sources":["../../src/menu/menu-popup.tsx"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"menu-popup.d.mts","names":[],"sources":["../../src/menu/menu-popup.tsx"],"mappings":";;;;;YAsCY,WAAW;YACX,YAAY;iBAEP;;WAEN;;;;;;WAMA,MAAM;;WAEN,OAAO;;WAEP;;;;;WAKA;;iBAGM,uBAAuB,KACtC;;;;;;;;;;;EA4BA,OAAO;;;;;;EAMP,QAAQ;;;;;;EAMR;;;;;;;EAOA;;;;;;;EAOA,aAAa;EACb,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;wBA6BpC,YACd,MAAM,UACN,OACA,aACA,yBACA,YACA,WACA,OACA,UACA,WACG,QACF,iBAAc;yBAXD"}
|
package/dist/menu/menu-popup.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import { usePopoverPopup } from "../internal/use-popover-popup.mjs";
|
|
|
14
14
|
import { MenuListContext, claimPress, useMenuContext } from "./menu-context.mjs";
|
|
15
15
|
import { edgeItem } from "./menu-dom.mjs";
|
|
16
16
|
import { capturePointer } from "../internal/pointer-capture.mjs";
|
|
17
|
+
import { listenInvokerPresses } from "../internal/invoker-press.mjs";
|
|
17
18
|
import { scheduleHoverClose } from "./menu-hover.mjs";
|
|
18
19
|
import { listenOutside } from "./menu-outside.mjs";
|
|
19
20
|
import { MENU_POINT_HREF, MENU_POINT_RULES, pointStyle } from "./menu-point.mjs";
|
|
@@ -29,7 +30,9 @@ const FOCUSABLE_SELECTOR = "a[href], button, input, select, textarea, summary, [
|
|
|
29
30
|
* placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):
|
|
30
31
|
* ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with
|
|
31
32
|
* `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft
|
|
32
|
-
* closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab)
|
|
33
|
+
* closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab);
|
|
34
|
+
* a press on a button of the consumer's that names it (`popovertarget`, `commandfor`) moves no
|
|
35
|
+
* focus, so that button's click closes the menu as `"activate"` (#126).
|
|
33
36
|
* Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While
|
|
34
37
|
* shown, those are where the browser placed it (conventions 13.2), otherwise the requested
|
|
35
38
|
* values.
|
|
@@ -83,8 +86,16 @@ function MenuPopup({ side: sideProp, align = "start", keepMounted, experimental_
|
|
|
83
86
|
onToggle: (event) => {
|
|
84
87
|
if (submenu) return;
|
|
85
88
|
const element = popover.popupRef.current;
|
|
86
|
-
if (event.newState === "open" && element !== null && isPopoverOpen(element))
|
|
87
|
-
|
|
89
|
+
if (event.newState === "open" && element !== null && isPopoverOpen(element)) {
|
|
90
|
+
if (outside.current === null) {
|
|
91
|
+
const stopListening = listenOutside(element, menu, () => latestPlacement.current);
|
|
92
|
+
const stopPresses = listenInvokerPresses(element);
|
|
93
|
+
outside.current = () => {
|
|
94
|
+
stopListening();
|
|
95
|
+
stopPresses();
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
} else if (event.newState === "closed") stopOutside();
|
|
88
99
|
}
|
|
89
100
|
});
|
|
90
101
|
const shownKey = useRef(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-popup.mjs","names":[],"sources":["../../src/menu/menu-popup.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useEffect, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/anchor-position.js\";\nimport { CSPContext } from \"../internal/csp-context.js\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { capturePointer } from \"../internal/pointer-capture.js\";\nimport { FSUI_PRECEDENCE } from \"../internal/shipped-styles.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useNativeFocusgroup } from \"../internal/use-native-focusgroup.js\";\nimport { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { useAnchoredPlacement } from \"../internal/use-resolved-placement.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { claimPress, MenuListContext, useMenuContext } from \"./menu-context.js\";\nimport type { MenuListContextValue } from \"./menu-context.js\";\nimport { edgeItem } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport { listenOutside } from \"./menu-outside.js\";\nimport { MENU_POINT_HREF, MENU_POINT_RULES, pointStyle } from \"./menu-point.js\";\nimport { useMenuKeyboard } from \"./use-menu-keyboard.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). */\nexport type MenuSide = AnchorSide;\nexport type MenuAlign = AnchorAlign;\n\nexport interface MenuPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n /**\n * While shown: the physical side the browser placed the popup on (after any fallback flip;\n * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`, and while the menu\n * is placed at a point (`context`).\n */\n readonly side: MenuSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: MenuAlign;\n /** This popup belongs to a submenu. */\n readonly submenu: boolean;\n /**\n * The current open came from a `Menu.ContextTrigger`: the popup is placed at the pointer, with\n * `--menu-point-x` / `--menu-point-y` set inline (`data-context`).\n */\n readonly context: boolean;\n}\n\nexport interface MenuPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"role\"\n | \"aria-labelledby\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onMouseDown\"\n | \"onContextMenu\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Placement against the Trigger through inline `position-area`, with `position-try-fallbacks`\n * flipping it when it does not fit. Default `\"bottom\"` for a top-level menu, `\"inline-end\"` for\n * a submenu (the right of the item in LTR, its left in RTL; its fallback is `flip-inline`\n * only). `\"left\"` / `\"right\"` stay physical. `null` emits no inline positioning (and no\n * `data-side` / `data-align`): the stylesheet owns placement. Ignored for an open from a\n * `Menu.ContextTrigger`, which is placed at the pointer; there `null` also opts out of the\n * inline point placement and the library's `@position-try` rules, leaving only\n * `--menu-point-x` / `--menu-point-y`.\n */\n side?: MenuSide | null;\n /**\n * Alignment along the side. Default `\"start\"` (both levels): inline-relative on a top / bottom\n * side (mirrored under `direction: rtl`), the top edges on the others. Ignored when `side` is\n * `null`.\n */\n align?: MenuAlign;\n /**\n * `false` (default): the items are not rendered while the menu is closed; mounting them is part\n * of the opening transition, so items that suspend hold the open (and the Trigger pending)\n * until they are ready. `true`: they stay mounted inside `<Activity mode=\"hidden\">`.\n */\n keepMounted?: boolean;\n /**\n * Experimental (Chromium 150+). Renders `focusgroup=\"menu wrap|nowrap\"` and, where the engine\n * implements `focusGroup`, lets the browser handle ArrowUp / ArrowDown / Home / End: items then\n * render no `tabindex` and the library's arrow-key handling steps aside. Typeahead, activation,\n * submenu keys and Tab stay in JS. No effect in other engines. Default `false`.\n */\n experimental_focusgroup?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popup element. Animates the opening\n * commit and every library-driven close (an item's activation, the Trigger, ArrowLeft, hover\n * leaving a submenu, controlled `open={false}`) in all engines; dismissals (Escape, a click\n * outside, Tab) animate with CSS only. Without it the part renders no `<ViewTransition>`.\n */\n transition?: ViewTransitionClass;\n className?: StateValue<string | undefined, MenuPopupState>;\n style?: StateValue<CSSProperties | undefined, MenuPopupState>;\n children?: StateValue<ReactNode, MenuPopupState>;\n /** Should render a `<div>`; a `<dialog>` would run the dialog focusing steps. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuPopupState>;\n}\n\n/** What a press may focus inside a popup: items, the popup itself, the consumer's controls. */\nconst FOCUSABLE_SELECTOR =\n 'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])';\n\n/**\n * The menu itself: `<div popover=\"auto\" role=\"menu\" aria-labelledby={trigger} tabindex=\"-1\">`,\n * placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):\n * ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with\n * `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft\n * closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab).\n * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While\n * shown, those are where the browser placed it (conventions 13.2), otherwise the requested\n * values.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),\n * `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on\n * non-item space keeps focus on the current item), `onContextMenu` (no native menu over this\n * one), `onPointerEnter` / `onPointerLeave`, `data-side` / `data-align` unless `side` is `null`\n * or the menu is placed at a point, and `data-context` for an open from a `Menu.ContextTrigger`.\n * Such an open is placed at the pointer: `--menu-point-x` / `--menu-point-y` inline and, unless\n * `side` is `null`, `top` and `left` (`right` for an RTL popup) at the point with the library's\n * `@position-try` fallbacks, whose rules it renders as a hoisted `<style>`. A top-level menu\n * closes at once on a right- or middle-click outside it.\n */\nexport function MenuPopup({\n side: sideProp,\n align = \"start\",\n keepMounted,\n experimental_focusgroup = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuPopupProps) {\n const menu = useMenuContext(\"Menu.Popup\");\n const { popover, submenu, loop } = menu;\n const csp = use(CSPContext);\n // The listeners installed at the open read the placement of the latest commit (4.8).\n const latestPlacement = useLatest(menu.placement);\n // A submenu opens on the inline-end side of its item: the side ArrowRight (ArrowLeft in RTL)\n // points to.\n const sideOption = sideProp === undefined ? (submenu ? \"inline-end\" : \"bottom\") : sideProp;\n // A ContextTrigger's open is placed at the point; nothing is anchored (context-menu.md 3.3).\n const point = menu.placement.kind === \"point\" ? menu.placement : null;\n const requestedSide = point !== null ? null : sideOption;\n // Resolved while shown (conventions 13.2); idle for a point open, which has no side.\n const placement = useAnchoredPlacement({\n side: requestedSide,\n align,\n fallbacks: submenu ? \"flip-inline\" : undefined,\n });\n const { side } = placement;\n const resolvedAlign = placement.align;\n\n const nativeFocusgroup = useNativeFocusgroup(experimental_focusgroup);\n const { onKeyDown, typingAhead } = useMenuKeyboard(menu, nativeFocusgroup);\n\n // The outside right- / middle-click listeners of a top-level menu, while it is shown.\n const outside = useRef<(() => void) | null>(null);\n const stopOutside = useCallback(() => {\n outside.current?.();\n outside.current = null;\n }, []);\n useEffect(() => stopOutside, [stopOutside]);\n\n const { setElement, visible, renderContent, reshow } = usePopoverPopup(popover, {\n part: \"Menu.Popup\",\n // Design 6.1: the first (or last) enabled item by open cause, nothing for a hover open, the\n // popup itself when there are no items.\n // A pointer open focuses without the focus ring where the engine can be told so.\n resolveInitialFocus: (popup) => {\n const { cause, pointer } = menu.takeOpenCause();\n if (cause === \"none\") return null;\n const element = edgeItem(popup, cause) ?? popup;\n return pointer ? { element, focusVisible: false } : element;\n },\n keepMounted,\n transition,\n // A point open nests through the region that opened it (context-menu.md 3.1).\n source: () => (point !== null ? point.source : popover.triggerRef.current),\n onToggle: (event) => {\n if (submenu) return;\n const element = popover.popupRef.current;\n if (event.newState === \"open\" && element !== null && isPopoverOpen(element)) {\n outside.current ??= listenOutside(element, menu, () => latestPlacement.current);\n } else if (event.newState === \"closed\") {\n stopOutside();\n }\n },\n });\n\n // A move (context-menu.md 4.3): the popup is shown and the placement changed since it was\n // shown (a new point, or a right-click in the region while a Trigger open is shown). Re-show\n // it so the respelled fallbacks place it afresh, the source is the region and the first item\n // is focused again; then capture the still-pressed pointer again, against the Firefox / WebKit\n // `pointerup` light dismiss. Runs after the hook's apply effect (declared after it).\n // Once the popup is not visible (hidden, exit animation over) and no open is intended or in\n // flight, a point placement goes back to anchored for the next open that is not a\n // ContextTrigger's: after a point open that was shown and closed, and after one that was\n // rejected or refused.\n const shownKey = useRef<number | \"anchor\" | null>(null);\n useLayoutEffect(() => {\n const element = popover.popupRef.current;\n if (element === null) return;\n const key = point !== null ? point.generation : \"anchor\";\n if (isPopoverOpen(element)) {\n if (shownKey.current !== null && shownKey.current !== key && reshow()) {\n capturePointer(element, point?.pointerId);\n }\n shownKey.current = key;\n } else {\n shownKey.current = null;\n if (!visible && point !== null && !popover.pending && !popover.intended()) {\n menu.resetPlacement(point.generation);\n }\n }\n });\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName === \"DIALOG\"\n ? \"Menu.Popup: rendered a <dialog>. Render a <div>: a <dialog popover> runs the dialog \" +\n \"focusing steps, which fight the menu's item focus.\"\n : null),\n );\n const devRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n // A press inside a menu is never a long-press of a Menu.ContextTrigger around it.\n // Native, so it runs before React's root listener dispatches to the region.\n const onPointerDown = (event: Event) => claimPress(event);\n element.addEventListener(\"pointerdown\", onPointerDown);\n return () => element.removeEventListener(\"pointerdown\", onPointerDown);\n },\n [checkElement],\n );\n const placementRef = placement.ref;\n const ref = useMergedRefs(setElement, devRef, placementRef);\n\n const listContext = useMemo<MenuListContextValue>(\n () => ({ menu, nativeFocusgroup, typingAhead }),\n [menu, nativeFocusgroup, typingAhead],\n );\n\n const state: MenuPopupState = {\n open: popover.committed,\n side,\n align: resolvedAlign,\n submenu,\n context: point !== null,\n };\n\n // Tab / Shift+Tab or any focus move out of the tree closes the whole stack at once (design\n // 2.2): submenus are DOM descendants of the top-level popup, the Trigger is outside on purpose.\n // A null `relatedTarget` (window blur, a removed element) closes nothing.\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n if (submenu) return;\n const popup = event.currentTarget;\n const next = event.relatedTarget;\n if (!(next instanceof Node) || popup.contains(next)) return;\n if (isPopoverOpen(popup)) popup.hidePopover();\n };\n\n // A press on non-item space (padding, a Separator, a GroupLabel) would focus the popup itself\n // (`tabindex=\"-1\"`) and take focus off the current item; keep it where it is (the\n // pointer-focus model of design 6.2). Focusable content of the consumer's (a text field) still\n // takes focus.\n const onMouseDown = (event: MouseEvent<HTMLElement>) => {\n if (event.button !== 0) return;\n const target = event.target as Element;\n const focusable = target.closest(FOCUSABLE_SELECTOR);\n if (focusable === null || focusable.getAttribute(\"role\") === \"menu\") event.preventDefault();\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n role: \"menu\",\n \"aria-labelledby\": menu.triggerId,\n // The popup itself takes focus as the last resort when a menu has no items.\n tabIndex: -1,\n ...(experimental_focusgroup && { focusgroup: `menu ${loop ? \"wrap\" : \"nowrap\"}` }),\n onKeyDown,\n onBlur,\n onMouseDown,\n // No native menu over the custom one. The popup is a sibling of any ContextTrigger, so this\n // event never reaches a region as a move; an outer region sees it prevented and stays quiet.\n onContextMenu: (event: MouseEvent<HTMLElement>) => {\n event.preventDefault();\n },\n ...(submenu && {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") menu.timers.cancelClose();\n },\n onPointerLeave: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") scheduleHoverClose(menu, event.nativeEvent);\n },\n }),\n ...placement.dataAttributes,\n \"data-context\": point !== null ? \"\" : undefined,\n };\n\n // The shipped `@position-try` rules (conventions 12): hoisted into <head> and deduplicated by\n // React, rendered only by a point open that does not opt out with `side={null}`, with the\n // `<CSPProvider>` nonce for a nonce-based `style-src`.\n const pointRules =\n point !== null && sideOption !== null ? (\n <style href={MENU_POINT_HREF} precedence={FSUI_PRECEDENCE} nonce={csp?.nonce}>\n {MENU_POINT_RULES}\n </style>\n ) : null;\n\n const content = (s: MenuPopupState): ReactNode => (\n <MenuListContext value={listContext}>\n {pointRules}\n {renderContent(() => resolveStateValue(children, s))}\n </MenuListContext>\n );\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The inline placement sits under the consumer's style: the consumer wins.\n style:\n point !== null\n ? (s) => ({ ...pointStyle(point, sideOption === null), ...resolveStateValue(style, s) })\n : placement.style(style),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Menu.Popup\", transition, element);\n}\n\nMenuPopup.displayName = \"MenuPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AA0FvC,MAAM,qBACJ;;;;;;;;;;;;;;;;;;;;;AAsBF,SAAgB,UAAU,EACxB,MAAM,UACN,QAAQ,SACR,aACA,0BAA0B,OAC1B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kB;EACnD,IAAI,cAAc,QAAQ,UAAU,aAAa,MAAM,MAAM,QAAQ,MAAM,eAAe;CAC5F;CAEA,MAAM,eAA8D;EAClE,IAAI,QAAQ,IAAI;EAChB,SAAS;EACT,MAAM;EACN,mBAAmB,KAAK;EAExB,UAAU;EACV,GAAI,2BAA2B,EAAE,YAAY,QAAQ,OAAO,SAAS,WAAW;EAChF;EACA;EACA;EAGA,gBAAgB,UAAmC;GACjD,MAAM,eAAe;EACvB;EACA,GAAI,WAAW;GACb,iBAAiB,UAAqC;IACpD,IAAI,MAAM,gBAAgB,SAAS,KAAK,OAAO,YAAY;GAC7D;GACA,iBAAiB,UAAqC;IACpD,IAAI,MAAM,gBAAgB,SAAS,mBAAmB,MAAM,MAAM,WAAW;GAC/E;EACF;EACA,GAAG,UAAU;EACb,gBAAgB,UAAU,OAAO,KAAK,KAAA;CACxC;CAKA,MAAM,aACJ,UAAU,QAAQ,eAAe,OAC/B,oBAAC,SAAD;EAAO,MAAM;EAAiB,YAAY;EAAiB,OAAO,KAAK;EACpE,UAAA;CACI,CAAA,IACL;CAEN,MAAM,WAAW,MACf,qBAAC,iBAAD;EAAiB,OAAO;EAAxB,UAAA,CACG,YACA,oBAAoB,kBAAkB,UAAU,CAAC,CAAC,CACpC;;CAGnB,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA;EACA;EAEA,OACE,UAAU,QACL,OAAO;GAAE,GAAG,WAAW,OAAO,eAAe,IAAI;GAAG,GAAG,kBAAkB,OAAO,CAAC;EAAE,KACpF,UAAU,MAAM,KAAK;EAC3B,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,cAAc,YAAY,OAAO;AAChE;AAEA,UAAU,cAAc"}
|
|
1
|
+
{"version":3,"file":"menu-popup.mjs","names":[],"sources":["../../src/menu/menu-popup.tsx"],"sourcesContent":["\"use client\";\nimport { use, useCallback, useEffect, useLayoutEffect, useMemo, useRef } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n FocusEvent,\n MouseEvent,\n PointerEvent,\n ReactNode,\n ViewTransitionClass,\n} from \"react\";\nimport type { AnchorAlign, AnchorSide } from \"../internal/anchor-position.js\";\nimport { CSPContext } from \"../internal/csp-context.js\";\nimport { listenInvokerPresses } from \"../internal/invoker-press.js\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { capturePointer } from \"../internal/pointer-capture.js\";\nimport { FSUI_PRECEDENCE } from \"../internal/shipped-styles.js\";\nimport { useTransitionBoundary } from \"../internal/transition-boundary.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useNativeFocusgroup } from \"../internal/use-native-focusgroup.js\";\nimport { usePopoverPopup } from \"../internal/use-popover-popup.js\";\nimport { useAnchoredPlacement } from \"../internal/use-resolved-placement.js\";\nimport { resolveStateValue, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { claimPress, MenuListContext, useMenuContext } from \"./menu-context.js\";\nimport type { MenuListContextValue } from \"./menu-context.js\";\nimport { edgeItem } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport { listenOutside } from \"./menu-outside.js\";\nimport { MENU_POINT_HREF, MENU_POINT_RULES, pointStyle } from \"./menu-point.js\";\nimport { useMenuKeyboard } from \"./use-menu-keyboard.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** `inline-start` / `inline-end` follow the popup's `direction` (conventions 13.1). */\nexport type MenuSide = AnchorSide;\nexport type MenuAlign = AnchorAlign;\n\nexport interface MenuPopupState {\n /** Committed open state. Read `:popover-open` for the DOM truth. */\n readonly open: boolean;\n /**\n * While shown: the physical side the browser placed the popup on (after any fallback flip;\n * conventions 13.2). Otherwise the `side` prop. `null` with `side={null}`, and while the menu\n * is placed at a point (`context`).\n */\n readonly side: MenuSide | null;\n /** While shown: the resolved alignment; otherwise the `align` prop. */\n readonly align: MenuAlign;\n /** This popup belongs to a submenu. */\n readonly submenu: boolean;\n /**\n * The current open came from a `Menu.ContextTrigger`: the popup is placed at the pointer, with\n * `--menu-point-x` / `--menu-point-y` set inline (`data-context`).\n */\n readonly context: boolean;\n}\n\nexport interface MenuPopupProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n | \"id\"\n | \"popover\"\n | \"role\"\n | \"aria-labelledby\"\n | \"onKeyDown\"\n | \"onFocus\"\n | \"onBlur\"\n | \"onMouseDown\"\n | \"onContextMenu\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"onToggle\"\n | \"onBeforeToggle\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * Placement against the Trigger through inline `position-area`, with `position-try-fallbacks`\n * flipping it when it does not fit. Default `\"bottom\"` for a top-level menu, `\"inline-end\"` for\n * a submenu (the right of the item in LTR, its left in RTL; its fallback is `flip-inline`\n * only). `\"left\"` / `\"right\"` stay physical. `null` emits no inline positioning (and no\n * `data-side` / `data-align`): the stylesheet owns placement. Ignored for an open from a\n * `Menu.ContextTrigger`, which is placed at the pointer; there `null` also opts out of the\n * inline point placement and the library's `@position-try` rules, leaving only\n * `--menu-point-x` / `--menu-point-y`.\n */\n side?: MenuSide | null;\n /**\n * Alignment along the side. Default `\"start\"` (both levels): inline-relative on a top / bottom\n * side (mirrored under `direction: rtl`), the top edges on the others. Ignored when `side` is\n * `null`.\n */\n align?: MenuAlign;\n /**\n * `false` (default): the items are not rendered while the menu is closed; mounting them is part\n * of the opening transition, so items that suspend hold the open (and the Trigger pending)\n * until they are ready. `true`: they stay mounted inside `<Activity mode=\"hidden\">`.\n */\n keepMounted?: boolean;\n /**\n * Experimental (Chromium 150+). Renders `focusgroup=\"menu wrap|nowrap\"` and, where the engine\n * implements `focusGroup`, lets the browser handle ArrowUp / ArrowDown / Home / End: items then\n * render no `tabindex` and the library's arrow-key handling steps aside. Typeahead, activation,\n * submenu keys and Tab stay in JS. No effect in other engines. Default `false`.\n */\n experimental_focusgroup?: boolean;\n /**\n * Forwarded to the `<ViewTransition default>` around the popup element. Animates the opening\n * commit and every library-driven close (an item's activation, the Trigger, ArrowLeft, hover\n * leaving a submenu, controlled `open={false}`) in all engines; dismissals (Escape, a click\n * outside, Tab) animate with CSS only. Without it the part renders no `<ViewTransition>`.\n */\n transition?: ViewTransitionClass;\n className?: StateValue<string | undefined, MenuPopupState>;\n style?: StateValue<CSSProperties | undefined, MenuPopupState>;\n children?: StateValue<ReactNode, MenuPopupState>;\n /** Should render a `<div>`; a `<dialog>` would run the dialog focusing steps. */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, MenuPopupState>;\n}\n\n/** What a press may focus inside a popup: items, the popup itself, the consumer's controls. */\nconst FOCUSABLE_SELECTOR =\n 'a[href], button, input, select, textarea, summary, [tabindex], [contenteditable]:not([contenteditable=\"false\"])';\n\n/**\n * The menu itself: `<div popover=\"auto\" role=\"menu\" aria-labelledby={trigger} tabindex=\"-1\">`,\n * placed against its Trigger with CSS Anchor Positioning. Owns the keyboard model (design 5):\n * ArrowUp / ArrowDown / Home / End move focus between items (or the browser does, with\n * `experimental_focusgroup` where supported), printable characters run typeahead, ArrowLeft\n * closes a submenu. The top-level popup closes the whole menu at once when focus leaves it (Tab);\n * a press on a button of the consumer's that names it (`popovertarget`, `commandfor`) moves no\n * focus, so that button's click closes the menu as `\"activate\"` (#126).\n * Style it with `:popover-open`; it emits `data-side` / `data-align` but no `data-open`. While\n * shown, those are where the browser placed it (conventions 13.2), otherwise the requested\n * values.\n *\n * Owned keys (conventions 1.2): `id`, `popover`, `role`, `aria-labelledby` (token-merged),\n * `tabIndex`, `focusgroup` (with the flag), `onKeyDown`, `onBlur`, `onMouseDown` (a press on\n * non-item space keeps focus on the current item), `onContextMenu` (no native menu over this\n * one), `onPointerEnter` / `onPointerLeave`, `data-side` / `data-align` unless `side` is `null`\n * or the menu is placed at a point, and `data-context` for an open from a `Menu.ContextTrigger`.\n * Such an open is placed at the pointer: `--menu-point-x` / `--menu-point-y` inline and, unless\n * `side` is `null`, `top` and `left` (`right` for an RTL popup) at the point with the library's\n * `@position-try` fallbacks, whose rules it renders as a hoisted `<style>`. A top-level menu\n * closes at once on a right- or middle-click outside it.\n */\nexport function MenuPopup({\n side: sideProp,\n align = \"start\",\n keepMounted,\n experimental_focusgroup = false,\n transition,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuPopupProps) {\n const menu = useMenuContext(\"Menu.Popup\");\n const { popover, submenu, loop } = menu;\n const csp = use(CSPContext);\n // The listeners installed at the open read the placement of the latest commit (4.8).\n const latestPlacement = useLatest(menu.placement);\n // A submenu opens on the inline-end side of its item: the side ArrowRight (ArrowLeft in RTL)\n // points to.\n const sideOption = sideProp === undefined ? (submenu ? \"inline-end\" : \"bottom\") : sideProp;\n // A ContextTrigger's open is placed at the point; nothing is anchored (context-menu.md 3.3).\n const point = menu.placement.kind === \"point\" ? menu.placement : null;\n const requestedSide = point !== null ? null : sideOption;\n // Resolved while shown (conventions 13.2); idle for a point open, which has no side.\n const placement = useAnchoredPlacement({\n side: requestedSide,\n align,\n fallbacks: submenu ? \"flip-inline\" : undefined,\n });\n const { side } = placement;\n const resolvedAlign = placement.align;\n\n const nativeFocusgroup = useNativeFocusgroup(experimental_focusgroup);\n const { onKeyDown, typingAhead } = useMenuKeyboard(menu, nativeFocusgroup);\n\n // The outside right- / middle-click listeners and the foreign invoker press guard (#126) of a\n // top-level menu, while it is shown.\n const outside = useRef<(() => void) | null>(null);\n const stopOutside = useCallback(() => {\n outside.current?.();\n outside.current = null;\n }, []);\n useEffect(() => stopOutside, [stopOutside]);\n\n const { setElement, visible, renderContent, reshow } = usePopoverPopup(popover, {\n part: \"Menu.Popup\",\n // Design 6.1: the first (or last) enabled item by open cause, nothing for a hover open, the\n // popup itself when there are no items.\n // A pointer open focuses without the focus ring where the engine can be told so.\n resolveInitialFocus: (popup) => {\n const { cause, pointer } = menu.takeOpenCause();\n if (cause === \"none\") return null;\n const element = edgeItem(popup, cause) ?? popup;\n return pointer ? { element, focusVisible: false } : element;\n },\n keepMounted,\n transition,\n // A point open nests through the region that opened it (context-menu.md 3.1).\n source: () => (point !== null ? point.source : popover.triggerRef.current),\n onToggle: (event) => {\n if (submenu) return;\n const element = popover.popupRef.current;\n if (event.newState === \"open\" && element !== null && isPopoverOpen(element)) {\n if (outside.current === null) {\n const stopListening = listenOutside(element, menu, () => latestPlacement.current);\n const stopPresses = listenInvokerPresses(element);\n outside.current = () => {\n stopListening();\n stopPresses();\n };\n }\n } else if (event.newState === \"closed\") {\n stopOutside();\n }\n },\n });\n\n // A move (context-menu.md 4.3): the popup is shown and the placement changed since it was\n // shown (a new point, or a right-click in the region while a Trigger open is shown). Re-show\n // it so the respelled fallbacks place it afresh, the source is the region and the first item\n // is focused again; then capture the still-pressed pointer again, against the Firefox / WebKit\n // `pointerup` light dismiss. Runs after the hook's apply effect (declared after it).\n // Once the popup is not visible (hidden, exit animation over) and no open is intended or in\n // flight, a point placement goes back to anchored for the next open that is not a\n // ContextTrigger's: after a point open that was shown and closed, and after one that was\n // rejected or refused.\n const shownKey = useRef<number | \"anchor\" | null>(null);\n useLayoutEffect(() => {\n const element = popover.popupRef.current;\n if (element === null) return;\n const key = point !== null ? point.generation : \"anchor\";\n if (isPopoverOpen(element)) {\n if (shownKey.current !== null && shownKey.current !== key && reshow()) {\n capturePointer(element, point?.pointerId);\n }\n shownKey.current = key;\n } else {\n shownKey.current = null;\n if (!visible && point !== null && !popover.pending && !popover.intended()) {\n menu.resetPlacement(point.generation);\n }\n }\n });\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName === \"DIALOG\"\n ? \"Menu.Popup: rendered a <dialog>. Render a <div>: a <dialog popover> runs the dialog \" +\n \"focusing steps, which fight the menu's item focus.\"\n : null),\n );\n const devRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n // A press inside a menu is never a long-press of a Menu.ContextTrigger around it.\n // Native, so it runs before React's root listener dispatches to the region.\n const onPointerDown = (event: Event) => claimPress(event);\n element.addEventListener(\"pointerdown\", onPointerDown);\n return () => element.removeEventListener(\"pointerdown\", onPointerDown);\n },\n [checkElement],\n );\n const placementRef = placement.ref;\n const ref = useMergedRefs(setElement, devRef, placementRef);\n\n const listContext = useMemo<MenuListContextValue>(\n () => ({ menu, nativeFocusgroup, typingAhead }),\n [menu, nativeFocusgroup, typingAhead],\n );\n\n const state: MenuPopupState = {\n open: popover.committed,\n side,\n align: resolvedAlign,\n submenu,\n context: point !== null,\n };\n\n // Tab / Shift+Tab or any focus move out of the tree closes the whole stack at once (design\n // 2.2): submenus are DOM descendants of the top-level popup, the Trigger is outside on purpose.\n // A null `relatedTarget` (window blur, a removed element) closes nothing.\n const onBlur = (event: FocusEvent<HTMLElement>) => {\n if (submenu) return;\n const popup = event.currentTarget;\n const next = event.relatedTarget;\n if (!(next instanceof Node) || popup.contains(next)) return;\n if (isPopoverOpen(popup)) popup.hidePopover();\n };\n\n // A press on non-item space (padding, a Separator, a GroupLabel) would focus the popup itself\n // (`tabindex=\"-1\"`) and take focus off the current item; keep it where it is (the\n // pointer-focus model of design 6.2). Focusable content of the consumer's (a text field) still\n // takes focus.\n const onMouseDown = (event: MouseEvent<HTMLElement>) => {\n if (event.button !== 0) return;\n const target = event.target as Element;\n const focusable = target.closest(FOCUSABLE_SELECTOR);\n if (focusable === null || focusable.getAttribute(\"role\") === \"menu\") event.preventDefault();\n };\n\n const libraryProps: ComponentPropsWithRef<\"div\"> & DataAttributes = {\n id: popover.ids.popup,\n popover: \"auto\",\n role: \"menu\",\n \"aria-labelledby\": menu.triggerId,\n // The popup itself takes focus as the last resort when a menu has no items.\n tabIndex: -1,\n ...(experimental_focusgroup && { focusgroup: `menu ${loop ? \"wrap\" : \"nowrap\"}` }),\n onKeyDown,\n onBlur,\n onMouseDown,\n // No native menu over the custom one. The popup is a sibling of any ContextTrigger, so this\n // event never reaches a region as a move; an outer region sees it prevented and stays quiet.\n onContextMenu: (event: MouseEvent<HTMLElement>) => {\n event.preventDefault();\n },\n ...(submenu && {\n onPointerEnter: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") menu.timers.cancelClose();\n },\n onPointerLeave: (event: PointerEvent<HTMLElement>) => {\n if (event.pointerType !== \"touch\") scheduleHoverClose(menu, event.nativeEvent);\n },\n }),\n ...placement.dataAttributes,\n \"data-context\": point !== null ? \"\" : undefined,\n };\n\n // The shipped `@position-try` rules (conventions 12): hoisted into <head> and deduplicated by\n // React, rendered only by a point open that does not opt out with `side={null}`, with the\n // `<CSPProvider>` nonce for a nonce-based `style-src`.\n const pointRules =\n point !== null && sideOption !== null ? (\n <style href={MENU_POINT_HREF} precedence={FSUI_PRECEDENCE} nonce={csp?.nonce}>\n {MENU_POINT_RULES}\n </style>\n ) : null;\n\n const content = (s: MenuPopupState): ReactNode => (\n <MenuListContext value={listContext}>\n {pointRules}\n {renderContent(() => resolveStateValue(children, s))}\n </MenuListContext>\n );\n\n const element = useRender<ComponentPropsWithRef<\"div\">, MenuPopupState>({\n defaultElement: \"div\",\n render,\n state,\n className,\n // The inline placement sits under the consumer's style: the consumer wins.\n style:\n point !== null\n ? (s) => ({ ...pointStyle(point, sideOption === null), ...resolveStateValue(style, s) })\n : placement.style(style),\n children: content,\n props: rest,\n libraryProps,\n ref,\n });\n\n return useTransitionBoundary(\"Menu.Popup\", transition, element);\n}\n\nMenuPopup.displayName = \"MenuPopup\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AA0FvC,MAAM,qBACJ;;;;;;;;;;;;;;;;;;;;;;;AAwBF,SAAgB,UAAU,EACxB,MAAM,UACN,QAAQ,SACR,aACA,0BAA0B,OAC1B,YACA,WACA,OACA,UACA,QACA,GAAG,QACc;CACjB,MAAM,OAAO,eAAe,YAAY;CACxC,MAAM,EAAE,SA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AAM,YADS,MAAM,OACI,QAAQ,kBAAkB;EACnD,IAAI,cAAc,QAAQ,UAAU,aAAa,MAAM,MAAM,QAAQ,MAAM,eAAe;CAC5F;CAEA,MAAM,eAA8D;EAClE,IAAI,QAAQ,IAAI;EAChB,SAAS;EACT,MAAM;EACN,mBAAmB,KAAK;EAExB,UAAU;EACV,GAAI,2BAA2B,EAAE,YAAY,QAAQ,OAAO,SAAS,WAAW;EAChF;EACA;EACA;EAGA,gBAAgB,UAAmC;GACjD,MAAM,eAAe;EACvB;EACA,GAAI,WAAW;GACb,iBAAiB,UAAqC;IACpD,IAAI,MAAM,gBAAgB,SAAS,KAAK,OAAO,YAAY;GAC7D;GACA,iBAAiB,UAAqC;IACpD,IAAI,MAAM,gBAAgB,SAAS,mBAAmB,MAAM,MAAM,WAAW;GAC/E;EACF;EACA,GAAG,UAAU;EACb,gBAAgB,UAAU,OAAO,KAAK,KAAA;CACxC;CAKA,MAAM,aACJ,UAAU,QAAQ,eAAe,OAC/B,oBAAC,SAAD;EAAO,MAAM;EAAiB,YAAY;EAAiB,OAAO,KAAK;EACpE,UAAA;CACI,CAAA,IACL;CAEN,MAAM,WAAW,MACf,qBAAC,iBAAD;EAAiB,OAAO;EAAxB,UAAA,CACG,YACA,oBAAoB,kBAAkB,UAAU,CAAC,CAAC,CACpC;;CAGnB,MAAM,UAAU,UAAwD;EACtE,gBAAgB;EAChB;EACA;EACA;EAEA,OACE,UAAU,QACL,OAAO;GAAE,GAAG,WAAW,OAAO,eAAe,IAAI;GAAG,GAAG,kBAAkB,OAAO,CAAC;EAAE,KACpF,UAAU,MAAM,KAAK;EAC3B,UAAU;EACV,OAAO;EACP;EACA;CACF,CAAC;CAED,OAAO,sBAAsB,cAAc,YAAY,OAAO;AAChE;AAEA,UAAU,cAAc"}
|
|
@@ -4,7 +4,7 @@ import { MenuTriggerState } from "./menu-trigger.mjs";
|
|
|
4
4
|
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
5
5
|
//#region src/menu/menu-submenu-trigger.d.ts
|
|
6
6
|
export type MenuSubmenuTriggerState = MenuTriggerState;
|
|
7
|
-
export interface MenuSubmenuTriggerProps extends Omit<MenuItemProps, "action" | "closeOnActivate" | "aria-expanded" | "aria-haspopup" | "onPointerEnter" | "onPointerLeave" | "className" | "style" | "children" | "render"> {
|
|
7
|
+
export interface MenuSubmenuTriggerProps extends Omit<MenuItemProps, "action" | "closeOnActivate" | "aria-expanded" | "aria-haspopup" | "commandfor" | "command" | "popoverTarget" | "popoverTargetAction" | "onPointerEnter" | "onPointerLeave" | "className" | "style" | "children" | "render"> {
|
|
8
8
|
className?: StateValue<string | undefined, MenuSubmenuTriggerState>;
|
|
9
9
|
style?: StateValue<CSSProperties | undefined, MenuSubmenuTriggerState>;
|
|
10
10
|
/** Rendered from optimistic state; must not suspend. */
|
|
@@ -13,13 +13,15 @@ export interface MenuSubmenuTriggerProps extends Omit<MenuItemProps, "action" |
|
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* The item that opens a submenu: an item of the parent menu (`role="menuitem"`, roving
|
|
16
|
-
* `tabindex`, typeahead) and the Trigger of the submenu's Root (`
|
|
17
|
-
* `
|
|
16
|
+
* `tabindex`, typeahead) and the Trigger of the submenu's Root (`popovertarget`,
|
|
17
|
+
* `aria-haspopup="menu"`; no `aria-expanded`: the browser exposes the submenu's state on its
|
|
18
|
+
* invoker, #121). ArrowRight (ArrowLeft in
|
|
18
19
|
* RTL), Enter, Space or a click open the submenu with its first item focused; hovering it opens
|
|
19
20
|
* the submenu after the Root's `delay` and leaves focus where it is.
|
|
20
21
|
*
|
|
21
|
-
* Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `
|
|
22
|
-
* `aria-haspopup`, `aria-expanded`, `data-open`, `data-pending`
|
|
22
|
+
* Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `popoverTarget`,
|
|
23
|
+
* `aria-haspopup`, `aria-expanded`, `data-open`, `data-pending`; `commandfor`, `command` and
|
|
24
|
+
* `popoverTargetAction`, never written) and the item's (`role`,
|
|
23
25
|
* `tabIndex`, `disabled` (absent), `aria-disabled`, `data-disabled`, `data-typeahead`,
|
|
24
26
|
* `onClick`, `onKeyDown`, `onPointerMove`, `onPointerEnter`, `onPointerLeave`).
|
|
25
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-submenu-trigger.d.mts","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"mappings":";;;;;YAyBY,0BAA0B;iBAErB,gCAAgC,KAC/C;
|
|
1
|
+
{"version":3,"file":"menu-submenu-trigger.d.mts","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"mappings":";;;;;YAyBY,0BAA0B;iBAErB,gCAAgC,KAC/C;EAgBA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;wBAiBvC,qBACd,UACA,OACA,WACA,OACA,UACA,WACG,QACF,0BAAuB;yBARV"}
|
|
@@ -14,13 +14,15 @@ import { useCallback } from "react";
|
|
|
14
14
|
const isDev = process.env.NODE_ENV !== "production";
|
|
15
15
|
/**
|
|
16
16
|
* The item that opens a submenu: an item of the parent menu (`role="menuitem"`, roving
|
|
17
|
-
* `tabindex`, typeahead) and the Trigger of the submenu's Root (`
|
|
18
|
-
* `
|
|
17
|
+
* `tabindex`, typeahead) and the Trigger of the submenu's Root (`popovertarget`,
|
|
18
|
+
* `aria-haspopup="menu"`; no `aria-expanded`: the browser exposes the submenu's state on its
|
|
19
|
+
* invoker, #121). ArrowRight (ArrowLeft in
|
|
19
20
|
* RTL), Enter, Space or a click open the submenu with its first item focused; hovering it opens
|
|
20
21
|
* the submenu after the Root's `delay` and leaves focus where it is.
|
|
21
22
|
*
|
|
22
|
-
* Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `
|
|
23
|
-
* `aria-haspopup`, `aria-expanded`, `data-open`, `data-pending`
|
|
23
|
+
* Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `popoverTarget`,
|
|
24
|
+
* `aria-haspopup`, `aria-expanded`, `data-open`, `data-pending`; `commandfor`, `command` and
|
|
25
|
+
* `popoverTargetAction`, never written) and the item's (`role`,
|
|
24
26
|
* `tabIndex`, `disabled` (absent), `aria-disabled`, `data-disabled`, `data-typeahead`,
|
|
25
27
|
* `onClick`, `onKeyDown`, `onPointerMove`, `onPointerEnter`, `onPointerLeave`).
|
|
26
28
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-submenu-trigger.mjs","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n KeyboardEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { usePopoverTrigger } from \"../internal/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { registerSubmenuHover, useMenuContext } from \"./menu-context.js\";\nimport { hasModifier, isRtl } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { openMenuWithFocus } from \"./menu-trigger.js\";\nimport type { MenuTriggerState } from \"./menu-trigger.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport type MenuSubmenuTriggerState = MenuTriggerState;\n\nexport interface MenuSubmenuTriggerProps extends Omit<\n MenuItemProps,\n | \"action\"\n | \"closeOnActivate\"\n | \"aria-expanded\"\n | \"aria-haspopup\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"className\"\n | \"style\"\n | \"children\"\n | \"render\"\n> {\n className?: StateValue<string | undefined, MenuSubmenuTriggerState>;\n style?: StateValue<CSSProperties | undefined, MenuSubmenuTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, MenuSubmenuTriggerState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>;\n}\n\n/**\n * The item that opens a submenu: an item of the parent menu (`role=\"menuitem\"`, roving\n * `tabindex`, typeahead) and the Trigger of the submenu's Root (`
|
|
1
|
+
{"version":3,"file":"menu-submenu-trigger.mjs","names":[],"sources":["../../src/menu/menu-submenu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n KeyboardEvent,\n PointerEvent,\n ReactNode,\n} from \"react\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useLatest } from \"../internal/use-latest.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { usePopoverTrigger } from \"../internal/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { registerSubmenuHover, useMenuContext } from \"./menu-context.js\";\nimport { hasModifier, isRtl } from \"./menu-dom.js\";\nimport { scheduleHoverClose } from \"./menu-hover.js\";\nimport type { MenuItemProps } from \"./menu-item.js\";\nimport { openMenuWithFocus } from \"./menu-trigger.js\";\nimport type { MenuTriggerState } from \"./menu-trigger.js\";\nimport { useMenuItem } from \"./use-menu-item.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport type MenuSubmenuTriggerState = MenuTriggerState;\n\nexport interface MenuSubmenuTriggerProps extends Omit<\n MenuItemProps,\n | \"action\"\n | \"closeOnActivate\"\n | \"aria-expanded\"\n | \"aria-haspopup\"\n | \"commandfor\"\n | \"command\"\n | \"popoverTarget\"\n | \"popoverTargetAction\"\n | \"onPointerEnter\"\n | \"onPointerLeave\"\n | \"className\"\n | \"style\"\n | \"children\"\n | \"render\"\n> {\n className?: StateValue<string | undefined, MenuSubmenuTriggerState>;\n style?: StateValue<CSSProperties | undefined, MenuSubmenuTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, MenuSubmenuTriggerState>;\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>;\n}\n\n/**\n * The item that opens a submenu: an item of the parent menu (`role=\"menuitem\"`, roving\n * `tabindex`, typeahead) and the Trigger of the submenu's Root (`popovertarget`,\n * `aria-haspopup=\"menu\"`; no `aria-expanded`: the browser exposes the submenu's state on its\n * invoker, #121). ArrowRight (ArrowLeft in\n * RTL), Enter, Space or a click open the submenu with its first item focused; hovering it opens\n * the submenu after the Root's `delay` and leaves focus where it is.\n *\n * Owned keys (conventions 1.2): the Trigger's (`type`, `id`, `popoverTarget`,\n * `aria-haspopup`, `aria-expanded`, `data-open`, `data-pending`; `commandfor`, `command` and\n * `popoverTargetAction`, never written) and the item's (`role`,\n * `tabIndex`, `disabled` (absent), `aria-disabled`, `data-disabled`, `data-typeahead`,\n * `onClick`, `onKeyDown`, `onPointerMove`, `onPointerEnter`, `onPointerLeave`).\n */\nexport function MenuSubmenuTrigger({\n disabled = false,\n label,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuSubmenuTriggerProps) {\n const menu = useMenuContext(\"Menu.SubmenuTrigger\");\n useDevWarning(\n !menu.submenu,\n isDev &&\n \"Menu.SubmenuTrigger: rendered in a top-level Menu.Root. Use Menu.Trigger, or put this Root \" +\n \"inside the parent's Menu.Popup.\",\n );\n\n const open = (event: Event) => openMenuWithFocus(menu, event, \"first\");\n\n // The item half: role, roving tabindex, aria-disabled, Enter / Space, pointer focus. Its\n // activation is the click, which the trigger half handles (`activate` below), so the item's own\n // `onClick` is not used.\n const item = useMenuItem({\n part: \"Menu.SubmenuTrigger\",\n role: \"menuitem\",\n disabled,\n label,\n });\n\n const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (event.defaultPrevented || hasModifier(event) || disabled) return;\n const parentPopup = event.currentTarget.closest('[role=\"menu\"]');\n const forward = parentPopup !== null && isRtl(parentPopup) ? \"ArrowLeft\" : \"ArrowRight\";\n if (event.key !== forward) return;\n event.preventDefault();\n open(event.nativeEvent);\n };\n\n // Hover intent (design/components/menu.md 7), shared by the pointer handlers and a\n // press-drag-release gesture of a context menu, whose captured pointer never enters this element\n // (context-menu.md 2.6).\n const hoverEnter = (native: Event) => {\n if (disabled) return;\n menu.timers.open(menu.delay, () => {\n menu.setOpenCause(\"none\");\n menu.popover.requestOpen(native, \"activate\");\n });\n };\n const hoverLeave = (native: Event) => {\n // Leaving before the open delay cancels it; leaving an open submenu's trigger starts the\n // close delay (cancelled by entering the submenu).\n if (menu.popover.intended()) scheduleHoverClose(menu, native);\n else menu.timers.cancel();\n };\n const submenuPopupRef = menu.popover.popupRef;\n const latestHover = useLatest({ enter: hoverEnter, leave: hoverLeave });\n const hoverRef = useCallback(\n (element: HTMLElement) =>\n registerSubmenuHover(element, {\n enter: (event) => latestHover.current.enter(event),\n leave: (event) => latestHover.current.leave(event),\n popup: () => submenuPopupRef.current,\n }),\n [latestHover, submenuPopupRef],\n );\n\n const {\n state,\n libraryProps,\n ref: triggerRef,\n } = usePopoverTrigger(menu.popover, {\n part: \"Menu.SubmenuTrigger\",\n disabled,\n render,\n disabledAs: \"aria\",\n // Item first (Enter / Space activation, pointer focus), then the submenu keys.\n handlers: {\n onKeyDown: (event) => {\n item.libraryProps.onKeyDown(event);\n onKeyDown(event);\n },\n onPointerMove: item.libraryProps.onPointerMove,\n onPointerEnter: (event: PointerEvent<HTMLButtonElement>) => {\n if (event.pointerType !== \"touch\") hoverEnter(event.nativeEvent);\n },\n onPointerLeave: (event: PointerEvent<HTMLButtonElement>) => {\n if (event.pointerType !== \"touch\") hoverLeave(event.nativeEvent);\n },\n },\n // A click opens (or moves focus into the open submenu); it never closes.\n activate: (event) => open(event.nativeEvent),\n opensOnly: true,\n });\n const ref = useMergedRefs(triggerRef, hoverRef);\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuSubmenuTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...libraryProps,\n role: item.libraryProps.role,\n tabIndex: item.libraryProps.tabIndex,\n \"data-typeahead\": item.libraryProps[\"data-typeahead\"],\n id: menu.triggerId,\n \"aria-haspopup\": \"menu\",\n },\n ref,\n });\n}\n\nMenuSubmenuTrigger.displayName = \"MenuSubmenuTrigger\";\n"],"mappings":";;;;;;;;;;;;;AAuBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;AA0CvC,SAAgB,mBAAmB,EACjC,WAAW,OACX,OACA,WACA,OACA,UACA,QACA,GAAG,QACuB;CAC1B,MAAM,OAAO,eAAe,qBAAqB;CACjD,cACE,CAAC,KAAK,SACN,SACE,4HAEJ;CAEA,MAAM,QAAQ,UAAiB,kBAAkB,MAAM,OAAO,OAAO;CAKrE,MAAM,OAAO,YAAY;EACvB,MAAM;EACN,MAAM;EACN;EACA;CACF,CAAC;CAED,MAAM,aAAa,UAA4C;EAC7D,IAAI,MAAM,oBAAoB,YAAY,KAAK,KAAK,UAAU;EAC9D,MAAM,cAAc,MAAM,cAAc,QAAQ,iBAAe;EAC/D,MAAM,UAAU,gBAAgB,QAAQ,MAAM,WAAW,IAAI,cAAc;EAC3E,IAAI,MAAM,QAAQ,SAAS;EAC3B,MAAM,eAAe;EACrB,KAAK,MAAM,WAAW;CACxB;CAKA,MAAM,cAAc,WAAkB;EACpC,IAAI,UAAU;EACd,KAAK,OAAO,KAAK,KAAK,aAAa;GACjC,KAAK,aAAa,MAAM;GACxB,KAAK,QAAQ,YAAY,QAAQ,UAAU;EAC7C,CAAC;CACH;CACA,MAAM,cAAc,WAAkB;EAGpC,IAAI,KAAK,QAAQ,SAAS,GAAG,mBAAmB,MAAM,MAAM;OACvD,KAAK,OAAO,OAAO;CAC1B;CACA,MAAM,kBAAkB,KAAK,QAAQ;CACrC,MAAM,cAAc,UAAU;EAAE,OAAO;EAAY,OAAO;CAAW,CAAC;CACtE,MAAM,WAAW,aACd,YACC,qBAAqB,SAAS;EAC5B,QAAQ,UAAU,YAAY,QAAQ,MAAM,KAAK;EACjD,QAAQ,UAAU,YAAY,QAAQ,MAAM,KAAK;EACjD,aAAa,gBAAgB;CAC/B,CAAC,GACH,CAAC,aAAa,eAAe,CAC/B;CAEA,MAAM,EACJ,OACA,cACA,KAAK,eACH,kBAAkB,KAAK,SAAS;EAClC,MAAM;EACN;EACA;EACA,YAAY;EAEZ,UAAU;GACR,YAAY,UAAU;IACpB,KAAK,aAAa,UAAU,KAAK;IACjC,UAAU,KAAK;GACjB;GACA,eAAe,KAAK,aAAa;GACjC,iBAAiB,UAA2C;IAC1D,IAAI,MAAM,gBAAgB,SAAS,WAAW,MAAM,WAAW;GACjE;GACA,iBAAiB,UAA2C;IAC1D,IAAI,MAAM,gBAAgB,SAAS,WAAW,MAAM,WAAW;GACjE;EACF;EAEA,WAAW,UAAU,KAAK,MAAM,WAAW;EAC3C,WAAW;CACb,CAAC;CACD,MAAM,MAAM,cAAc,YAAY,QAAQ;CAE9C,OAAO,UAAoE;EACzE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAG;GACH,MAAM,KAAK,aAAa;GACxB,UAAU,KAAK,aAAa;GAC5B,kBAAkB,KAAK,aAAa;GACpC,IAAI,KAAK;GACT,iBAAiB;EACnB;EACA;CACF,CAAC;AACH;AAEA,mBAAmB,cAAc"}
|
|
@@ -4,7 +4,7 @@ import "./menu-context.mjs";
|
|
|
4
4
|
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
5
5
|
//#region src/menu/menu-trigger.d.ts
|
|
6
6
|
export type MenuTriggerState = PopoverTriggerHookState;
|
|
7
|
-
export interface MenuTriggerProps extends Omit<ComponentPropsWithRef<"button">, "onClick" | "onKeyDown" | "onMouseDown" | "aria-expanded" | "aria-haspopup" | "className" | "style" | "children"> {
|
|
7
|
+
export interface MenuTriggerProps extends Omit<ComponentPropsWithRef<"button">, "onClick" | "onKeyDown" | "onMouseDown" | "aria-expanded" | "aria-haspopup" | "commandfor" | "command" | "popoverTarget" | "popoverTargetAction" | "className" | "style" | "children"> {
|
|
8
8
|
/**
|
|
9
9
|
* The menu cannot be opened from this button. Native `disabled` on a `<button>`; with a link or
|
|
10
10
|
* component `render`, `aria-disabled="true"` instead (the element stays focusable).
|
|
@@ -15,21 +15,23 @@ export interface MenuTriggerProps extends Omit<ComponentPropsWithRef<"button">,
|
|
|
15
15
|
/** Rendered from optimistic state; must not suspend. */
|
|
16
16
|
children?: StateValue<ReactNode, MenuTriggerState>;
|
|
17
17
|
/**
|
|
18
|
-
* Should render a `<button>` (the
|
|
18
|
+
* Should render a `<button>` (the `popovertarget` path before hydration). Another element works through
|
|
19
19
|
* the click handler, but a press on it while the menu is open is a light dismiss rather than the
|
|
20
20
|
* awaited close.
|
|
21
21
|
*/
|
|
22
22
|
render?: RenderProp<ComponentPropsWithRef<"button">, MenuTriggerState>;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* The menu button: `<button type="button"
|
|
26
|
-
* aria-
|
|
25
|
+
* The menu button: `<button type="button" popovertarget aria-haspopup="menu">`, with no
|
|
26
|
+
* `aria-expanded` (the browser exposes the menu's state on its invoker, #121; a link or other
|
|
27
|
+
* non-button element, or a disabled component `render`, renders it from the shown menu). A click (Enter, Space) toggles the menu through the
|
|
27
28
|
* Root's transition; ArrowDown / ArrowUp open it with the first / last item focused (inside a
|
|
28
29
|
* vertical `Toolbar.Root`: the inline-end arrow, with the first item focused).
|
|
29
30
|
*
|
|
30
31
|
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `id`, `disabled`, `aria-disabled`
|
|
31
|
-
* (link or component `render`), `
|
|
32
|
-
* `
|
|
32
|
+
* (link or component `render`), `popoverTarget`, `aria-haspopup`, `aria-expanded`, `onClick`,
|
|
33
|
+
* `onKeyDown`, `onMouseDown`, `data-open`, `data-pending`, `data-disabled`; `commandfor`,
|
|
34
|
+
* `command` and `popoverTargetAction` (never written; omitted from the props type).
|
|
33
35
|
*/
|
|
34
36
|
export declare function MenuTrigger({ disabled, className, style, children, render, ...rest }: MenuTriggerProps): ReactNode;
|
|
35
37
|
export declare namespace MenuTrigger {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-trigger.d.mts","names":[],"sources":["../../src/menu/menu-trigger.tsx"],"mappings":";;;;;YAqBY,mBAAmB;iBAEd,yBAAyB,KACxC;;;;;
|
|
1
|
+
{"version":3,"file":"menu-trigger.d.mts","names":[],"sources":["../../src/menu/menu-trigger.tsx"],"mappings":";;;;;YAqBY,mBAAmB;iBAEd,yBAAyB,KACxC;;;;;EAkBA;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;;;;;EAMjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;wBA0CvC,cACd,UACA,WACA,OACA,UACA,WACG,QACF,mBAAgB;yBAPH"}
|
|
@@ -30,14 +30,16 @@ function isPointerClick(event) {
|
|
|
30
30
|
return event.type === "click" && event.detail > 0;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* The menu button: `<button type="button"
|
|
34
|
-
* aria-
|
|
33
|
+
* The menu button: `<button type="button" popovertarget aria-haspopup="menu">`, with no
|
|
34
|
+
* `aria-expanded` (the browser exposes the menu's state on its invoker, #121; a link or other
|
|
35
|
+
* non-button element, or a disabled component `render`, renders it from the shown menu). A click (Enter, Space) toggles the menu through the
|
|
35
36
|
* Root's transition; ArrowDown / ArrowUp open it with the first / last item focused (inside a
|
|
36
37
|
* vertical `Toolbar.Root`: the inline-end arrow, with the first item focused).
|
|
37
38
|
*
|
|
38
39
|
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `id`, `disabled`, `aria-disabled`
|
|
39
|
-
* (link or component `render`), `
|
|
40
|
-
* `
|
|
40
|
+
* (link or component `render`), `popoverTarget`, `aria-haspopup`, `aria-expanded`, `onClick`,
|
|
41
|
+
* `onKeyDown`, `onMouseDown`, `data-open`, `data-pending`, `data-disabled`; `commandfor`,
|
|
42
|
+
* `command` and `popoverTargetAction` (never written; omitted from the props type).
|
|
41
43
|
*/
|
|
42
44
|
function MenuTrigger({ disabled = false, className, style, children, render, ...rest }) {
|
|
43
45
|
const menu = useMenuContext("Menu.Trigger");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu-trigger.mjs","names":[],"sources":["../../src/menu/menu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n KeyboardEvent,\n MouseEvent as ReactMouseEvent,\n ReactNode,\n} from \"react\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { useToolbarContext } from \"../internal/toolbar-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePopoverTrigger } from \"../internal/use-popover-trigger.js\";\nimport type { PopoverTriggerHookState } from \"../internal/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useMenuContext } from \"./menu-context.js\";\nimport type { MenuContextValue } from \"./menu-context.js\";\nimport { edgeItem, focusItem, hasModifier, isRtl } from \"./menu-dom.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport type MenuTriggerState = PopoverTriggerHookState;\n\nexport interface MenuTriggerProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n | \"onClick\"\n | \"onKeyDown\"\n | \"onMouseDown\"\n | \"aria-expanded\"\n | \"aria-haspopup\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * The menu cannot be opened from this button. Native `disabled` on a `<button>`; with a link or\n * component `render`, `aria-disabled=\"true\"` instead (the element stays focusable).\n */\n disabled?: boolean;\n className?: StateValue<string | undefined, MenuTriggerState>;\n style?: StateValue<CSSProperties | undefined, MenuTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, MenuTriggerState>;\n /**\n * Should render a `<button>` (the
|
|
1
|
+
{"version":3,"file":"menu-trigger.mjs","names":[],"sources":["../../src/menu/menu-trigger.tsx"],"sourcesContent":["\"use client\";\nimport type {\n ComponentPropsWithRef,\n CSSProperties,\n KeyboardEvent,\n MouseEvent as ReactMouseEvent,\n ReactNode,\n} from \"react\";\nimport { isPopoverOpen } from \"../internal/popover-open.js\";\nimport { useToolbarContext } from \"../internal/toolbar-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useDevWarning } from \"../internal/use-dev-warning.js\";\nimport { usePopoverTrigger } from \"../internal/use-popover-trigger.js\";\nimport type { PopoverTriggerHookState } from \"../internal/use-popover-trigger.js\";\nimport { useRender } from \"../internal/use-render.js\";\nimport { useMenuContext } from \"./menu-context.js\";\nimport type { MenuContextValue } from \"./menu-context.js\";\nimport { edgeItem, focusItem, hasModifier, isRtl } from \"./menu-dom.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\nexport type MenuTriggerState = PopoverTriggerHookState;\n\nexport interface MenuTriggerProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n | \"onClick\"\n | \"onKeyDown\"\n | \"onMouseDown\"\n | \"aria-expanded\"\n | \"aria-haspopup\"\n | \"commandfor\"\n | \"command\"\n | \"popoverTarget\"\n | \"popoverTargetAction\"\n | \"className\"\n | \"style\"\n | \"children\"\n> {\n /**\n * The menu cannot be opened from this button. Native `disabled` on a `<button>`; with a link or\n * component `render`, `aria-disabled=\"true\"` instead (the element stays focusable).\n */\n disabled?: boolean;\n className?: StateValue<string | undefined, MenuTriggerState>;\n style?: StateValue<CSSProperties | undefined, MenuTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, MenuTriggerState>;\n /**\n * Should render a `<button>` (the `popovertarget` path before hydration). Another element works through\n * the click handler, but a press on it while the menu is open is a light dismiss rather than the\n * awaited close.\n */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, MenuTriggerState>;\n}\n\n/**\n * Opens with the first (`\"first\"`) or last (`\"last\"`) item focused, or focuses that item when the\n * menu is already open (a pre-hydration open, design walkthrough 10). Shared with SubmenuTrigger.\n */\nexport function openMenuWithFocus(\n menu: MenuContextValue,\n event: Event,\n which: \"first\" | \"last\",\n): void {\n const { popover } = menu;\n if (popover.intended()) {\n const popup = popover.popupRef.current;\n if (popup !== null && isPopoverOpen(popup)) {\n const item = edgeItem(popup, which);\n if (item !== null) focusItem(item);\n }\n return;\n }\n menu.setOpenCause(which, isPointerClick(event));\n popover.requestOpen(event, \"activate\");\n}\n\n/** A click from a pointing device (`detail` counts clicks; keyboard and `click()` give 0). */\nfunction isPointerClick(event: Event): boolean {\n return event.type === \"click\" && (event as MouseEvent).detail > 0;\n}\n\n/**\n * The menu button: `<button type=\"button\" popovertarget aria-haspopup=\"menu\">`, with no\n * `aria-expanded` (the browser exposes the menu's state on its invoker, #121; a link or other\n * non-button element, or a disabled component `render`, renders it from the shown menu). A click (Enter, Space) toggles the menu through the\n * Root's transition; ArrowDown / ArrowUp open it with the first / last item focused (inside a\n * vertical `Toolbar.Root`: the inline-end arrow, with the first item focused).\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `id`, `disabled`, `aria-disabled`\n * (link or component `render`), `popoverTarget`, `aria-haspopup`, `aria-expanded`, `onClick`,\n * `onKeyDown`, `onMouseDown`, `data-open`, `data-pending`, `data-disabled`; `commandfor`,\n * `command` and `popoverTargetAction` (never written; omitted from the props type).\n */\nexport function MenuTrigger({\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: MenuTriggerProps) {\n const menu = useMenuContext(\"Menu.Trigger\");\n useDevWarning(\n menu.submenu,\n isDev &&\n \"Menu.Trigger: rendered in a submenu. Use Menu.SubmenuTrigger, which is also an item of the \" +\n \"parent menu.\",\n );\n\n // Inside a vertical Toolbar, ArrowDown / ArrowUp are the Toolbar's: the trigger opens on the\n // inline-end arrow instead, as a submenu trigger does (design/components/toggle-group.md 7.4).\n const toolbar = useToolbarContext();\n const onKeyDown = (event: KeyboardEvent<HTMLButtonElement>) => {\n if (disabled || hasModifier(event)) return;\n let which: \"first\" | \"last\";\n if (toolbar?.orientation === \"vertical\") {\n const openKey = isRtl(event.currentTarget) ? \"ArrowLeft\" : \"ArrowRight\";\n if (event.key !== openKey) return;\n which = \"first\";\n } else {\n if (event.key !== \"ArrowDown\" && event.key !== \"ArrowUp\") return;\n which = event.key === \"ArrowDown\" ? \"first\" : \"last\";\n }\n // No page scroll, and an enclosing Toolbar sees `defaultPrevented`; Enter and Space stay the\n // native click.\n event.preventDefault();\n openMenuWithFocus(menu, event.nativeEvent, which);\n };\n\n const { state, libraryProps, ref } = usePopoverTrigger(menu.popover, {\n part: \"Menu.Trigger\",\n disabled,\n render,\n handlers: {\n onKeyDown,\n onMouseDown: (event: ReactMouseEvent<HTMLButtonElement>) => {\n // A press on the Trigger of an open menu must not move focus out of the popup: the Popup's\n // focusout would hide the menu before the click's library-owned close (design 2.2, #110).\n if (event.button === 0 && menu.popover.intended()) event.preventDefault();\n },\n },\n activate: (event) => {\n const native = event.nativeEvent;\n if (menu.popover.intended()) {\n menu.popover.requestClose(native, \"activate\");\n } else {\n menu.setOpenCause(\"first\", isPointerClick(native));\n menu.popover.requestOpen(native, \"activate\");\n }\n },\n });\n\n return useRender<ComponentPropsWithRef<\"button\">, MenuTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n ...libraryProps,\n id: menu.triggerId,\n \"aria-haspopup\": \"menu\",\n },\n ref,\n });\n}\n\nMenuTrigger.displayName = \"MenuTrigger\";\n"],"mappings":";;;;;;;;;AAmBA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;AAwCvC,SAAgB,kBACd,MACA,OACA,OACM;CACN,MAAM,EAAE,YAAY;CAC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AAe,MAAM,CAAC;IACjD,KAAK,QAAQ,YAAY,QAAQ,UAAU;GAC7C;EACF;CACF,CAAC;CAED,OAAO,UAA6D;EAClE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,GAAG;GACH,IAAI,KAAK;GACT,iBAAiB;EACnB;EACA;CACF,CAAC;AACH;AAEA,YAAY,cAAc"}
|
package/dist/popover/index.d.mts
CHANGED
|
@@ -8,7 +8,7 @@ import { PopoverTrigger, PopoverTriggerProps, PopoverTriggerState } from "./popo
|
|
|
8
8
|
//#region src/popover/index.d.ts
|
|
9
9
|
/**
|
|
10
10
|
* Popover built on `popover="auto"` and Invoker Commands: `Root` (no DOM) > `Trigger`
|
|
11
|
-
* (`button[
|
|
11
|
+
* (`button[popovertarget]`) + `Popup` (`dialog[popover=auto][aria-modal=false]`) >
|
|
12
12
|
* `Title`, `Description`, `Close`. The platform gives the top layer, light dismiss, Escape,
|
|
13
13
|
* nesting, the implicit anchor and focus return. JS-free when the Root has none of `open` /
|
|
14
14
|
* `defaultOpen` / `openChangeAction`; otherwise opening and the closes a part asks for are
|
package/dist/popover/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { PopoverTrigger } from "./popover-trigger.mjs";
|
|
|
7
7
|
//#region src/popover/index.ts
|
|
8
8
|
/**
|
|
9
9
|
* Popover built on `popover="auto"` and Invoker Commands: `Root` (no DOM) > `Trigger`
|
|
10
|
-
* (`button[
|
|
10
|
+
* (`button[popovertarget]`) + `Popup` (`dialog[popover=auto][aria-modal=false]`) >
|
|
11
11
|
* `Title`, `Description`, `Close`. The platform gives the top layer, light dismiss, Escape,
|
|
12
12
|
* nesting, the implicit anchor and focus return. JS-free when the Root has none of `open` /
|
|
13
13
|
* `defaultOpen` / `openChangeAction`; otherwise opening and the closes a part asks for are
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/popover/index.ts"],"sourcesContent":["// Ships the platform attribute typings (`command`, `commandfor`) with this subpath\n// (conventions 7.4). Type-only: the built JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport { PopoverClose } from \"./popover-close.js\";\nimport { PopoverDescription } from \"./popover-description.js\";\nimport { PopoverPopup } from \"./popover-popup.js\";\nimport { PopoverRoot } from \"./popover-root.js\";\nimport { PopoverTitle } from \"./popover-title.js\";\nimport { PopoverTrigger } from \"./popover-trigger.js\";\n\n/**\n * Popover built on `popover=\"auto\"` and Invoker Commands: `Root` (no DOM) > `Trigger`\n * (`button[
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/popover/index.ts"],"sourcesContent":["// Ships the platform attribute typings (`command`, `commandfor`) with this subpath\n// (conventions 7.4). Type-only: the built JS has no import of it.\nimport \"../internal/platform-attributes.js\";\nimport { PopoverClose } from \"./popover-close.js\";\nimport { PopoverDescription } from \"./popover-description.js\";\nimport { PopoverPopup } from \"./popover-popup.js\";\nimport { PopoverRoot } from \"./popover-root.js\";\nimport { PopoverTitle } from \"./popover-title.js\";\nimport { PopoverTrigger } from \"./popover-trigger.js\";\n\n/**\n * Popover built on `popover=\"auto\"` and Invoker Commands: `Root` (no DOM) > `Trigger`\n * (`button[popovertarget]`) + `Popup` (`dialog[popover=auto][aria-modal=false]`) >\n * `Title`, `Description`, `Close`. The platform gives the top layer, light dismiss, Escape,\n * nesting, the implicit anchor and focus return. JS-free when the Root has none of `open` /\n * `defaultOpen` / `openChangeAction`; otherwise opening and the closes a part asks for are\n * transitions (pending Trigger, content from committed state), and dismissals are notified\n * through `openChangeAction(false)`.\n */\nexport const Popover = {\n Root: PopoverRoot,\n Trigger: PopoverTrigger,\n Popup: PopoverPopup,\n Close: PopoverClose,\n Title: PopoverTitle,\n Description: PopoverDescription,\n} as const;\n\nexport type {\n PopoverRootProps,\n PopoverRootState,\n PopoverOpenChangeDetails,\n} from \"./popover-root.js\";\nexport type { PopoverTriggerProps, PopoverTriggerState } from \"./popover-trigger.js\";\nexport type {\n PopoverPopupProps,\n PopoverPopupState,\n PopoverSide,\n PopoverAlign,\n} from \"./popover-popup.js\";\nexport type { PopoverCloseProps, PopoverCloseState } from \"./popover-close.js\";\nexport type { PopoverTitleProps, PopoverTitleState } from \"./popover-title.js\";\nexport type { PopoverDescriptionProps, PopoverDescriptionState } from \"./popover-description.js\";\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,MAAa,UAAU;CACrB,MAAM;CACN,SAAS;CACT,OAAO;CACP,OAAO;CACP,OAAO;CACP,aAAa;AACf"}
|
|
@@ -33,7 +33,9 @@ export interface PopoverCloseProps extends Omit<ComponentPropsWithRef<"button">,
|
|
|
33
33
|
* and the close goes through the Root (`openChangeAction(false)` awaited, `hidePopover()` in the
|
|
34
34
|
* commit). With `action` the action runs first in this part's own transition (`data-pending` on
|
|
35
35
|
* the button, with `aria-disabled`; a second click meanwhile is ignored); a rejection leaves the
|
|
36
|
-
* popover open.
|
|
36
|
+
* popover open. It keeps `commandfor` where the Trigger has `popovertarget` (#121): an invoker
|
|
37
|
+
* inside its own popover exposes no state either way, and the `command` event tells the Popup a
|
|
38
|
+
* foreign hide's reason.
|
|
37
39
|
*
|
|
38
40
|
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `commandfor`,
|
|
39
41
|
* `command`, `onClick` (library mode, or with `action`), `aria-disabled`, `data-pending`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover-close.d.mts","names":[],"sources":["../../src/popover/popover-close.tsx"],"mappings":";;;iBAQiB;;WAEN;WACA;;iBAGM,0BAA0B,KACzC;;;;;;;;;EAWA,SAAS,QAAQ,SAAS;;;;;;EAM1B;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC
|
|
1
|
+
{"version":3,"file":"popover-close.d.mts","names":[],"sources":["../../src/popover/popover-close.tsx"],"mappings":";;;iBAQiB;;WAEN;WACA;;iBAGM,0BAA0B,KACzC;;;;;;;;;EAWA,SAAS,QAAQ,SAAS;;;;;;EAM1B;EACA,YAAY,+BAA+B;EAC3C,QAAQ,WAAW,2BAA2B;EAC9C,WAAW,WAAW,WAAW;EACjC,SAAS,WAAW,iCAAiC;;;;;;;;;;;;;;;;wBAiBvC,eACd,QACA,UACA,WACA,OACA,UACA,WACG,QACF,oBAAiB;yBARJ"}
|
|
@@ -10,7 +10,9 @@ import { usePopoverContext } from "./popover-context.mjs";
|
|
|
10
10
|
* and the close goes through the Root (`openChangeAction(false)` awaited, `hidePopover()` in the
|
|
11
11
|
* commit). With `action` the action runs first in this part's own transition (`data-pending` on
|
|
12
12
|
* the button, with `aria-disabled`; a second click meanwhile is ignored); a rejection leaves the
|
|
13
|
-
* popover open.
|
|
13
|
+
* popover open. It keeps `commandfor` where the Trigger has `popovertarget` (#121): an invoker
|
|
14
|
+
* inside its own popover exposes no state either way, and the `command` event tells the Popup a
|
|
15
|
+
* foreign hide's reason.
|
|
14
16
|
*
|
|
15
17
|
* Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `commandfor`,
|
|
16
18
|
* `command`, `onClick` (library mode, or with `action`), `aria-disabled`, `data-pending`,
|