@sereno-ds/ui 0.41.2 → 0.41.4
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/_internal/useIsoLayoutEffect.d.ts +1 -1
- package/dist/_internal/useOutsidePress.d.ts +15 -0
- package/dist/_internal/useOutsidePress.js +20 -0
- package/dist/_internal/useOutsidePress.js.map +1 -0
- package/dist/core/Menu.js +2 -10
- package/dist/core/Menu.js.map +1 -1
- package/dist/forms/Autocomplete.js +2 -11
- package/dist/forms/Autocomplete.js.map +1 -1
- package/dist/forms/AvatarUpload.js +3 -258
- package/dist/forms/AvatarUpload.js.map +1 -1
- package/dist/forms/DatePicker.js +3 -11
- package/dist/forms/DatePicker.js.map +1 -1
- package/dist/forms/Select.js +2 -10
- package/dist/forms/Select.js.map +1 -1
- package/dist/forms/_internal/AvatarCaptureDialog.d.ts +28 -0
- package/dist/forms/_internal/AvatarCaptureDialog.js +127 -0
- package/dist/forms/_internal/AvatarCaptureDialog.js.map +1 -0
- package/dist/forms/_internal/CalendarGrid.js +6 -11
- package/dist/forms/_internal/CalendarGrid.js.map +1 -1
- package/dist/forms/_internal/useCamera.d.ts +12 -0
- package/dist/forms/_internal/useCamera.js +58 -0
- package/dist/forms/_internal/useCamera.js.map +1 -0
- package/dist/forms/_internal/useCropper.d.ts +27 -0
- package/dist/forms/_internal/useCropper.js +92 -0
- package/dist/forms/_internal/useCropper.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/navigation/SidebarNav.d.ts +3 -43
- package/dist/navigation/SidebarNav.js +4 -415
- package/dist/navigation/SidebarNav.js.map +1 -1
- package/dist/navigation/_internal/SidebarNavItems.d.ts +46 -0
- package/dist/navigation/_internal/SidebarNavItems.js +299 -0
- package/dist/navigation/_internal/SidebarNavItems.js.map +1 -0
- package/dist/navigation/_internal/SidebarSubmenuPopover.d.ts +13 -0
- package/dist/navigation/_internal/SidebarSubmenuPopover.js +129 -0
- package/dist/navigation/_internal/SidebarSubmenuPopover.js.map +1 -0
- package/dist/navigation/_internal/sidebarNavContext.d.ts +24 -0
- package/dist/navigation/_internal/sidebarNavContext.js +14 -0
- package/dist/navigation/_internal/sidebarNavContext.js.map +1 -0
- package/package.json +1 -1
|
@@ -2,6 +2,6 @@ import * as React from 'react';
|
|
|
2
2
|
|
|
3
3
|
/** `useLayoutEffect` in the browser, `useEffect` on the server (React 18 warns
|
|
4
4
|
* about the former during SSR). */
|
|
5
|
-
declare const useIsoLayoutEffect: typeof React.
|
|
5
|
+
declare const useIsoLayoutEffect: typeof React.useLayoutEffect;
|
|
6
6
|
|
|
7
7
|
export { useIsoLayoutEffect };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calls `onOutside` when a pointer goes down anywhere outside every element in `refs`, while `enabled`.
|
|
5
|
+
* What `Select`, `Menu`, `Autocomplete`, `DatePicker` and the month / year popover of the calendar all do
|
|
6
|
+
* to close their popup on a press elsewhere (SS-575): one place, one behavior.
|
|
7
|
+
*
|
|
8
|
+
* It listens on `document` in the **capture** phase, so a component that stops the event on its way down
|
|
9
|
+
* cannot hide a press from it. `refs` and `onOutside` are read when the event arrives, so passing a new
|
|
10
|
+
* array or a new callback every render does not re-subscribe. A ref that is `null` (not mounted) counts
|
|
11
|
+
* as "nothing there", so a press is outside of it.
|
|
12
|
+
*/
|
|
13
|
+
declare function useOutsidePress(enabled: boolean, refs: ReadonlyArray<React.RefObject<Element | null>>, onOutside: (event: PointerEvent) => void): void;
|
|
14
|
+
|
|
15
|
+
export { useOutsidePress };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useLatest } from "./useLatest.js";
|
|
3
|
+
function useOutsidePress(enabled, refs, onOutside) {
|
|
4
|
+
const refsRef = useLatest(refs);
|
|
5
|
+
const onOutsideRef = useLatest(onOutside);
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
if (!enabled) return;
|
|
8
|
+
const onDown = (e) => {
|
|
9
|
+
const target = e.target;
|
|
10
|
+
if (refsRef.current.some((r) => r.current?.contains(target))) return;
|
|
11
|
+
onOutsideRef.current(e);
|
|
12
|
+
};
|
|
13
|
+
document.addEventListener("pointerdown", onDown, true);
|
|
14
|
+
return () => document.removeEventListener("pointerdown", onDown, true);
|
|
15
|
+
}, [enabled, refsRef, onOutsideRef]);
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
useOutsidePress
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=useOutsidePress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/_internal/useOutsidePress.ts"],"sourcesContent":["import * as React from 'react';\nimport { useLatest } from './useLatest';\n\n/**\n * Calls `onOutside` when a pointer goes down anywhere outside every element in `refs`, while `enabled`.\n * What `Select`, `Menu`, `Autocomplete`, `DatePicker` and the month / year popover of the calendar all do\n * to close their popup on a press elsewhere (SS-575): one place, one behavior.\n *\n * It listens on `document` in the **capture** phase, so a component that stops the event on its way down\n * cannot hide a press from it. `refs` and `onOutside` are read when the event arrives, so passing a new\n * array or a new callback every render does not re-subscribe. A ref that is `null` (not mounted) counts\n * as \"nothing there\", so a press is outside of it.\n */\nexport function useOutsidePress(\n enabled: boolean,\n refs: ReadonlyArray<React.RefObject<Element | null>>,\n onOutside: (event: PointerEvent) => void,\n): void {\n const refsRef = useLatest(refs);\n const onOutsideRef = useLatest(onOutside);\n React.useEffect(() => {\n if (!enabled) return;\n const onDown = (e: PointerEvent) => {\n const target = e.target as Node;\n if (refsRef.current.some((r) => r.current?.contains(target))) return;\n onOutsideRef.current(e);\n };\n document.addEventListener('pointerdown', onDown, true);\n return () => document.removeEventListener('pointerdown', onDown, true);\n }, [enabled, refsRef, onOutsideRef]);\n}\n"],"mappings":"AAAA,YAAY,WAAW;AACvB,SAAS,iBAAiB;AAYnB,SAAS,gBACd,SACA,MACA,WACM;AACN,QAAM,UAAU,UAAU,IAAI;AAC9B,QAAM,eAAe,UAAU,SAAS;AACxC,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,QAAS;AACd,UAAM,SAAS,CAAC,MAAoB;AAClC,YAAM,SAAS,EAAE;AACjB,UAAI,QAAQ,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,SAAS,MAAM,CAAC,EAAG;AAC9D,mBAAa,QAAQ,CAAC;AAAA,IACxB;AACA,aAAS,iBAAiB,eAAe,QAAQ,IAAI;AACrD,WAAO,MAAM,SAAS,oBAAoB,eAAe,QAAQ,IAAI;AAAA,EACvE,GAAG,CAAC,SAAS,SAAS,YAAY,CAAC;AACrC;","names":[]}
|
package/dist/core/Menu.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { createPortal } from "react-dom";
|
|
5
5
|
import { sx } from "../_internal/style.js";
|
|
6
|
+
import { useOutsidePress } from "../_internal/useOutsidePress.js";
|
|
6
7
|
const isItem = (e) => !("separator" in e) && !("heading" in e);
|
|
7
8
|
const GAP = 6;
|
|
8
9
|
const GUTTER = 12;
|
|
@@ -83,16 +84,7 @@ function Menu({ trigger, adornment, items, children, header, label, align = "end
|
|
|
83
84
|
window.removeEventListener("resize", onResize);
|
|
84
85
|
};
|
|
85
86
|
}, [open, mounted, align, width, close]);
|
|
86
|
-
|
|
87
|
-
if (!open) return;
|
|
88
|
-
const onDown = (e) => {
|
|
89
|
-
const t = e.target;
|
|
90
|
-
if (anchorRef.current?.contains(t) || panelRef.current?.contains(t)) return;
|
|
91
|
-
close(false);
|
|
92
|
-
};
|
|
93
|
-
document.addEventListener("pointerdown", onDown, true);
|
|
94
|
-
return () => document.removeEventListener("pointerdown", onDown, true);
|
|
95
|
-
}, [open, close]);
|
|
87
|
+
useOutsidePress(open, [anchorRef, panelRef], () => close(false));
|
|
96
88
|
const placed = place !== null;
|
|
97
89
|
React.useEffect(() => {
|
|
98
90
|
const panel = panelRef.current;
|
package/dist/core/Menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/Menu.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { sx } from '../_internal/style';\n\n/**\n * Action menu / dropdown - a `trigger` you supply plus a portalled panel of\n * items. Same mechanics as `Select`: `position: fixed` panel measured off the\n * trigger, flips up when there's no room, closes on outside pointerdown / `Escape`\n * / selection, and returns focus to the trigger. `role=\"menu\"` with arrow-key\n * roving. Needs the `sereno-pop` keyframe from `@sereno-ds/ui/styles.css`.\n *\n * Opened with a click or tap, no row is highlighted until the pointer enters one\n * or the user arrows. Opened from the keyboard (Enter, Space or ArrowDown on the\n * trigger; ArrowUp for the last row) the first enabled row is active, with a\n * focus ring, so Enter acts straight away.\n *\n * ```tsx\n * <Menu\n * trigger={<IconButton label=\"Conta\"><User /></IconButton>}\n * items={[\n * { label: 'Configurações', icon: <Settings />, onClick: openSettings },\n * { separator: true },\n * { label: 'Sair', icon: <LogOut />, tone: 'danger', onClick: signOut },\n * ]}\n * />\n * ```\n *\n * For a rich popover (a notifications list, say) pass a render function instead\n * of `items` - it receives `close`:\n * `<Menu trigger={…}>{(close) => <NotificationList onDone={close} />}</Menu>`\n */\n\nexport interface MenuItem {\n label: string;\n icon?: React.ReactNode;\n onClick?: () => void;\n disabled?: boolean;\n /** `danger` paints the row in the error colour (destructive action). */\n tone?: 'default' | 'danger';\n /** Keep the menu open after activating (e.g. a toggle row). Default `false`. */\n keepOpen?: boolean;\n}\n/** A hairline rule between groups. */\nexport interface MenuSeparator {\n separator: true;\n}\n/** A non-interactive group caption. */\nexport interface MenuHeading {\n heading: string;\n}\nexport type MenuEntry = MenuItem | MenuSeparator | MenuHeading;\n\nconst isItem = (e: MenuEntry): e is MenuItem => !('separator' in e) && !('heading' in e);\n\nexport interface MenuProps {\n /** The clickable element that opens the menu (an `IconButton`, `Button`, avatar button…). */\n trigger: React.ReactElement;\n /** Overlaid on the trigger - a notification count, a status dot. Sits in a\n * `pointer-events: none` layer so a click still opens the menu. */\n adornment?: React.ReactNode;\n /** Structured rows. Omit when using the `children` render function. */\n items?: MenuEntry[];\n /** Rich panel content - receives `close`. Mutually exclusive with `items`. */\n children?: (close: () => void) => React.ReactNode;\n /** A block above the `items` - a name + email, a title. Not part of the keyboard roving. */\n header?: React.ReactNode;\n /** Accessible name for the panel, and a heading row when `items` is used. */\n label?: string;\n /** Which trigger edge the panel lines up with. Default `end` (right). */\n align?: 'start' | 'end';\n /** Panel width. Number → px; string → any CSS length. Default: fits the content (min 180). */\n width?: number | string;\n disabled?: boolean;\n /** Controlled open state. Omit for uncontrolled. */\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n}\n\nconst GAP = 6;\nconst GUTTER = 12;\n\n/** `left` is clamped so the panel is always fully on screen; `above` picks the\n * vertical edge. On a narrow (phone) viewport `right` is set too - the panel\n * spans the gutters (centred, full-width) instead of hanging off the trigger. */\ntype Place = { top?: number; bottom?: number; left: number; right?: number; above: boolean; maxH: number };\n\n/** Phone-width viewport (`--bp-sm`). Width only - not `pointer: coarse`, which a\n * trackpad / touch laptop reports on a full-size screen. */\nconst PHONE_W = 560;\n\nexport function Menu({ trigger, adornment, items, children, header, label, align = 'end', width, disabled, open: openProp, onOpenChange }: MenuProps) {\n const rid = React.useId();\n const menuId = `${rid}-menu`;\n const anchorRef = React.useRef<HTMLSpanElement>(null);\n const panelRef = React.useRef<HTMLDivElement>(null);\n\n const isControlled = openProp !== undefined;\n const [openState, setOpenState] = React.useState(false);\n const open = isControlled ? openProp! : openState;\n const setOpen = React.useCallback(\n (next: boolean) => {\n if (!isControlled) setOpenState(next);\n onOpenChange?.(next);\n },\n [isControlled, onOpenChange],\n );\n\n const [mounted, setMounted] = React.useState(false);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- portal target is client-only\n React.useEffect(() => setMounted(true), []);\n\n const [place, setPlace] = React.useState<Place | null>(null);\n const [activeIndex, setActiveIndex] = React.useState(-1);\n // How the user is driving the menu. `pointer` (opened by a click or tap, or the mouse\n // entered a row): nothing is highlighted until a row is hovered or arrowed to. `keyboard`\n // (anything else): the first row is active so Enter works straight away, and the active\n // row gets a focus ring. Unknown opens (a screen reader, the parent forcing `open`) take\n // the keyboard side, the one that stays operable without a pointer.\n const [inputMode, setInputMode] = React.useState<'pointer' | 'keyboard'>('keyboard');\n\n // A fresh open never inherits the last session's row or mode, whichever way it closed\n // (Escape, outside click, the trigger, the parent). Adjusted during render, not in an effect.\n const [wasOpen, setWasOpen] = React.useState(open);\n if (open !== wasOpen) {\n setWasOpen(open);\n if (!open) {\n setActiveIndex(-1);\n setInputMode('keyboard');\n }\n }\n\n const itemIndexes = React.useMemo(() => (items ?? []).map((e, i) => (isItem(e) && !e.disabled ? i : -1)).filter((i) => i >= 0), [items]);\n\n const close = React.useCallback(\n (refocus = true) => {\n setOpen(false);\n if (refocus) {\n const btn = anchorRef.current?.querySelector<HTMLElement>('button, [role=\"button\"], a, [tabindex]');\n btn?.focus({ preventScroll: true });\n }\n },\n [setOpen],\n );\n\n // Measure + place the panel while open. `left` is clamped to keep the whole\n // panel on screen (it can't just right-anchor - on a phone a 360px panel off a\n // trigger 300px from the left would run off the edge). Re-runs on scroll/resize;\n // closes if the trigger scrolls away (mirrors Select's fixed strategy). A\n // microtask re-measure picks up the real panel box once it's in the DOM.\n React.useLayoutEffect(() => {\n if (!open || !mounted) return;\n const anchor = anchorRef.current;\n if (!anchor) return;\n\n const measure = (): Place => {\n const r = anchor.getBoundingClientRect();\n // Fall back to a *desktop* width when unmeasurable - never full-width a\n // menu just because a reading came back 0 (a real phone always reports).\n const vw = window.innerWidth || document.documentElement.clientWidth || 1024;\n const vh = window.innerHeight || document.documentElement.clientHeight || 768;\n const roomBelow = vh - r.bottom - GUTTER;\n const roomAbove = r.top - GUTTER;\n const panelH = panelRef.current?.scrollHeight ?? 240;\n const above = roomBelow < Math.min(panelH, 200) && roomAbove > roomBelow;\n const maxH = Math.max(120, Math.round((above ? roomAbove : roomBelow) - GAP));\n const vert: Pick<Place, 'top' | 'bottom'> = above ? { bottom: Math.max(GUTTER, vh - r.top + GAP) } : { top: r.bottom + GAP };\n\n // Phone-width: span the gutters - centred, full-width - rather than hang off the trigger.\n if (vw <= PHONE_W) return { left: GUTTER, right: GUTTER, ...vert, above, maxH };\n\n const panelW = Math.min(panelRef.current?.offsetWidth || (typeof width === 'number' ? width : 240), vw - GUTTER * 2);\n const wanted = align === 'end' ? r.right - panelW : r.left;\n const left = Math.min(Math.max(GUTTER, wanted), vw - GUTTER - panelW);\n return { left, ...vert, above, maxH };\n };\n\n setPlace(measure());\n const raf = window.setTimeout(() => setPlace(measure()), 0); // real height now that the panel is in the DOM\n const anchorTop = anchor.getBoundingClientRect().top;\n const onScroll = (e: Event) => {\n if (e.target instanceof Node && panelRef.current?.contains(e.target)) return;\n if (Math.abs(anchor.getBoundingClientRect().top - anchorTop) > 1) close(false);\n else setPlace(measure());\n };\n const onResize = () => setPlace(measure());\n window.addEventListener('scroll', onScroll, true);\n window.addEventListener('resize', onResize);\n return () => {\n window.clearTimeout(raf);\n window.removeEventListener('scroll', onScroll, true);\n window.removeEventListener('resize', onResize);\n };\n }, [open, mounted, align, width, close]);\n\n // Outside pointerdown closes.\n React.useEffect(() => {\n if (!open) return;\n const onDown = (e: PointerEvent) => {\n const t = e.target as Node;\n if (anchorRef.current?.contains(t) || panelRef.current?.contains(t)) return;\n close(false);\n };\n document.addEventListener('pointerdown', onDown, true);\n return () => document.removeEventListener('pointerdown', onDown, true);\n }, [open, close]);\n\n // Move focus into the panel on open. Which row starts active depends on how it\n // was opened (see `effectiveActive`). The panel only mounts once `place` is measured,\n // so on the first open of an instance this has to wait for it (`placed`), or the\n // focus stays on the trigger and the arrow keys / Enter never reach the panel.\n // Leave it be if something inside already took focus (an `autoFocus` field in a rich panel).\n const placed = place !== null;\n React.useEffect(() => {\n const panel = panelRef.current;\n if (open && mounted && placed && panel && !panel.contains(document.activeElement)) panel.focus({ preventScroll: true });\n }, [open, mounted, placed]);\n\n // Opened by a pointer, no row is active until one is hovered or arrowed to, so the\n // panel never looks hovered under a cursor that is still on the trigger.\n const effectiveActive = activeIndex >= 0 ? activeIndex : inputMode === 'pointer' ? -1 : itemIndexes[0] ?? -1;\n\n const activate = (i: number) => {\n const e = (items ?? [])[i];\n if (!e || !isItem(e) || e.disabled) return;\n e.onClick?.();\n if (!e.keepOpen) close();\n };\n\n const roverKeyDown = (ev: React.KeyboardEvent) => {\n if (ev.key === 'Escape') {\n ev.preventDefault();\n close();\n return;\n }\n if (ev.key === 'Tab') {\n close(false);\n return;\n }\n if (!items) return;\n const pos = itemIndexes.indexOf(effectiveActive);\n const last = itemIndexes[itemIndexes.length - 1];\n let next: number | undefined;\n if (ev.key === 'ArrowDown') next = itemIndexes[Math.min(pos + 1, itemIndexes.length - 1)];\n // From \"nothing active\" (pointer open) ArrowUp goes to the last row, like on the trigger.\n else if (ev.key === 'ArrowUp') next = pos < 0 ? last : itemIndexes[Math.max(pos - 1, 0)];\n else if (ev.key === 'Home') next = itemIndexes[0];\n else if (ev.key === 'End') next = last;\n else if (ev.key === 'Enter' || ev.key === ' ') {\n ev.preventDefault();\n activate(effectiveActive);\n return;\n } else return;\n ev.preventDefault();\n setInputMode('keyboard');\n if (next !== undefined) setActiveIndex(next);\n };\n\n // `viaPointer` picks the starting state (see `inputMode`).\n const toggle = (viaPointer: boolean) => {\n if (disabled) return;\n if (!open) setInputMode(viaPointer ? 'pointer' : 'keyboard');\n setOpen(!open);\n };\n\n const triggerEl = React.cloneElement(trigger as React.ReactElement<Record<string, unknown>>, {\n onClick: (e: React.MouseEvent) => {\n (trigger.props as { onClick?: (e: React.MouseEvent) => void }).onClick?.(e);\n // A real click or tap carries a click count (`detail` >= 1). Enter / Space on the\n // trigger, a screen reader and `element.click()` all report 0.\n toggle((e?.detail ?? 0) > 0);\n },\n // Menu button pattern: ArrowDown opens on the first row, ArrowUp on the last.\n onKeyDown: (e: React.KeyboardEvent) => {\n (trigger.props as { onKeyDown?: (e: React.KeyboardEvent) => void }).onKeyDown?.(e);\n if (e.defaultPrevented || disabled || open || !items) return;\n if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;\n e.preventDefault();\n setInputMode('keyboard');\n setActiveIndex(e.key === 'ArrowUp' ? itemIndexes[itemIndexes.length - 1] ?? -1 : -1);\n setOpen(true);\n },\n 'aria-haspopup': 'menu',\n 'aria-expanded': open,\n 'aria-controls': open ? menuId : undefined,\n 'data-menu-open': open || undefined,\n });\n\n const panelStyle = (p: Place): React.CSSProperties => {\n const full = p.right != null; // phone: left+right span the gutters, width is implied\n return sx({\n position: 'fixed',\n top: p.top,\n bottom: p.bottom,\n left: p.left,\n right: p.right,\n width: full ? undefined : width ?? 'max-content',\n minWidth: full ? undefined : width ?? 180,\n maxWidth: full ? undefined : `calc(100vw - ${GUTTER * 2}px)`,\n maxHeight: p.maxH,\n zIndex: 1200,\n display: 'flex',\n flexDirection: 'column',\n overflowY: 'auto',\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-md)',\n boxShadow: 'var(--shadow-lg)',\n padding: items ? 'var(--space-1)' : 0,\n outline: 'none',\n transformOrigin: p.above ? 'bottom' : 'top',\n animation: 'sereno-pop var(--duration-fast) var(--ease-out)',\n });\n };\n\n /* eslint-disable react-hooks/refs -- the `children` render function receives `close`, a stable\n useCallback that reads the anchor ref only when a consumer invokes it from an event handler -\n never during this render. */\n return (\n <span ref={anchorRef} style={sx({ display: 'inline-flex', position: 'relative' })}>\n {triggerEl}\n {adornment != null && <span style={sx({ position: 'absolute', inset: 0, pointerEvents: 'none' })}>{adornment}</span>}\n {open &&\n mounted &&\n place &&\n createPortal(\n <div\n ref={panelRef}\n id={menuId}\n role={items ? 'menu' : 'dialog'}\n aria-label={label}\n aria-modal={items ? undefined : true}\n tabIndex={-1}\n onKeyDown={roverKeyDown}\n style={panelStyle(place)}\n >\n {header && (\n <div\n style={sx({\n flex: '0 0 auto',\n padding: 'var(--space-3) var(--space-4)',\n margin: items ? 'calc(var(--space-1) * -1) calc(var(--space-1) * -1) var(--space-1)' : 0,\n borderBottom: 'var(--border-width-hairline) solid var(--border-subtle)',\n fontFamily: 'var(--font-body)',\n })}\n >\n {header}\n </div>\n )}\n {items ? (\n <>\n {label && (\n <div\n style={sx({\n padding: 'var(--space-2) var(--space-3) var(--space-1)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-bold)',\n letterSpacing: 'var(--tracking-caps)',\n textTransform: 'uppercase',\n color: 'var(--text-muted)',\n })}\n >\n {label}\n </div>\n )}\n {items.map((entry, i) => {\n if ('separator' in entry) {\n return <div key={i} role=\"separator\" style={sx({ height: 1, margin: 'var(--space-1) 0', background: 'var(--border-subtle)' })} />;\n }\n if ('heading' in entry) {\n return (\n <div\n key={i}\n style={sx({\n padding: 'var(--space-2) var(--space-3) var(--space-1)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-bold)',\n letterSpacing: 'var(--tracking-caps)',\n textTransform: 'uppercase',\n color: 'var(--text-muted)',\n })}\n >\n {entry.heading}\n </div>\n );\n }\n const danger = entry.tone === 'danger';\n const active = i === effectiveActive && !entry.disabled;\n return (\n <button\n key={i}\n type=\"button\"\n role=\"menuitem\"\n disabled={entry.disabled}\n data-active={active || undefined}\n onMouseEnter={() => {\n if (entry.disabled) return;\n setActiveIndex(i);\n setInputMode('pointer');\n }}\n // Hover ends with the pointer, so the fill must not stay behind on the last\n // row it crossed. A row the keyboard moved to is left alone.\n onMouseLeave={() => {\n if (inputMode === 'pointer') setActiveIndex((a) => (a === i ? -1 : a));\n }}\n onClick={() => activate(i)}\n style={sx({\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-3)',\n width: '100%',\n padding: 'var(--space-2) var(--space-3)',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: active ? 'var(--bg-subtle)' : 'transparent',\n // The active row is not the DOM-focused element (the panel is), so mark it for keyboard users.\n boxShadow: active && inputMode === 'keyboard' ? 'var(--focus-ring)' : 'none',\n color: entry.disabled\n ? 'var(--text-disabled)'\n : danger\n ? 'var(--status-error-fg)'\n : 'var(--text-secondary)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n textAlign: 'left',\n cursor: entry.disabled ? 'not-allowed' : 'pointer',\n })}\n >\n {entry.icon && <span style={sx({ display: 'flex', flex: '0 0 auto' })}>{entry.icon}</span>}\n <span style={sx({ flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' })}>{entry.label}</span>\n </button>\n );\n })}\n </>\n ) : (\n children?.(close)\n )}\n </div>,\n document.body,\n )}\n </span>\n );\n /* eslint-enable react-hooks/refs */\n}\n"],"mappings":";AAkU4B,SA6Bd,UA7Bc,KAsER,YAtEQ;AAhU5B,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AAkDnB,MAAM,SAAS,CAAC,MAAgC,EAAE,eAAe,MAAM,EAAE,aAAa;AA0BtF,MAAM,MAAM;AACZ,MAAM,SAAS;AASf,MAAM,UAAU;AAET,SAAS,KAAK,EAAE,SAAS,WAAW,OAAO,UAAU,QAAQ,OAAO,QAAQ,OAAO,OAAO,UAAU,MAAM,UAAU,aAAa,GAAc;AACpJ,QAAM,MAAM,MAAM,MAAM;AACxB,QAAM,SAAS,GAAG,GAAG;AACrB,QAAM,YAAY,MAAM,OAAwB,IAAI;AACpD,QAAM,WAAW,MAAM,OAAuB,IAAI;AAElD,QAAM,eAAe,aAAa;AAClC,QAAM,CAAC,WAAW,YAAY,IAAI,MAAM,SAAS,KAAK;AACtD,QAAM,OAAO,eAAe,WAAY;AACxC,QAAM,UAAU,MAAM;AAAA,IACpB,CAAC,SAAkB;AACjB,UAAI,CAAC,aAAc,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AO,MAAM,IAAI,KAAK,CAAE;AAAA,oBACvE;AAAA,oBACA,SAAS,MAAM,SAAS,CAAC;AAAA,oBACzB,OAAO,GAAG;AAAA,sBACR,SAAS;AAAA,sBACT,YAAY;AAAA,sBACZ,KAAK;AAAA,sBACL,OAAO;AAAA,sBACP,SAAS;AAAA,sBACT,QAAQ;AAAA,sBACR,cAAc;AAAA,sBACd,YAAY,SAAS,qBAAqB;AAAA;AAAA,sBAE1C,WAAW,UAAU,cAAc,aAAa,sBAAsB;AAAA,sBACtE,OAAO,MAAM,WACT,yBACA,SACE,2BACA;AAAA,sBACN,YAAY;AAAA,sBACZ,UAAU;AAAA,sBACV,WAAW;AAAA,sBACX,QAAQ,MAAM,WAAW,gBAAgB;AAAA,oBAC3C,CAAC;AAAA,oBAEA;AAAA,4BAAM,QAAQ,oBAAC,UAAK,OAAO,GAAG,EAAE,SAAS,QAAQ,MAAM,WAAW,CAAC,GAAI,gBAAM,MAAK;AAAA,sBACnF,oBAAC,UAAK,OAAO,GAAG,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,UAAU,cAAc,YAAY,YAAY,SAAS,CAAC,GAAI,gBAAM,OAAM;AAAA;AAAA;AAAA,kBAvCvH;AAAA,gBAwCP;AAAA,cAEJ,CAAC;AAAA,eACH,IAEA,WAAW,KAAK;AAAA;AAAA;AAAA,MAEpB;AAAA,MACA,SAAS;AAAA,IACX;AAAA,KACJ;AAGJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/core/Menu.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { sx } from '../_internal/style';\nimport { useOutsidePress } from '../_internal/useOutsidePress';\n\n/**\n * Action menu / dropdown - a `trigger` you supply plus a portalled panel of\n * items. Same mechanics as `Select`: `position: fixed` panel measured off the\n * trigger, flips up when there's no room, closes on outside pointerdown / `Escape`\n * / selection, and returns focus to the trigger. `role=\"menu\"` with arrow-key\n * roving. Needs the `sereno-pop` keyframe from `@sereno-ds/ui/styles.css`.\n *\n * Opened with a click or tap, no row is highlighted until the pointer enters one\n * or the user arrows. Opened from the keyboard (Enter, Space or ArrowDown on the\n * trigger; ArrowUp for the last row) the first enabled row is active, with a\n * focus ring, so Enter acts straight away.\n *\n * ```tsx\n * <Menu\n * trigger={<IconButton label=\"Conta\"><User /></IconButton>}\n * items={[\n * { label: 'Configurações', icon: <Settings />, onClick: openSettings },\n * { separator: true },\n * { label: 'Sair', icon: <LogOut />, tone: 'danger', onClick: signOut },\n * ]}\n * />\n * ```\n *\n * For a rich popover (a notifications list, say) pass a render function instead\n * of `items` - it receives `close`:\n * `<Menu trigger={…}>{(close) => <NotificationList onDone={close} />}</Menu>`\n */\n\nexport interface MenuItem {\n label: string;\n icon?: React.ReactNode;\n onClick?: () => void;\n disabled?: boolean;\n /** `danger` paints the row in the error colour (destructive action). */\n tone?: 'default' | 'danger';\n /** Keep the menu open after activating (e.g. a toggle row). Default `false`. */\n keepOpen?: boolean;\n}\n/** A hairline rule between groups. */\nexport interface MenuSeparator {\n separator: true;\n}\n/** A non-interactive group caption. */\nexport interface MenuHeading {\n heading: string;\n}\nexport type MenuEntry = MenuItem | MenuSeparator | MenuHeading;\n\nconst isItem = (e: MenuEntry): e is MenuItem => !('separator' in e) && !('heading' in e);\n\nexport interface MenuProps {\n /** The clickable element that opens the menu (an `IconButton`, `Button`, avatar button…). */\n trigger: React.ReactElement;\n /** Overlaid on the trigger - a notification count, a status dot. Sits in a\n * `pointer-events: none` layer so a click still opens the menu. */\n adornment?: React.ReactNode;\n /** Structured rows. Omit when using the `children` render function. */\n items?: MenuEntry[];\n /** Rich panel content - receives `close`. Mutually exclusive with `items`. */\n children?: (close: () => void) => React.ReactNode;\n /** A block above the `items` - a name + email, a title. Not part of the keyboard roving. */\n header?: React.ReactNode;\n /** Accessible name for the panel, and a heading row when `items` is used. */\n label?: string;\n /** Which trigger edge the panel lines up with. Default `end` (right). */\n align?: 'start' | 'end';\n /** Panel width. Number → px; string → any CSS length. Default: fits the content (min 180). */\n width?: number | string;\n disabled?: boolean;\n /** Controlled open state. Omit for uncontrolled. */\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n}\n\nconst GAP = 6;\nconst GUTTER = 12;\n\n/** `left` is clamped so the panel is always fully on screen; `above` picks the\n * vertical edge. On a narrow (phone) viewport `right` is set too - the panel\n * spans the gutters (centred, full-width) instead of hanging off the trigger. */\ntype Place = { top?: number; bottom?: number; left: number; right?: number; above: boolean; maxH: number };\n\n/** Phone-width viewport (`--bp-sm`). Width only - not `pointer: coarse`, which a\n * trackpad / touch laptop reports on a full-size screen. */\nconst PHONE_W = 560;\n\nexport function Menu({ trigger, adornment, items, children, header, label, align = 'end', width, disabled, open: openProp, onOpenChange }: MenuProps) {\n const rid = React.useId();\n const menuId = `${rid}-menu`;\n const anchorRef = React.useRef<HTMLSpanElement>(null);\n const panelRef = React.useRef<HTMLDivElement>(null);\n\n const isControlled = openProp !== undefined;\n const [openState, setOpenState] = React.useState(false);\n const open = isControlled ? openProp! : openState;\n const setOpen = React.useCallback(\n (next: boolean) => {\n if (!isControlled) setOpenState(next);\n onOpenChange?.(next);\n },\n [isControlled, onOpenChange],\n );\n\n const [mounted, setMounted] = React.useState(false);\n // eslint-disable-next-line react-hooks/set-state-in-effect -- portal target is client-only\n React.useEffect(() => setMounted(true), []);\n\n const [place, setPlace] = React.useState<Place | null>(null);\n const [activeIndex, setActiveIndex] = React.useState(-1);\n // How the user is driving the menu. `pointer` (opened by a click or tap, or the mouse\n // entered a row): nothing is highlighted until a row is hovered or arrowed to. `keyboard`\n // (anything else): the first row is active so Enter works straight away, and the active\n // row gets a focus ring. Unknown opens (a screen reader, the parent forcing `open`) take\n // the keyboard side, the one that stays operable without a pointer.\n const [inputMode, setInputMode] = React.useState<'pointer' | 'keyboard'>('keyboard');\n\n // A fresh open never inherits the last session's row or mode, whichever way it closed\n // (Escape, outside click, the trigger, the parent). Adjusted during render, not in an effect.\n const [wasOpen, setWasOpen] = React.useState(open);\n if (open !== wasOpen) {\n setWasOpen(open);\n if (!open) {\n setActiveIndex(-1);\n setInputMode('keyboard');\n }\n }\n\n const itemIndexes = React.useMemo(() => (items ?? []).map((e, i) => (isItem(e) && !e.disabled ? i : -1)).filter((i) => i >= 0), [items]);\n\n const close = React.useCallback(\n (refocus = true) => {\n setOpen(false);\n if (refocus) {\n const btn = anchorRef.current?.querySelector<HTMLElement>('button, [role=\"button\"], a, [tabindex]');\n btn?.focus({ preventScroll: true });\n }\n },\n [setOpen],\n );\n\n // Measure + place the panel while open. `left` is clamped to keep the whole\n // panel on screen (it can't just right-anchor - on a phone a 360px panel off a\n // trigger 300px from the left would run off the edge). Re-runs on scroll/resize;\n // closes if the trigger scrolls away (mirrors Select's fixed strategy). A\n // microtask re-measure picks up the real panel box once it's in the DOM.\n React.useLayoutEffect(() => {\n if (!open || !mounted) return;\n const anchor = anchorRef.current;\n if (!anchor) return;\n\n const measure = (): Place => {\n const r = anchor.getBoundingClientRect();\n // Fall back to a *desktop* width when unmeasurable - never full-width a\n // menu just because a reading came back 0 (a real phone always reports).\n const vw = window.innerWidth || document.documentElement.clientWidth || 1024;\n const vh = window.innerHeight || document.documentElement.clientHeight || 768;\n const roomBelow = vh - r.bottom - GUTTER;\n const roomAbove = r.top - GUTTER;\n const panelH = panelRef.current?.scrollHeight ?? 240;\n const above = roomBelow < Math.min(panelH, 200) && roomAbove > roomBelow;\n const maxH = Math.max(120, Math.round((above ? roomAbove : roomBelow) - GAP));\n const vert: Pick<Place, 'top' | 'bottom'> = above ? { bottom: Math.max(GUTTER, vh - r.top + GAP) } : { top: r.bottom + GAP };\n\n // Phone-width: span the gutters - centred, full-width - rather than hang off the trigger.\n if (vw <= PHONE_W) return { left: GUTTER, right: GUTTER, ...vert, above, maxH };\n\n const panelW = Math.min(panelRef.current?.offsetWidth || (typeof width === 'number' ? width : 240), vw - GUTTER * 2);\n const wanted = align === 'end' ? r.right - panelW : r.left;\n const left = Math.min(Math.max(GUTTER, wanted), vw - GUTTER - panelW);\n return { left, ...vert, above, maxH };\n };\n\n setPlace(measure());\n const raf = window.setTimeout(() => setPlace(measure()), 0); // real height now that the panel is in the DOM\n const anchorTop = anchor.getBoundingClientRect().top;\n const onScroll = (e: Event) => {\n if (e.target instanceof Node && panelRef.current?.contains(e.target)) return;\n if (Math.abs(anchor.getBoundingClientRect().top - anchorTop) > 1) close(false);\n else setPlace(measure());\n };\n const onResize = () => setPlace(measure());\n window.addEventListener('scroll', onScroll, true);\n window.addEventListener('resize', onResize);\n return () => {\n window.clearTimeout(raf);\n window.removeEventListener('scroll', onScroll, true);\n window.removeEventListener('resize', onResize);\n };\n }, [open, mounted, align, width, close]);\n\n // Outside pointerdown closes.\n useOutsidePress(open, [anchorRef, panelRef], () => close(false));\n\n // Move focus into the panel on open. Which row starts active depends on how it\n // was opened (see `effectiveActive`). The panel only mounts once `place` is measured,\n // so on the first open of an instance this has to wait for it (`placed`), or the\n // focus stays on the trigger and the arrow keys / Enter never reach the panel.\n // Leave it be if something inside already took focus (an `autoFocus` field in a rich panel).\n const placed = place !== null;\n React.useEffect(() => {\n const panel = panelRef.current;\n if (open && mounted && placed && panel && !panel.contains(document.activeElement)) panel.focus({ preventScroll: true });\n }, [open, mounted, placed]);\n\n // Opened by a pointer, no row is active until one is hovered or arrowed to, so the\n // panel never looks hovered under a cursor that is still on the trigger.\n const effectiveActive = activeIndex >= 0 ? activeIndex : inputMode === 'pointer' ? -1 : itemIndexes[0] ?? -1;\n\n const activate = (i: number) => {\n const e = (items ?? [])[i];\n if (!e || !isItem(e) || e.disabled) return;\n e.onClick?.();\n if (!e.keepOpen) close();\n };\n\n const roverKeyDown = (ev: React.KeyboardEvent) => {\n if (ev.key === 'Escape') {\n ev.preventDefault();\n close();\n return;\n }\n if (ev.key === 'Tab') {\n close(false);\n return;\n }\n if (!items) return;\n const pos = itemIndexes.indexOf(effectiveActive);\n const last = itemIndexes[itemIndexes.length - 1];\n let next: number | undefined;\n if (ev.key === 'ArrowDown') next = itemIndexes[Math.min(pos + 1, itemIndexes.length - 1)];\n // From \"nothing active\" (pointer open) ArrowUp goes to the last row, like on the trigger.\n else if (ev.key === 'ArrowUp') next = pos < 0 ? last : itemIndexes[Math.max(pos - 1, 0)];\n else if (ev.key === 'Home') next = itemIndexes[0];\n else if (ev.key === 'End') next = last;\n else if (ev.key === 'Enter' || ev.key === ' ') {\n ev.preventDefault();\n activate(effectiveActive);\n return;\n } else return;\n ev.preventDefault();\n setInputMode('keyboard');\n if (next !== undefined) setActiveIndex(next);\n };\n\n // `viaPointer` picks the starting state (see `inputMode`).\n const toggle = (viaPointer: boolean) => {\n if (disabled) return;\n if (!open) setInputMode(viaPointer ? 'pointer' : 'keyboard');\n setOpen(!open);\n };\n\n const triggerEl = React.cloneElement(trigger as React.ReactElement<Record<string, unknown>>, {\n onClick: (e: React.MouseEvent) => {\n (trigger.props as { onClick?: (e: React.MouseEvent) => void }).onClick?.(e);\n // A real click or tap carries a click count (`detail` >= 1). Enter / Space on the\n // trigger, a screen reader and `element.click()` all report 0.\n toggle((e?.detail ?? 0) > 0);\n },\n // Menu button pattern: ArrowDown opens on the first row, ArrowUp on the last.\n onKeyDown: (e: React.KeyboardEvent) => {\n (trigger.props as { onKeyDown?: (e: React.KeyboardEvent) => void }).onKeyDown?.(e);\n if (e.defaultPrevented || disabled || open || !items) return;\n if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;\n e.preventDefault();\n setInputMode('keyboard');\n setActiveIndex(e.key === 'ArrowUp' ? itemIndexes[itemIndexes.length - 1] ?? -1 : -1);\n setOpen(true);\n },\n 'aria-haspopup': 'menu',\n 'aria-expanded': open,\n 'aria-controls': open ? menuId : undefined,\n 'data-menu-open': open || undefined,\n });\n\n const panelStyle = (p: Place): React.CSSProperties => {\n const full = p.right != null; // phone: left+right span the gutters, width is implied\n return sx({\n position: 'fixed',\n top: p.top,\n bottom: p.bottom,\n left: p.left,\n right: p.right,\n width: full ? undefined : width ?? 'max-content',\n minWidth: full ? undefined : width ?? 180,\n maxWidth: full ? undefined : `calc(100vw - ${GUTTER * 2}px)`,\n maxHeight: p.maxH,\n zIndex: 1200,\n display: 'flex',\n flexDirection: 'column',\n overflowY: 'auto',\n background: 'var(--bg-surface)',\n border: 'var(--border-width-hairline) solid var(--border-default)',\n borderRadius: 'var(--radius-md)',\n boxShadow: 'var(--shadow-lg)',\n padding: items ? 'var(--space-1)' : 0,\n outline: 'none',\n transformOrigin: p.above ? 'bottom' : 'top',\n animation: 'sereno-pop var(--duration-fast) var(--ease-out)',\n });\n };\n\n /* eslint-disable react-hooks/refs -- the `children` render function receives `close`, a stable\n useCallback that reads the anchor ref only when a consumer invokes it from an event handler -\n never during this render. */\n return (\n <span ref={anchorRef} style={sx({ display: 'inline-flex', position: 'relative' })}>\n {triggerEl}\n {adornment != null && <span style={sx({ position: 'absolute', inset: 0, pointerEvents: 'none' })}>{adornment}</span>}\n {open &&\n mounted &&\n place &&\n createPortal(\n <div\n ref={panelRef}\n id={menuId}\n role={items ? 'menu' : 'dialog'}\n aria-label={label}\n aria-modal={items ? undefined : true}\n tabIndex={-1}\n onKeyDown={roverKeyDown}\n style={panelStyle(place)}\n >\n {header && (\n <div\n style={sx({\n flex: '0 0 auto',\n padding: 'var(--space-3) var(--space-4)',\n margin: items ? 'calc(var(--space-1) * -1) calc(var(--space-1) * -1) var(--space-1)' : 0,\n borderBottom: 'var(--border-width-hairline) solid var(--border-subtle)',\n fontFamily: 'var(--font-body)',\n })}\n >\n {header}\n </div>\n )}\n {items ? (\n <>\n {label && (\n <div\n style={sx({\n padding: 'var(--space-2) var(--space-3) var(--space-1)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-bold)',\n letterSpacing: 'var(--tracking-caps)',\n textTransform: 'uppercase',\n color: 'var(--text-muted)',\n })}\n >\n {label}\n </div>\n )}\n {items.map((entry, i) => {\n if ('separator' in entry) {\n return <div key={i} role=\"separator\" style={sx({ height: 1, margin: 'var(--space-1) 0', background: 'var(--border-subtle)' })} />;\n }\n if ('heading' in entry) {\n return (\n <div\n key={i}\n style={sx({\n padding: 'var(--space-2) var(--space-3) var(--space-1)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-2xs)',\n fontWeight: 'var(--weight-bold)',\n letterSpacing: 'var(--tracking-caps)',\n textTransform: 'uppercase',\n color: 'var(--text-muted)',\n })}\n >\n {entry.heading}\n </div>\n );\n }\n const danger = entry.tone === 'danger';\n const active = i === effectiveActive && !entry.disabled;\n return (\n <button\n key={i}\n type=\"button\"\n role=\"menuitem\"\n disabled={entry.disabled}\n data-active={active || undefined}\n onMouseEnter={() => {\n if (entry.disabled) return;\n setActiveIndex(i);\n setInputMode('pointer');\n }}\n // Hover ends with the pointer, so the fill must not stay behind on the last\n // row it crossed. A row the keyboard moved to is left alone.\n onMouseLeave={() => {\n if (inputMode === 'pointer') setActiveIndex((a) => (a === i ? -1 : a));\n }}\n onClick={() => activate(i)}\n style={sx({\n display: 'flex',\n alignItems: 'center',\n gap: 'var(--space-3)',\n width: '100%',\n padding: 'var(--space-2) var(--space-3)',\n border: 'none',\n borderRadius: 'var(--radius-sm)',\n background: active ? 'var(--bg-subtle)' : 'transparent',\n // The active row is not the DOM-focused element (the panel is), so mark it for keyboard users.\n boxShadow: active && inputMode === 'keyboard' ? 'var(--focus-ring)' : 'none',\n color: entry.disabled\n ? 'var(--text-disabled)'\n : danger\n ? 'var(--status-error-fg)'\n : 'var(--text-secondary)',\n fontFamily: 'var(--font-body)',\n fontSize: 'var(--text-sm)',\n textAlign: 'left',\n cursor: entry.disabled ? 'not-allowed' : 'pointer',\n })}\n >\n {entry.icon && <span style={sx({ display: 'flex', flex: '0 0 auto' })}>{entry.icon}</span>}\n <span style={sx({ flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' })}>{entry.label}</span>\n </button>\n );\n })}\n </>\n ) : (\n children?.(close)\n )}\n </div>,\n document.body,\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CAAC;AAAA,eACH,IAEA,WAAW,KAAK;AAAA;AAAA;AAAA,MAEpB;AAAA,MACA,SAAS;AAAA,IACX;AAAA,KACJ;AAGJ;","names":[]}
|
|
@@ -11,6 +11,7 @@ import { useIsoLayoutEffect } from "../_internal/useIsoLayoutEffect.js";
|
|
|
11
11
|
import { useLatest } from "../_internal/useLatest.js";
|
|
12
12
|
import { useCoarsePointer } from "../_internal/useCoarsePointer.js";
|
|
13
13
|
import { useMenuPlacement } from "../_internal/useMenuPlacement.js";
|
|
14
|
+
import { useOutsidePress } from "../_internal/useOutsidePress.js";
|
|
14
15
|
import { revealInList, useRevealActive } from "../_internal/useRevealActive.js";
|
|
15
16
|
import { MenuOption, menuListStyle, menuRowPadY, menuSurfaceStyle } from "../_internal/MenuOption.js";
|
|
16
17
|
import { fieldBoxStyle } from "./_internal/fieldBoxStyle.js";
|
|
@@ -160,17 +161,7 @@ const Autocomplete = React.forwardRef(function Autocomplete2({
|
|
|
160
161
|
useIsoLayoutEffect(() => {
|
|
161
162
|
if (draft !== null && listRef.current) listRef.current.scrollTop = 0;
|
|
162
163
|
}, [draft, firstValue]);
|
|
163
|
-
|
|
164
|
-
React.useEffect(() => {
|
|
165
|
-
if (!open) return;
|
|
166
|
-
const onDown = (e) => {
|
|
167
|
-
const target = e.target;
|
|
168
|
-
if (boxRef.current?.contains(target) || panelRef.current?.contains(target)) return;
|
|
169
|
-
settleRef.current();
|
|
170
|
-
};
|
|
171
|
-
document.addEventListener("pointerdown", onDown, true);
|
|
172
|
-
return () => document.removeEventListener("pointerdown", onDown, true);
|
|
173
|
-
}, [open, settleRef]);
|
|
164
|
+
useOutsidePress(open, [boxRef, panelRef], () => settle());
|
|
174
165
|
const firstEnabledKey = () => visible.find((o) => !o.disabled)?.value ?? null;
|
|
175
166
|
const lastEnabledKey = () => {
|
|
176
167
|
for (let i = rows - 1; i >= 0; i--) if (!visible[i].disabled) return visible[i].value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/forms/Autocomplete.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { ChevronDown, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { srOnlyStyle } from '../_internal/srOnly';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { useIsoLayoutEffect } from '../_internal/useIsoLayoutEffect';\nimport { useLatest } from '../_internal/useLatest';\nimport { useCoarsePointer } from '../_internal/useCoarsePointer';\nimport { useMenuPlacement } from '../_internal/useMenuPlacement';\nimport { revealInList, useRevealActive } from '../_internal/useRevealActive';\nimport { MenuOption, menuListStyle, menuRowPadY, menuSurfaceStyle } from '../_internal/MenuOption';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\n\nexport interface AutocompleteOption {\n value: string;\n label: string;\n disabled?: boolean;\n}\n\n/** Every string the component says. Defaults come from `locale`; pass `labels` to change some. */\nexport interface AutocompleteLabels {\n /** Placeholder of the text box while nothing is chosen. */\n placeholder: string;\n /** aria-label of the clear (×) button. */\n clear: string;\n /** aria-label of the chevron button while the list is closed. */\n open: string;\n /** aria-label of the chevron button while the list is open. */\n close: string;\n /** What a screen reader hears while `loading` (the list itself shows only a spinner). */\n loading: string;\n /** The row shown when no option is left to show. */\n empty: string;\n /** What a screen reader hears when the list changes size. */\n results: (count: number) => string;\n}\n\nconst TEXT: Record<'pt-BR' | 'en', AutocompleteLabels> = {\n 'pt-BR': {\n placeholder: 'Buscar…',\n clear: 'Limpar seleção',\n open: 'Abrir lista',\n close: 'Fechar lista',\n loading: 'Carregando…',\n empty: 'Nenhum resultado',\n results: (n) => (n === 1 ? '1 resultado' : n + ' resultados'),\n },\n en: {\n placeholder: 'Search…',\n clear: 'Clear selection',\n open: 'Open list',\n close: 'Close list',\n loading: 'Loading…',\n empty: 'No results',\n results: (n) => (n === 1 ? '1 result' : n + ' results'),\n },\n};\n\n/**\n * Single choice from a list you search by typing. Like `Select`, but the box is a text field: type\n * to narrow the list, pick one row, and the value is that row. For a list too long to scroll\n * (past ~12 options), or one the server searches and pages (a thousand clients, fifty at a time).\n *\n * The value is the chosen option itself, `{ value, label }`, and it carries its own label. The\n * box shows `value.label` whether or not that option is in `options` right now, which is what\n * keeps the label when the page it came from is no longer loaded. `options` is only what the list\n * shows. `onValueChange` gives the option (or `null` when cleared), not a string.\n *\n * Two kinds of search, one prop apart:\n * - the default filters `options` itself, as you type (case and accents ignored);\n * - `filter={false}` leaves the list alone and tells you what was typed (`onSearch`, debounced),\n * for a list the server already filtered.\n *\n * It is a text box, not free text: what is typed never becomes the value. Leaving the box puts the\n * chosen label back.\n */\nexport interface AutocompleteProps {\n label?: string;\n hint?: string;\n /** Error message; also turns the control red. */\n error?: string;\n required?: boolean;\n /** What the list shows now. Appending rows while it is open is fine: the list keeps its scroll. */\n options?: AutocompleteOption[];\n /** Controlled value: the chosen option, or `null` for none. */\n value?: AutocompleteOption | null;\n /** Uncontrolled initial value. */\n defaultValue?: AutocompleteOption | null;\n /** The chosen option, or `null` when the value is cleared. */\n onValueChange?: (option: AutocompleteOption | null) => void;\n /**\n * How typing narrows `options`. `true` (default): keep the rows whose label contains the text,\n * ignoring case and accents. `false`: show `options` as they are (the server did the filtering).\n * A function decides per row.\n */\n filter?: boolean | ((option: AutocompleteOption, query: string) => boolean);\n /**\n * The text to search for changed: fired as the user types (after `debounce`) and with `''` once\n * the box goes back to showing the chosen label (pick, clear, leave, Esc). Never with the label\n * itself, so it is safe to run the query here. Use it with `filter={false}`.\n */\n onSearch?: (query: string) => void;\n /** Debounce for `onSearch` while typing, in ms. */\n debounce?: number;\n /** The list is waiting for rows: a spinner under them (or alone), the list marked busy, and a screen reader told. */\n loading?: boolean;\n /**\n * The list was scrolled to within about five rows of its end. Fires once per list size, never\n * while `loading`. Pass it only while there is a next page, so a list that is complete asks for nothing.\n */\n onReachEnd?: () => void;\n /** The list opened or closed. For a list that loads when it opens. */\n onOpenChange?: (open: boolean) => void;\n /** A × button, and an emptied box clears the value. */\n clearable?: boolean;\n /** Shown in muted text while nothing is chosen. Defaults to the `locale` text. */\n placeholder?: string;\n size?: 'sm' | 'md' | 'lg';\n disabled?: boolean;\n /** Form field name - mirrored to a hidden input so the chosen value can be submitted. */\n name?: string;\n id?: string;\n containerStyle?: React.CSSProperties;\n /**\n * Accessible name for the text box. Only needed when there's no visible `label`. Takes\n * precedence over `label` if both are set - don't pass both.\n */\n 'aria-label'?: string;\n /** Reserve the hint/error row's height even with neither set - stops the field from growing\n * the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n /** Language of the built-in texts. */\n locale?: 'pt-BR' | 'en';\n /** Override any built-in text. */\n labels?: Partial<AutocompleteLabels>;\n}\n\n/** How close to the end of the list, in rows, `onReachEnd` fires. */\nconst REACH_ROWS = 5;\n\nconst MARKS = /[̀-ͯ]/g;\nconst plain = (s: string) => s.normalize('NFD').replace(MARKS, '').toLowerCase();\n\nfunction narrow(\n options: AutocompleteOption[],\n filter: AutocompleteProps['filter'],\n query: string,\n): AutocompleteOption[] {\n if (filter === false) return options;\n const q = query.trim();\n if (!q) return options;\n if (typeof filter === 'function') return options.filter((o) => filter(o, query));\n const needle = plain(q);\n return options.filter((o) => plain(o.label).includes(needle));\n}\n\n/**\n * `ref` reaches the hidden `<input type=\"hidden\">` that mirrors the chosen value (rendered only\n * when `name` is set - pass it, as `register()` does), the same as `Select`. A plain\n * `{...register(name)}` spread still won't validate on change: wire it through `Controller`, or\n * call the registered `onChange` yourself from `onValueChange`.\n */\nexport const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>(function Autocomplete(\n {\n label,\n hint,\n error,\n required,\n options = [],\n value: valueProp,\n defaultValue,\n onValueChange,\n filter = true,\n onSearch,\n debounce = 250,\n loading = false,\n onReachEnd,\n onOpenChange,\n clearable = true,\n placeholder,\n size = 'md',\n disabled,\n name,\n id,\n containerStyle,\n 'aria-label': ariaLabel,\n preserveHelperSpace,\n locale = 'pt-BR',\n labels,\n },\n ref,\n) {\n const reactId = React.useId();\n const rid = id || reactId;\n const listboxId = `${rid}-listbox`;\n const copy: AutocompleteLabels = { ...TEXT[locale], ...labels };\n const coarse = useCoarsePointer();\n\n const inputRef = React.useRef<HTMLInputElement>(null);\n const boxRef = React.useRef<HTMLDivElement>(null);\n const panelRef = React.useRef<HTMLDivElement>(null);\n const listRef = React.useRef<HTMLUListElement>(null);\n\n // ── value: the chosen option, with its own label ──\n const isControlled = valueProp !== undefined;\n const [inner, setInner] = React.useState<AutocompleteOption | null>(defaultValue ?? null);\n const value = isControlled ? valueProp : inner;\n const valueLabel = value?.label ?? '';\n\n // ── the text box: the chosen label, until the user types (`draft`) ──\n const [draft, setDraft] = React.useState<string | null>(null);\n const text = draft ?? valueLabel;\n const query = draft ?? '';\n\n const [open, setOpen] = React.useState(false);\n const [focused, setFocused] = React.useState(false);\n const [activeKey, setActiveKey] = React.useState<string | null>(null);\n // The active row is the chosen one only because the list opened on it, not because the user went\n // there: set by opening, cleared by the first thing the user does to the highlight.\n const activeFromOpen = React.useRef(false);\n const pick = (key: string | null) => {\n activeFromOpen.current = false;\n setActiveKey(key);\n };\n\n const visible = React.useMemo(() => narrow(options, filter, query), [options, filter, query]);\n const activeIndex = activeKey === null ? -1 : visible.findIndex((o) => o.value === activeKey && !o.disabled);\n const activeId = activeIndex >= 0 ? `${rid}-opt-${activeIndex}` : null;\n\n const rows = visible.length;\n const status = loading ? copy.loading : rows === 0 ? copy.empty : null;\n\n // ── open / close, told to the app once per change ──\n const onOpenChangeRef = useLatest(onOpenChange);\n const toldOpen = React.useRef(false);\n React.useEffect(() => {\n if (toldOpen.current === open) return;\n toldOpen.current = open;\n onOpenChangeRef.current?.(open);\n }, [open, onOpenChangeRef]);\n\n // ── search: told to the app when the query changes, debounced while typing ──\n const onSearchRef = useLatest(onSearch);\n const searchTimer = React.useRef<number | undefined>(undefined);\n const toldQuery = React.useRef('');\n React.useEffect(() => () => window.clearTimeout(searchTimer.current), []);\n const search = (q: string, immediate: boolean) => {\n window.clearTimeout(searchTimer.current);\n const run = () => {\n if (q === toldQuery.current) return;\n toldQuery.current = q;\n onSearchRef.current?.(q);\n };\n if (immediate) run();\n else searchTimer.current = window.setTimeout(run, debounce);\n };\n\n /** The box goes back to the chosen label: closes the list, drops what was typed, resets the query. */\n const settle = () => {\n setOpen(false);\n setDraft(null);\n search('', true);\n };\n\n const place = useMenuPlacement({\n open,\n anchorRef: boxRef,\n panelRef,\n itemCount: rows + (status ? 1 : 0),\n onDismiss: () => settle(),\n });\n // The chosen row can arrive after the list opened (a list that loads when it opens, on the page around\n // the chosen row). It is brought into view then, unless the user has already scrolled the list away\n // from the top: a user paging down for the next page is not carried off to a row that just landed.\n useRevealActive(open, activeId, place, revealInList, (el) => !activeFromOpen.current || (el.parentElement?.scrollTop ?? 0) === 0);\n\n // ── pagination: ask for more once the list is near its end ──\n const onReachEndRef = useLatest(onReachEnd);\n const askedFor = React.useRef<string | null>(null);\n // What the list is, for \"once per size\": a new search that happens to return as many rows is a new list.\n const shape = options.length + '|' + (options[0]?.value ?? '') + '|' + (options[options.length - 1]?.value ?? '');\n useIsoLayoutEffect(() => {\n if (!open) {\n askedFor.current = null;\n return;\n }\n const list = listRef.current;\n if (!list || rows === 0) return;\n const check = () => {\n if (loading || !onReachEndRef.current || askedFor.current === shape) return;\n const remaining = list.scrollHeight - list.scrollTop - list.clientHeight;\n if (remaining > (list.scrollHeight / rows) * REACH_ROWS) return;\n askedFor.current = shape;\n onReachEndRef.current();\n };\n check();\n list.addEventListener('scroll', check, { passive: true });\n return () => list.removeEventListener('scroll', check);\n }, [open, loading, shape, place, rows, onReachEndRef]);\n\n // A new search starts at the top.\n const firstValue = options[0]?.value;\n useIsoLayoutEffect(() => {\n if (draft !== null && listRef.current) listRef.current.scrollTop = 0;\n }, [draft, firstValue]);\n\n // iOS keeps the keyboard (and the field) up when you tap on plain page: close on any press outside.\n const settleRef = useLatest(settle);\n React.useEffect(() => {\n if (!open) return;\n const onDown = (e: PointerEvent) => {\n const target = e.target as Node;\n if (boxRef.current?.contains(target) || panelRef.current?.contains(target)) return;\n settleRef.current();\n };\n document.addEventListener('pointerdown', onDown, true);\n return () => document.removeEventListener('pointerdown', onDown, true);\n }, [open, settleRef]);\n\n // ── choosing ──\n const firstEnabledKey = () => visible.find((o) => !o.disabled)?.value ?? null;\n const lastEnabledKey = () => {\n for (let i = rows - 1; i >= 0; i--) if (!visible[i].disabled) return visible[i].value;\n return null;\n };\n const move = (dir: 1 | -1) => {\n let i = activeIndex < 0 ? (dir === 1 ? -1 : rows) : activeIndex;\n for (let step = 0; step < rows; step++) {\n i += dir;\n if (i < 0 || i >= rows) return; // the ends are walls, not a loop: a paged list has no \"wrap\"\n if (!visible[i].disabled) {\n pick(visible[i].value);\n return;\n }\n }\n };\n\n const choose = (o: AutocompleteOption) => {\n if (o.disabled) return;\n if (!isControlled) setInner(o);\n onValueChange?.(o);\n setOpen(false);\n setDraft(null);\n search('', true);\n // On a phone the keyboard goes with the choice.\n if (coarse) inputRef.current?.blur();\n };\n const clear = () => {\n if (value) {\n if (!isControlled) setInner(null);\n onValueChange?.(null);\n }\n setDraft(''); // empty at once, even if the app takes a moment to take the value away\n search('', true);\n inputRef.current?.focus();\n };\n\n const selectedKey = value?.value;\n // Opening starts on the chosen row. If it is not in the list *yet* because the list is empty (it\n // loads when it opens), it stays the active one so it is revealed when it arrives. With rows on screen\n // that do not include it, it is not chased: the list is not moved under the user later.\n const startKey = (fallback: string | null) =>\n selectedKey !== undefined && (rows === 0 || visible.some((o) => o.value === selectedKey)) ? selectedKey : fallback;\n const openFromPointer = () => {\n activeFromOpen.current = true;\n setActiveKey(startKey(null));\n setOpen(true);\n };\n const openFromKey = () => {\n activeFromOpen.current = true;\n setActiveKey(startKey(firstEnabledKey()));\n setOpen(true);\n };\n\n const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const next = e.currentTarget.value;\n setDraft(next);\n // Filtering here, the first match is ready for Enter. A server search has not answered yet:\n // an Enter now would pick a row of the old answer, so nothing is active until the user moves.\n pick(filter === false ? null : narrow(options, filter, next).find((o) => !o.disabled)?.value ?? null);\n setOpen(true);\n if (next === '' && clearable && value) {\n if (!isControlled) setInner(null);\n onValueChange?.(null);\n }\n search(next, false);\n };\n\n const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (disabled || e.nativeEvent.isComposing) return; // an IME is still composing the text\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n if (!open) openFromKey();\n else move(1);\n return;\n case 'ArrowUp':\n e.preventDefault();\n if (!open) openFromKey();\n else move(-1);\n return;\n case 'Home':\n case 'End':\n if (open) {\n e.preventDefault();\n pick(e.key === 'Home' ? firstEnabledKey() : lastEnabledKey());\n }\n return;\n case 'Enter':\n // Closed: let the form have its Enter. Open: it is for the list, never a submit.\n if (open) {\n e.preventDefault();\n if (activeIndex >= 0) choose(visible[activeIndex]);\n }\n return;\n case 'Escape':\n if (open) {\n e.preventDefault();\n // Only the list closes: a Dialog around the field keeps its own Esc for the next press.\n // (`stopImmediate...` too: React may listen on `document`, where the Dialog listens as well.)\n e.stopPropagation();\n e.nativeEvent.stopImmediatePropagation();\n settle();\n }\n return;\n default:\n }\n };\n\n // Select the text on the way in, so typing replaces the label instead of appending to it. The click\n // that gave the focus would put the caret back, hence the second select.\n const selectOnClick = React.useRef(false);\n\n const fieldAria = fieldA11y(rid, { hint, error, required });\n const rowPadY = menuRowPadY(coarse, size);\n const fontSize = size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)';\n const showClear = clearable && !disabled && text !== '';\n\n const list = (\n <div\n ref={panelRef}\n // Keeps the focus in the text box: pressing the list (or its scrollbar) must not blur it.\n onMouseDown={(e) => e.preventDefault()}\n style={sx({\n ...menuSurfaceStyle(size),\n display: 'flex',\n flexDirection: 'column',\n overflow: 'hidden',\n maxHeight: place?.maxH,\n ...(place?.strategy === 'fixed'\n ? {\n position: 'fixed',\n top: place.top,\n left: place.left,\n width: place.width,\n ...(place.above ? { transform: 'translateY(-100%)' } : null),\n zIndex: 1100,\n }\n : {\n position: 'absolute',\n left: 0,\n right: 0,\n ...(place?.above ? { bottom: 'calc(100% + 6px)' } : { top: 'calc(100% + 6px)' }),\n zIndex: 100,\n }),\n })}\n >\n <ul\n ref={listRef}\n id={listboxId}\n role=\"listbox\"\n aria-label={ariaLabel ?? label}\n aria-busy={loading || undefined}\n tabIndex={-1}\n style={sx({\n ...menuListStyle,\n position: 'relative', // so an option's offsetTop is measured from the list\n flex: '1 1 auto',\n minHeight: 0,\n padding: rows ? 'var(--space-1)' : 0,\n overscrollBehavior: 'contain', // don't chain the list's scroll to the page\n })}\n >\n {visible.map((o, i) => (\n <MenuOption\n key={o.value}\n id={`${rid}-opt-${i}`}\n label={o.label}\n selected={o.value === selectedKey}\n active={i === activeIndex}\n disabled={o.disabled}\n coarse={coarse}\n padY={rowPadY}\n // Pointer *move*, not enter: a list that scrolls under a still mouse (the keyboard\n // revealing a row) must not hand the highlight to whatever slid beneath it.\n onPointerMove={() => !o.disabled && pick(o.value)}\n onClick={() => choose(o)}\n />\n ))}\n </ul>\n {status && (\n // Loading is a lone spinner, no text and no rule above it: a screen reader gets the words from the\n // live region below, and this is for the eye. \"No results\" is the same row with words.\n <div\n aria-hidden=\"true\"\n style={sx({\n flex: '0 0 auto',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n minHeight: coarse ? 44 : undefined,\n padding: 'var(--space-3)',\n color: 'var(--text-muted)',\n fontSize: coarse ? 'var(--text-base)' : 'var(--text-sm)',\n })}\n >\n {loading ? (\n <span\n style={sx({\n flex: '0 0 auto',\n width: 18,\n height: 18,\n borderRadius: '999px',\n border: '2px solid var(--border-default)',\n borderTopColor: 'var(--text-brand)',\n animation: 'sereno-spin .7s linear infinite',\n })}\n />\n ) : (\n status\n )}\n </div>\n )}\n </div>\n );\n\n return (\n <Field label={label} hint={hint} error={error} required={required} requiredExposed htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <div style={sx({ position: 'relative', width: '100%' })}>\n <div\n ref={boxRef}\n // The padding around the text is part of the field: pressing it puts the caret in the box.\n onMouseDown={(e) => {\n if (e.target === inputRef.current || disabled) return;\n e.preventDefault();\n inputRef.current?.focus();\n }}\n style={sx({ ...fieldBoxStyle(size, !!error, focused || open, !!disabled), cursor: disabled ? 'not-allowed' : 'text' })}\n >\n <input\n ref={inputRef}\n id={rid}\n type=\"text\"\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-autocomplete=\"list\"\n aria-expanded={open}\n aria-controls={open ? listboxId : undefined}\n aria-activedescendant={open && activeId ? activeId : undefined}\n aria-label={ariaLabel}\n {...fieldAria}\n // A text box that looks like a name or an address draws the browser's autofill and the\n // password managers. Best effort: Chrome ignores `autoComplete=\"off\"`, and Bitwarden only\n // honors its attribute when the user turned that option on.\n autoComplete=\"off\"\n autoCorrect=\"off\"\n autoCapitalize=\"off\"\n spellCheck={false}\n enterKeyHint=\"done\"\n data-1p-ignore\n data-lpignore=\"true\"\n data-bwignore=\"true\"\n data-form-type=\"other\"\n disabled={disabled}\n placeholder={placeholder ?? copy.placeholder}\n value={text}\n onChange={onChange}\n onKeyDown={onKeyDown}\n onFocus={(e) => {\n setFocused(true);\n selectOnClick.current = true;\n e.currentTarget.select();\n }}\n onBlur={(e) => {\n setFocused(false);\n if (boxRef.current?.contains(e.relatedTarget as Node | null)) return;\n settle();\n }}\n onClick={(e) => {\n const el = e.currentTarget;\n if (selectOnClick.current && el.selectionStart === el.selectionEnd) el.select();\n selectOnClick.current = false;\n if (!open) openFromPointer();\n }}\n style={sx({\n flex: 1,\n minWidth: 0,\n margin: 0,\n padding: 0, // reset the UA input padding - the box's own padding insets it\n border: 'none',\n outline: 'none',\n background: 'transparent',\n fontFamily: 'var(--font-body)',\n fontSize,\n lineHeight: 1.2,\n textOverflow: 'ellipsis',\n color: disabled ? 'var(--text-disabled)' : 'var(--text-primary)',\n })}\n />\n {showClear && (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n tabIndex={-1}\n aria-label={copy.clear}\n onMouseDown={(e) => e.preventDefault()}\n onClick={clear}\n >\n <X size={16} strokeWidth={2} />\n </button>\n )}\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n tabIndex={-1}\n disabled={disabled}\n aria-label={open ? copy.close : copy.open}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => {\n inputRef.current?.focus({ preventScroll: true });\n if (open) settle();\n else openFromPointer();\n }}\n style={sx({\n transition: 'transform var(--duration-fast) var(--ease-standard)',\n transform: open ? 'rotate(180deg)' : 'none',\n })}\n >\n <ChevronDown size={16} strokeWidth={1.75} />\n </button>\n </div>\n\n {open && place && place.strategy === 'inline' && list}\n {open && place && place.strategy === 'fixed' && createPortal(list, document.body)}\n\n {/* Always rendered, so the change of its text is what a screen reader announces. */}\n <div role=\"status\" aria-live=\"polite\" style={srOnlyStyle}>\n {open ? (loading ? copy.loading : rows === 0 ? copy.empty : copy.results(rows)) : ''}\n </div>\n </div>\n {name && <input ref={ref} type=\"hidden\" name={name} value={value?.value ?? ''} />}\n </Field>\n );\n});\n\nAutocomplete.displayName = 'Autocomplete';\n"],"mappings":";AA2bI,SA6CM,KA7CN;AAzbJ,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,aAAa,SAAS;AAC/B,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,cAAc,uBAAuB;AAC9C,SAAS,YAAY,eAAe,aAAa,wBAAwB;AACzE,SAAS,qBAAqB;AA0B9B,MAAM,OAAmD;AAAA,EACvD,SAAS;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SAAS;AAAA,IACT,OAAO;AAAA,IACP,SAAS,CAAC,MAAO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AAAA,gBACV,UAAU;AAAA,gBACV;AAAA,gBACA,cAAY,OAAO,KAAK,QAAQ,KAAK;AAAA,gBACrC,aAAa,CAAC,MAAM,EAAE,eAAe;AAAA,gBACrC,SAAS,MAAM;AACb,2BAAS,SAAS,MAAM,EAAE,eAAe,KAAK,CAAC;AAC/C,sBAAI,KAAM,QAAO;AAAA,sBACZ,iBAAgB;AAAA,gBACvB;AAAA,gBACA,OAAO,GAAG;AAAA,kBACR,YAAY;AAAA,kBACZ,WAAW,OAAO,mBAAmB;AAAA,gBACvC,CAAC;AAAA,gBAED,8BAAC,eAAY,MAAM,IAAI,aAAa,MAAM;AAAA;AAAA,YAC5C;AAAA;AAAA;AAAA,MACF;AAAA,MAEC,QAAQ,SAAS,MAAM,aAAa,YAAY;AAAA,MAChD,QAAQ,SAAS,MAAM,aAAa,WAAW,aAAa,MAAM,SAAS,IAAI;AAAA,MAGhF,oBAAC,SAAI,MAAK,UAAS,aAAU,UAAS,OAAO,aAC1C,iBAAQ,UAAU,KAAK,UAAU,SAAS,IAAI,KAAK,QAAQ,KAAK,QAAQ,IAAI,IAAK,IACpF;AAAA,OACF;AAAA,IACC,QAAQ,oBAAC,WAAM,KAAU,MAAK,UAAS,MAAY,OAAO,OAAO,SAAS,IAAI;AAAA,KACjF;AAEJ,CAAC;AAED,aAAa,cAAc;","names":["Autocomplete","list"]}
|
|
1
|
+
{"version":3,"sources":["../../src/forms/Autocomplete.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { ChevronDown, X } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { srOnlyStyle } from '../_internal/srOnly';\nimport { Field } from '../_internal/Field';\nimport { fieldA11y } from '../_internal/fieldA11y';\nimport { useIsoLayoutEffect } from '../_internal/useIsoLayoutEffect';\nimport { useLatest } from '../_internal/useLatest';\nimport { useCoarsePointer } from '../_internal/useCoarsePointer';\nimport { useMenuPlacement } from '../_internal/useMenuPlacement';\nimport { useOutsidePress } from '../_internal/useOutsidePress';\nimport { revealInList, useRevealActive } from '../_internal/useRevealActive';\nimport { MenuOption, menuListStyle, menuRowPadY, menuSurfaceStyle } from '../_internal/MenuOption';\nimport { fieldBoxStyle } from './_internal/fieldBoxStyle';\n\nexport interface AutocompleteOption {\n value: string;\n label: string;\n disabled?: boolean;\n}\n\n/** Every string the component says. Defaults come from `locale`; pass `labels` to change some. */\nexport interface AutocompleteLabels {\n /** Placeholder of the text box while nothing is chosen. */\n placeholder: string;\n /** aria-label of the clear (×) button. */\n clear: string;\n /** aria-label of the chevron button while the list is closed. */\n open: string;\n /** aria-label of the chevron button while the list is open. */\n close: string;\n /** What a screen reader hears while `loading` (the list itself shows only a spinner). */\n loading: string;\n /** The row shown when no option is left to show. */\n empty: string;\n /** What a screen reader hears when the list changes size. */\n results: (count: number) => string;\n}\n\nconst TEXT: Record<'pt-BR' | 'en', AutocompleteLabels> = {\n 'pt-BR': {\n placeholder: 'Buscar…',\n clear: 'Limpar seleção',\n open: 'Abrir lista',\n close: 'Fechar lista',\n loading: 'Carregando…',\n empty: 'Nenhum resultado',\n results: (n) => (n === 1 ? '1 resultado' : n + ' resultados'),\n },\n en: {\n placeholder: 'Search…',\n clear: 'Clear selection',\n open: 'Open list',\n close: 'Close list',\n loading: 'Loading…',\n empty: 'No results',\n results: (n) => (n === 1 ? '1 result' : n + ' results'),\n },\n};\n\n/**\n * Single choice from a list you search by typing. Like `Select`, but the box is a text field: type\n * to narrow the list, pick one row, and the value is that row. For a list too long to scroll\n * (past ~12 options), or one the server searches and pages (a thousand clients, fifty at a time).\n *\n * The value is the chosen option itself, `{ value, label }`, and it carries its own label. The\n * box shows `value.label` whether or not that option is in `options` right now, which is what\n * keeps the label when the page it came from is no longer loaded. `options` is only what the list\n * shows. `onValueChange` gives the option (or `null` when cleared), not a string.\n *\n * Two kinds of search, one prop apart:\n * - the default filters `options` itself, as you type (case and accents ignored);\n * - `filter={false}` leaves the list alone and tells you what was typed (`onSearch`, debounced),\n * for a list the server already filtered.\n *\n * It is a text box, not free text: what is typed never becomes the value. Leaving the box puts the\n * chosen label back.\n */\nexport interface AutocompleteProps {\n label?: string;\n hint?: string;\n /** Error message; also turns the control red. */\n error?: string;\n required?: boolean;\n /** What the list shows now. Appending rows while it is open is fine: the list keeps its scroll. */\n options?: AutocompleteOption[];\n /** Controlled value: the chosen option, or `null` for none. */\n value?: AutocompleteOption | null;\n /** Uncontrolled initial value. */\n defaultValue?: AutocompleteOption | null;\n /** The chosen option, or `null` when the value is cleared. */\n onValueChange?: (option: AutocompleteOption | null) => void;\n /**\n * How typing narrows `options`. `true` (default): keep the rows whose label contains the text,\n * ignoring case and accents. `false`: show `options` as they are (the server did the filtering).\n * A function decides per row.\n */\n filter?: boolean | ((option: AutocompleteOption, query: string) => boolean);\n /**\n * The text to search for changed: fired as the user types (after `debounce`) and with `''` once\n * the box goes back to showing the chosen label (pick, clear, leave, Esc). Never with the label\n * itself, so it is safe to run the query here. Use it with `filter={false}`.\n */\n onSearch?: (query: string) => void;\n /** Debounce for `onSearch` while typing, in ms. */\n debounce?: number;\n /** The list is waiting for rows: a spinner under them (or alone), the list marked busy, and a screen reader told. */\n loading?: boolean;\n /**\n * The list was scrolled to within about five rows of its end. Fires once per list size, never\n * while `loading`. Pass it only while there is a next page, so a list that is complete asks for nothing.\n */\n onReachEnd?: () => void;\n /** The list opened or closed. For a list that loads when it opens. */\n onOpenChange?: (open: boolean) => void;\n /** A × button, and an emptied box clears the value. */\n clearable?: boolean;\n /** Shown in muted text while nothing is chosen. Defaults to the `locale` text. */\n placeholder?: string;\n size?: 'sm' | 'md' | 'lg';\n disabled?: boolean;\n /** Form field name - mirrored to a hidden input so the chosen value can be submitted. */\n name?: string;\n id?: string;\n containerStyle?: React.CSSProperties;\n /**\n * Accessible name for the text box. Only needed when there's no visible `label`. Takes\n * precedence over `label` if both are set - don't pass both.\n */\n 'aria-label'?: string;\n /** Reserve the hint/error row's height even with neither set - stops the field from growing\n * the moment a validation message appears. */\n preserveHelperSpace?: boolean;\n /** Language of the built-in texts. */\n locale?: 'pt-BR' | 'en';\n /** Override any built-in text. */\n labels?: Partial<AutocompleteLabels>;\n}\n\n/** How close to the end of the list, in rows, `onReachEnd` fires. */\nconst REACH_ROWS = 5;\n\nconst MARKS = /[̀-ͯ]/g;\nconst plain = (s: string) => s.normalize('NFD').replace(MARKS, '').toLowerCase();\n\nfunction narrow(\n options: AutocompleteOption[],\n filter: AutocompleteProps['filter'],\n query: string,\n): AutocompleteOption[] {\n if (filter === false) return options;\n const q = query.trim();\n if (!q) return options;\n if (typeof filter === 'function') return options.filter((o) => filter(o, query));\n const needle = plain(q);\n return options.filter((o) => plain(o.label).includes(needle));\n}\n\n/**\n * `ref` reaches the hidden `<input type=\"hidden\">` that mirrors the chosen value (rendered only\n * when `name` is set - pass it, as `register()` does), the same as `Select`. A plain\n * `{...register(name)}` spread still won't validate on change: wire it through `Controller`, or\n * call the registered `onChange` yourself from `onValueChange`.\n */\nexport const Autocomplete = React.forwardRef<HTMLInputElement, AutocompleteProps>(function Autocomplete(\n {\n label,\n hint,\n error,\n required,\n options = [],\n value: valueProp,\n defaultValue,\n onValueChange,\n filter = true,\n onSearch,\n debounce = 250,\n loading = false,\n onReachEnd,\n onOpenChange,\n clearable = true,\n placeholder,\n size = 'md',\n disabled,\n name,\n id,\n containerStyle,\n 'aria-label': ariaLabel,\n preserveHelperSpace,\n locale = 'pt-BR',\n labels,\n },\n ref,\n) {\n const reactId = React.useId();\n const rid = id || reactId;\n const listboxId = `${rid}-listbox`;\n const copy: AutocompleteLabels = { ...TEXT[locale], ...labels };\n const coarse = useCoarsePointer();\n\n const inputRef = React.useRef<HTMLInputElement>(null);\n const boxRef = React.useRef<HTMLDivElement>(null);\n const panelRef = React.useRef<HTMLDivElement>(null);\n const listRef = React.useRef<HTMLUListElement>(null);\n\n // ── value: the chosen option, with its own label ──\n const isControlled = valueProp !== undefined;\n const [inner, setInner] = React.useState<AutocompleteOption | null>(defaultValue ?? null);\n const value = isControlled ? valueProp : inner;\n const valueLabel = value?.label ?? '';\n\n // ── the text box: the chosen label, until the user types (`draft`) ──\n const [draft, setDraft] = React.useState<string | null>(null);\n const text = draft ?? valueLabel;\n const query = draft ?? '';\n\n const [open, setOpen] = React.useState(false);\n const [focused, setFocused] = React.useState(false);\n const [activeKey, setActiveKey] = React.useState<string | null>(null);\n // The active row is the chosen one only because the list opened on it, not because the user went\n // there: set by opening, cleared by the first thing the user does to the highlight.\n const activeFromOpen = React.useRef(false);\n const pick = (key: string | null) => {\n activeFromOpen.current = false;\n setActiveKey(key);\n };\n\n const visible = React.useMemo(() => narrow(options, filter, query), [options, filter, query]);\n const activeIndex = activeKey === null ? -1 : visible.findIndex((o) => o.value === activeKey && !o.disabled);\n const activeId = activeIndex >= 0 ? `${rid}-opt-${activeIndex}` : null;\n\n const rows = visible.length;\n const status = loading ? copy.loading : rows === 0 ? copy.empty : null;\n\n // ── open / close, told to the app once per change ──\n const onOpenChangeRef = useLatest(onOpenChange);\n const toldOpen = React.useRef(false);\n React.useEffect(() => {\n if (toldOpen.current === open) return;\n toldOpen.current = open;\n onOpenChangeRef.current?.(open);\n }, [open, onOpenChangeRef]);\n\n // ── search: told to the app when the query changes, debounced while typing ──\n const onSearchRef = useLatest(onSearch);\n const searchTimer = React.useRef<number | undefined>(undefined);\n const toldQuery = React.useRef('');\n React.useEffect(() => () => window.clearTimeout(searchTimer.current), []);\n const search = (q: string, immediate: boolean) => {\n window.clearTimeout(searchTimer.current);\n const run = () => {\n if (q === toldQuery.current) return;\n toldQuery.current = q;\n onSearchRef.current?.(q);\n };\n if (immediate) run();\n else searchTimer.current = window.setTimeout(run, debounce);\n };\n\n /** The box goes back to the chosen label: closes the list, drops what was typed, resets the query. */\n const settle = () => {\n setOpen(false);\n setDraft(null);\n search('', true);\n };\n\n const place = useMenuPlacement({\n open,\n anchorRef: boxRef,\n panelRef,\n itemCount: rows + (status ? 1 : 0),\n onDismiss: () => settle(),\n });\n // The chosen row can arrive after the list opened (a list that loads when it opens, on the page around\n // the chosen row). It is brought into view then, unless the user has already scrolled the list away\n // from the top: a user paging down for the next page is not carried off to a row that just landed.\n useRevealActive(open, activeId, place, revealInList, (el) => !activeFromOpen.current || (el.parentElement?.scrollTop ?? 0) === 0);\n\n // ── pagination: ask for more once the list is near its end ──\n const onReachEndRef = useLatest(onReachEnd);\n const askedFor = React.useRef<string | null>(null);\n // What the list is, for \"once per size\": a new search that happens to return as many rows is a new list.\n const shape = options.length + '|' + (options[0]?.value ?? '') + '|' + (options[options.length - 1]?.value ?? '');\n useIsoLayoutEffect(() => {\n if (!open) {\n askedFor.current = null;\n return;\n }\n const list = listRef.current;\n if (!list || rows === 0) return;\n const check = () => {\n if (loading || !onReachEndRef.current || askedFor.current === shape) return;\n const remaining = list.scrollHeight - list.scrollTop - list.clientHeight;\n if (remaining > (list.scrollHeight / rows) * REACH_ROWS) return;\n askedFor.current = shape;\n onReachEndRef.current();\n };\n check();\n list.addEventListener('scroll', check, { passive: true });\n return () => list.removeEventListener('scroll', check);\n }, [open, loading, shape, place, rows, onReachEndRef]);\n\n // A new search starts at the top.\n const firstValue = options[0]?.value;\n useIsoLayoutEffect(() => {\n if (draft !== null && listRef.current) listRef.current.scrollTop = 0;\n }, [draft, firstValue]);\n\n // iOS keeps the keyboard (and the field) up when you tap on plain page: close on any press outside.\n useOutsidePress(open, [boxRef, panelRef], () => settle());\n\n // ── choosing ──\n const firstEnabledKey = () => visible.find((o) => !o.disabled)?.value ?? null;\n const lastEnabledKey = () => {\n for (let i = rows - 1; i >= 0; i--) if (!visible[i].disabled) return visible[i].value;\n return null;\n };\n const move = (dir: 1 | -1) => {\n let i = activeIndex < 0 ? (dir === 1 ? -1 : rows) : activeIndex;\n for (let step = 0; step < rows; step++) {\n i += dir;\n if (i < 0 || i >= rows) return; // the ends are walls, not a loop: a paged list has no \"wrap\"\n if (!visible[i].disabled) {\n pick(visible[i].value);\n return;\n }\n }\n };\n\n const choose = (o: AutocompleteOption) => {\n if (o.disabled) return;\n if (!isControlled) setInner(o);\n onValueChange?.(o);\n setOpen(false);\n setDraft(null);\n search('', true);\n // On a phone the keyboard goes with the choice.\n if (coarse) inputRef.current?.blur();\n };\n const clear = () => {\n if (value) {\n if (!isControlled) setInner(null);\n onValueChange?.(null);\n }\n setDraft(''); // empty at once, even if the app takes a moment to take the value away\n search('', true);\n inputRef.current?.focus();\n };\n\n const selectedKey = value?.value;\n // Opening starts on the chosen row. If it is not in the list *yet* because the list is empty (it\n // loads when it opens), it stays the active one so it is revealed when it arrives. With rows on screen\n // that do not include it, it is not chased: the list is not moved under the user later.\n const startKey = (fallback: string | null) =>\n selectedKey !== undefined && (rows === 0 || visible.some((o) => o.value === selectedKey)) ? selectedKey : fallback;\n const openFromPointer = () => {\n activeFromOpen.current = true;\n setActiveKey(startKey(null));\n setOpen(true);\n };\n const openFromKey = () => {\n activeFromOpen.current = true;\n setActiveKey(startKey(firstEnabledKey()));\n setOpen(true);\n };\n\n const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const next = e.currentTarget.value;\n setDraft(next);\n // Filtering here, the first match is ready for Enter. A server search has not answered yet:\n // an Enter now would pick a row of the old answer, so nothing is active until the user moves.\n pick(filter === false ? null : narrow(options, filter, next).find((o) => !o.disabled)?.value ?? null);\n setOpen(true);\n if (next === '' && clearable && value) {\n if (!isControlled) setInner(null);\n onValueChange?.(null);\n }\n search(next, false);\n };\n\n const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {\n if (disabled || e.nativeEvent.isComposing) return; // an IME is still composing the text\n switch (e.key) {\n case 'ArrowDown':\n e.preventDefault();\n if (!open) openFromKey();\n else move(1);\n return;\n case 'ArrowUp':\n e.preventDefault();\n if (!open) openFromKey();\n else move(-1);\n return;\n case 'Home':\n case 'End':\n if (open) {\n e.preventDefault();\n pick(e.key === 'Home' ? firstEnabledKey() : lastEnabledKey());\n }\n return;\n case 'Enter':\n // Closed: let the form have its Enter. Open: it is for the list, never a submit.\n if (open) {\n e.preventDefault();\n if (activeIndex >= 0) choose(visible[activeIndex]);\n }\n return;\n case 'Escape':\n if (open) {\n e.preventDefault();\n // Only the list closes: a Dialog around the field keeps its own Esc for the next press.\n // (`stopImmediate...` too: React may listen on `document`, where the Dialog listens as well.)\n e.stopPropagation();\n e.nativeEvent.stopImmediatePropagation();\n settle();\n }\n return;\n default:\n }\n };\n\n // Select the text on the way in, so typing replaces the label instead of appending to it. The click\n // that gave the focus would put the caret back, hence the second select.\n const selectOnClick = React.useRef(false);\n\n const fieldAria = fieldA11y(rid, { hint, error, required });\n const rowPadY = menuRowPadY(coarse, size);\n const fontSize = size === 'sm' ? 'var(--text-sm)' : 'var(--text-base)';\n const showClear = clearable && !disabled && text !== '';\n\n const list = (\n <div\n ref={panelRef}\n // Keeps the focus in the text box: pressing the list (or its scrollbar) must not blur it.\n onMouseDown={(e) => e.preventDefault()}\n style={sx({\n ...menuSurfaceStyle(size),\n display: 'flex',\n flexDirection: 'column',\n overflow: 'hidden',\n maxHeight: place?.maxH,\n ...(place?.strategy === 'fixed'\n ? {\n position: 'fixed',\n top: place.top,\n left: place.left,\n width: place.width,\n ...(place.above ? { transform: 'translateY(-100%)' } : null),\n zIndex: 1100,\n }\n : {\n position: 'absolute',\n left: 0,\n right: 0,\n ...(place?.above ? { bottom: 'calc(100% + 6px)' } : { top: 'calc(100% + 6px)' }),\n zIndex: 100,\n }),\n })}\n >\n <ul\n ref={listRef}\n id={listboxId}\n role=\"listbox\"\n aria-label={ariaLabel ?? label}\n aria-busy={loading || undefined}\n tabIndex={-1}\n style={sx({\n ...menuListStyle,\n position: 'relative', // so an option's offsetTop is measured from the list\n flex: '1 1 auto',\n minHeight: 0,\n padding: rows ? 'var(--space-1)' : 0,\n overscrollBehavior: 'contain', // don't chain the list's scroll to the page\n })}\n >\n {visible.map((o, i) => (\n <MenuOption\n key={o.value}\n id={`${rid}-opt-${i}`}\n label={o.label}\n selected={o.value === selectedKey}\n active={i === activeIndex}\n disabled={o.disabled}\n coarse={coarse}\n padY={rowPadY}\n // Pointer *move*, not enter: a list that scrolls under a still mouse (the keyboard\n // revealing a row) must not hand the highlight to whatever slid beneath it.\n onPointerMove={() => !o.disabled && pick(o.value)}\n onClick={() => choose(o)}\n />\n ))}\n </ul>\n {status && (\n // Loading is a lone spinner, no text and no rule above it: a screen reader gets the words from the\n // live region below, and this is for the eye. \"No results\" is the same row with words.\n <div\n aria-hidden=\"true\"\n style={sx({\n flex: '0 0 auto',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n minHeight: coarse ? 44 : undefined,\n padding: 'var(--space-3)',\n color: 'var(--text-muted)',\n fontSize: coarse ? 'var(--text-base)' : 'var(--text-sm)',\n })}\n >\n {loading ? (\n <span\n style={sx({\n flex: '0 0 auto',\n width: 18,\n height: 18,\n borderRadius: '999px',\n border: '2px solid var(--border-default)',\n borderTopColor: 'var(--text-brand)',\n animation: 'sereno-spin .7s linear infinite',\n })}\n />\n ) : (\n status\n )}\n </div>\n )}\n </div>\n );\n\n return (\n <Field label={label} hint={hint} error={error} required={required} requiredExposed htmlFor={rid} style={containerStyle} preserveHelperSpace={preserveHelperSpace}>\n <div style={sx({ position: 'relative', width: '100%' })}>\n <div\n ref={boxRef}\n // The padding around the text is part of the field: pressing it puts the caret in the box.\n onMouseDown={(e) => {\n if (e.target === inputRef.current || disabled) return;\n e.preventDefault();\n inputRef.current?.focus();\n }}\n style={sx({ ...fieldBoxStyle(size, !!error, focused || open, !!disabled), cursor: disabled ? 'not-allowed' : 'text' })}\n >\n <input\n ref={inputRef}\n id={rid}\n type=\"text\"\n role=\"combobox\"\n aria-haspopup=\"listbox\"\n aria-autocomplete=\"list\"\n aria-expanded={open}\n aria-controls={open ? listboxId : undefined}\n aria-activedescendant={open && activeId ? activeId : undefined}\n aria-label={ariaLabel}\n {...fieldAria}\n // A text box that looks like a name or an address draws the browser's autofill and the\n // password managers. Best effort: Chrome ignores `autoComplete=\"off\"`, and Bitwarden only\n // honors its attribute when the user turned that option on.\n autoComplete=\"off\"\n autoCorrect=\"off\"\n autoCapitalize=\"off\"\n spellCheck={false}\n enterKeyHint=\"done\"\n data-1p-ignore\n data-lpignore=\"true\"\n data-bwignore=\"true\"\n data-form-type=\"other\"\n disabled={disabled}\n placeholder={placeholder ?? copy.placeholder}\n value={text}\n onChange={onChange}\n onKeyDown={onKeyDown}\n onFocus={(e) => {\n setFocused(true);\n selectOnClick.current = true;\n e.currentTarget.select();\n }}\n onBlur={(e) => {\n setFocused(false);\n if (boxRef.current?.contains(e.relatedTarget as Node | null)) return;\n settle();\n }}\n onClick={(e) => {\n const el = e.currentTarget;\n if (selectOnClick.current && el.selectionStart === el.selectionEnd) el.select();\n selectOnClick.current = false;\n if (!open) openFromPointer();\n }}\n style={sx({\n flex: 1,\n minWidth: 0,\n margin: 0,\n padding: 0, // reset the UA input padding - the box's own padding insets it\n border: 'none',\n outline: 'none',\n background: 'transparent',\n fontFamily: 'var(--font-body)',\n fontSize,\n lineHeight: 1.2,\n textOverflow: 'ellipsis',\n color: disabled ? 'var(--text-disabled)' : 'var(--text-primary)',\n })}\n />\n {showClear && (\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n tabIndex={-1}\n aria-label={copy.clear}\n onMouseDown={(e) => e.preventDefault()}\n onClick={clear}\n >\n <X size={16} strokeWidth={2} />\n </button>\n )}\n <button\n type=\"button\"\n className=\"ds-affix-btn\"\n tabIndex={-1}\n disabled={disabled}\n aria-label={open ? copy.close : copy.open}\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => {\n inputRef.current?.focus({ preventScroll: true });\n if (open) settle();\n else openFromPointer();\n }}\n style={sx({\n transition: 'transform var(--duration-fast) var(--ease-standard)',\n transform: open ? 'rotate(180deg)' : 'none',\n })}\n >\n <ChevronDown size={16} strokeWidth={1.75} />\n </button>\n </div>\n\n {open && place && place.strategy === 'inline' && list}\n {open && place && place.strategy === 'fixed' && createPortal(list, document.body)}\n\n {/* Always rendered, so the change of its text is what a screen reader announces. */}\n <div role=\"status\" aria-live=\"polite\" style={srOnlyStyle}>\n {open ? (loading ? copy.loading : rows === 0 ? copy.empty : copy.results(rows)) : ''}\n </div>\n </div>\n {name && <input ref={ref} type=\"hidden\" name={name} value={value?.value ?? ''} />}\n </Field>\n );\n});\n\nAutocomplete.displayName = 'Autocomplete';\n"],"mappings":";AAkbI,SA6CM,KA7CN;AAhbJ,YAAY,WAAW;AACvB,SAAS,oBAAoB;AAC7B,SAAS,aAAa,SAAS;AAC/B,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAC5B,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,0BAA0B;AACnC,SAAS,iBAAiB;AAC1B,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,cAAc,uBAAuB;AAC9C,SAAS,YAAY,eAAe,aAAa,wBAAwB;AACzE,SAAS,qBAAqB;AA0B9B,MAAM,OAAmD;AAAA,EACvD,SAAS;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SAAS;AAAA,IACT,OAAO;AAAA,IACP,SAAS,CAAC,MAAO,MAAM,IAAI,gBAAgB,IAAI;AAAA,EACjD;AAAA,EACA,IAAI;AAAA,IACF,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,IACN,OAAO;AAAA,IACP,SAAS;AAAA,IACT,OAAO;AAAA,IACP,SAAS,CAAC,MAAO,MAAM,IAAI,aAAa,IAAI;AAAA,EAC9C;AACF;AAkFA,MAAM,aAAa;AAEnB,MAAM,QAAQ;AACd,MAAM,QAAQ,CAAC,MAAc,EAAE,UAAU,KAAK,EAAE,QAAQ,OAAO,EAAE,EAAE,YAAY;AAE/E,SAAS,OACP,SACA,QACA,OACsB;AACtB,MAAI,WAAW,MAAO,QAAO;AAC7B,QAAM,IAAI,MAAM,KAAK;AACrB,MAAI,CAAC,EAAG,QAAO;AACf,MAAI,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