@mortenbrudvik/waveui 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +274 -24
  2. package/dist/components/data-display/List.cjs +1 -1
  3. package/dist/components/data-display/List.cjs.map +1 -1
  4. package/dist/components/data-display/List.mjs +405 -219
  5. package/dist/components/data-display/List.mjs.map +1 -1
  6. package/dist/components/data-display/List.registry.cjs +1 -1
  7. package/dist/components/data-display/List.registry.cjs.map +1 -1
  8. package/dist/components/data-display/List.registry.mjs +12 -6
  9. package/dist/components/data-display/List.registry.mjs.map +1 -1
  10. package/dist/components/input/Combobox.cjs +1 -1
  11. package/dist/components/input/Combobox.cjs.map +1 -1
  12. package/dist/components/input/Combobox.mjs +163 -148
  13. package/dist/components/input/Combobox.mjs.map +1 -1
  14. package/dist/components/input/Dropdown.cjs +1 -1
  15. package/dist/components/input/Dropdown.cjs.map +1 -1
  16. package/dist/components/input/Dropdown.mjs +132 -117
  17. package/dist/components/input/Dropdown.mjs.map +1 -1
  18. package/dist/components/input/Listbox.cjs +1 -1
  19. package/dist/components/input/Listbox.cjs.map +1 -1
  20. package/dist/components/input/Listbox.mjs +90 -78
  21. package/dist/components/input/Listbox.mjs.map +1 -1
  22. package/dist/components/input/Option.cjs +1 -1
  23. package/dist/components/input/Option.cjs.map +1 -1
  24. package/dist/components/input/Option.data.cjs +2 -0
  25. package/dist/components/input/Option.data.cjs.map +1 -0
  26. package/dist/components/input/Option.data.mjs +114 -0
  27. package/dist/components/input/Option.data.mjs.map +1 -0
  28. package/dist/components/input/Option.mjs +21 -17
  29. package/dist/components/input/Option.mjs.map +1 -1
  30. package/dist/components/layout/FlatTree.cjs +2 -0
  31. package/dist/components/layout/FlatTree.cjs.map +1 -0
  32. package/dist/components/layout/FlatTree.context.cjs +2 -0
  33. package/dist/components/layout/FlatTree.context.cjs.map +1 -0
  34. package/dist/components/layout/FlatTree.context.mjs +20 -0
  35. package/dist/components/layout/FlatTree.context.mjs.map +1 -0
  36. package/dist/components/layout/FlatTree.item.cjs +2 -0
  37. package/dist/components/layout/FlatTree.item.cjs.map +1 -0
  38. package/dist/components/layout/FlatTree.item.mjs +90 -0
  39. package/dist/components/layout/FlatTree.item.mjs.map +1 -0
  40. package/dist/components/layout/FlatTree.mjs +276 -0
  41. package/dist/components/layout/FlatTree.mjs.map +1 -0
  42. package/dist/components/layout/Tree.core.cjs +1 -1
  43. package/dist/components/layout/Tree.core.cjs.map +1 -1
  44. package/dist/components/layout/Tree.core.mjs +166 -165
  45. package/dist/components/layout/Tree.core.mjs.map +1 -1
  46. package/dist/components/layout/Tree.selection.cjs +1 -1
  47. package/dist/components/layout/Tree.selection.cjs.map +1 -1
  48. package/dist/components/layout/Tree.selection.mjs +11 -57
  49. package/dist/components/layout/Tree.selection.mjs.map +1 -1
  50. package/dist/components/layout/useFlatTree.cjs +2 -0
  51. package/dist/components/layout/useFlatTree.cjs.map +1 -0
  52. package/dist/components/layout/useFlatTree.mjs +83 -0
  53. package/dist/components/layout/useFlatTree.mjs.map +1 -0
  54. package/dist/components/table/DataGrid.cjs +1 -1
  55. package/dist/components/table/DataGrid.cjs.map +1 -1
  56. package/dist/components/table/DataGrid.context.cjs +2 -0
  57. package/dist/components/table/DataGrid.context.cjs.map +1 -0
  58. package/dist/components/table/DataGrid.context.mjs +74 -0
  59. package/dist/components/table/DataGrid.context.mjs.map +1 -0
  60. package/dist/components/table/DataGrid.header.cjs +2 -0
  61. package/dist/components/table/DataGrid.header.cjs.map +1 -0
  62. package/dist/components/table/DataGrid.header.mjs +168 -0
  63. package/dist/components/table/DataGrid.header.mjs.map +1 -0
  64. package/dist/components/table/DataGrid.mjs +488 -591
  65. package/dist/components/table/DataGrid.mjs.map +1 -1
  66. package/dist/components/table/DataGrid.sizing.cjs +2 -0
  67. package/dist/components/table/DataGrid.sizing.cjs.map +1 -0
  68. package/dist/components/table/DataGrid.sizing.mjs +187 -0
  69. package/dist/components/table/DataGrid.sizing.mjs.map +1 -0
  70. package/dist/components/table/DataGrid.store.cjs +2 -0
  71. package/dist/components/table/DataGrid.store.cjs.map +1 -0
  72. package/dist/components/table/DataGrid.store.mjs +108 -0
  73. package/dist/components/table/DataGrid.store.mjs.map +1 -0
  74. package/dist/components/table/DataGrid.window.cjs +2 -0
  75. package/dist/components/table/DataGrid.window.cjs.map +1 -0
  76. package/dist/components/table/DataGrid.window.mjs +165 -0
  77. package/dist/components/table/DataGrid.window.mjs.map +1 -0
  78. package/dist/components/table/Table.cjs +1 -1
  79. package/dist/components/table/Table.cjs.map +1 -1
  80. package/dist/components/table/Table.mjs +74 -72
  81. package/dist/components/table/Table.mjs.map +1 -1
  82. package/dist/components/table/Table.resize.cjs +2 -0
  83. package/dist/components/table/Table.resize.cjs.map +1 -0
  84. package/dist/components/table/Table.resize.mjs +98 -0
  85. package/dist/components/table/Table.resize.mjs.map +1 -0
  86. package/dist/components/table/useGridNavigation.cjs +1 -1
  87. package/dist/components/table/useGridNavigation.cjs.map +1 -1
  88. package/dist/components/table/useGridNavigation.mjs +343 -140
  89. package/dist/components/table/useGridNavigation.mjs.map +1 -1
  90. package/dist/components/table/useTableColumnSizing.cjs +2 -0
  91. package/dist/components/table/useTableColumnSizing.cjs.map +1 -0
  92. package/dist/components/table/useTableColumnSizing.mjs +76 -0
  93. package/dist/components/table/useTableColumnSizing.mjs.map +1 -0
  94. package/dist/components/table/useTableFeatures.cjs +2 -0
  95. package/dist/components/table/useTableFeatures.cjs.map +1 -0
  96. package/dist/components/table/useTableFeatures.mjs +110 -0
  97. package/dist/components/table/useTableFeatures.mjs.map +1 -0
  98. package/dist/components/table/useTableSelection.cjs +2 -0
  99. package/dist/components/table/useTableSelection.cjs.map +1 -0
  100. package/dist/components/table/useTableSelection.mjs +39 -0
  101. package/dist/components/table/useTableSelection.mjs.map +1 -0
  102. package/dist/components/table/useTableSort.cjs +2 -0
  103. package/dist/components/table/useTableSort.cjs.map +1 -0
  104. package/dist/components/table/useTableSort.mjs +58 -0
  105. package/dist/components/table/useTableSort.mjs.map +1 -0
  106. package/dist/hooks/useActiveDescendant.cjs +1 -1
  107. package/dist/hooks/useActiveDescendant.cjs.map +1 -1
  108. package/dist/hooks/useActiveDescendant.mjs +33 -25
  109. package/dist/hooks/useActiveDescendant.mjs.map +1 -1
  110. package/dist/hooks/useListbox.cjs +1 -1
  111. package/dist/hooks/useListbox.cjs.map +1 -1
  112. package/dist/hooks/useListbox.mjs +140 -130
  113. package/dist/hooks/useListbox.mjs.map +1 -1
  114. package/dist/hooks/useRovingTabIndex.cjs +1 -1
  115. package/dist/hooks/useRovingTabIndex.cjs.map +1 -1
  116. package/dist/hooks/useRovingTabIndex.mjs +1 -1
  117. package/dist/hooks/useRovingTabIndex.mjs.map +1 -1
  118. package/dist/hooks/useSelection.cjs +2 -0
  119. package/dist/hooks/useSelection.cjs.map +1 -0
  120. package/dist/hooks/useSelection.mjs +57 -0
  121. package/dist/hooks/useSelection.mjs.map +1 -0
  122. package/dist/hooks/useVirtualWindow.cjs +2 -0
  123. package/dist/hooks/useVirtualWindow.cjs.map +1 -0
  124. package/dist/hooks/useVirtualWindow.mjs +102 -0
  125. package/dist/hooks/useVirtualWindow.mjs.map +1 -0
  126. package/dist/index.cjs +1 -1
  127. package/dist/index.d.cts +1542 -53
  128. package/dist/index.d.ts +1542 -53
  129. package/dist/index.mjs +147 -136
  130. package/dist/lib/classNames.cjs +1 -1
  131. package/dist/lib/classNames.cjs.map +1 -1
  132. package/dist/lib/classNames.mjs +68 -49
  133. package/dist/lib/classNames.mjs.map +1 -1
  134. package/dist/lib/columnSizing.cjs +2 -0
  135. package/dist/lib/columnSizing.cjs.map +1 -0
  136. package/dist/lib/columnSizing.mjs +27 -0
  137. package/dist/lib/columnSizing.mjs.map +1 -0
  138. package/dist/lib/flatTree.cjs +2 -0
  139. package/dist/lib/flatTree.cjs.map +1 -0
  140. package/dist/lib/flatTree.mjs +118 -0
  141. package/dist/lib/flatTree.mjs.map +1 -0
  142. package/dist/lib/selection.cjs +2 -0
  143. package/dist/lib/selection.cjs.map +1 -0
  144. package/dist/lib/selection.mjs +28 -0
  145. package/dist/lib/selection.mjs.map +1 -0
  146. package/dist/lib/treeCascade.cjs +2 -0
  147. package/dist/lib/treeCascade.cjs.map +1 -0
  148. package/dist/lib/treeCascade.mjs +52 -0
  149. package/dist/lib/treeCascade.mjs.map +1 -0
  150. package/dist/lib/virtual.cjs +2 -0
  151. package/dist/lib/virtual.cjs.map +1 -0
  152. package/dist/lib/virtual.mjs +54 -0
  153. package/dist/lib/virtual.mjs.map +1 -0
  154. package/dist/styles.css +1 -1
  155. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Listbox.cjs","names":["useFieldContext","useFieldControl","useControllable","EMPTY_VALUES","toValues","React","useIsClient","isFocused","useListbox","toggleValue","useMergedRefs","resetValues","isOwnEvent","composeEventHandlers","cn","listboxClassNames","focusRing","PickerAnnouncer","ListboxProvider","HiddenInput","Option","OptionGroup","require_runtime","require_cn","require_dev","require_composeEventHandlers","require_classNames","require_useControllable","require_focus","require_useMergedRefs","require_useIsClient","require_useFieldControl","require_useListbox","require_styles","require_useFormReset","require_HiddenInput","require_Option","require_pickerLabels","require_pickerValues","require_events","react","react_jsx_runtime","UNNAMED_WARNING","DISABLED_ATTRIBUTES","ListboxRoot","valueProp","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaInvalid","ariaRequired","rest","props","field","fieldProps","required","value","setValue","defaultValue","multiselect","onValueChange","next","values","focused","setFocused","listRef","isClient","autoFocusHandledRef","list","autoFocus","disabled","listbox","updated","labels","details","added","onActiveOptionChange","listElementRef","listProps","mergedRef","ref","activeId","activeOutOfView","setActiveOutOfView","observedId","setObservedId","option","el","observer","entry","entries","current","form","unnamed","handleKeyDown","event","handleFocus","handleBlur","onKeyDown","onKeyUp","onFocus","onBlur","className","ListboxOption","ListboxOptionGroup","Listbox"],"sources":["../../../src/components/input/Listbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { listboxClassNames } from '../../lib/classNames';\nimport { cn } from '../../lib/cn';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { warnOnce } from '../../lib/dev';\nimport { isOwnEvent } from '../../lib/events';\nimport { isFocused } from '../../lib/focus';\nimport { focusRing } from '../../lib/styles';\nimport { useControllable } from '../../hooks/useControllable';\nimport { useFieldContext, useFieldControl } from '../../hooks/useFieldControl';\nimport { useFormReset } from '../../hooks/useFormReset';\nimport { useIsClient } from '../../hooks/useIsClient';\nimport { useListbox } from '../../hooks/useListbox';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { HiddenInput } from '../internal/HiddenInput';\nimport { ListboxProvider, Option, OptionGroup } from './Option';\nimport { announceToggle, PickerAnnouncer } from './pickerLabels';\nimport { EMPTY_VALUES, resetValues, toggleValue, toValues } from './pickerValues';\n\n/* ------------------------------------------------------------------ */\n/* Listbox */\n/* ------------------------------------------------------------------ */\n\n/**\n * The Listbox's built-in texts, for localization: the announcements of a `multiselect` toggle.\n * Each member is optional and falls back to its English default.\n */\nexport interface ListboxLabels {\n /**\n * Announced when a `multiselect` toggle selects an option; `count` is the number of values\n * selected after the change.\n * @default (label, count) => `${label} added, ${count} selected`\n */\n added?: (label: string, count: number) => string;\n /**\n * Announced when a `multiselect` toggle deselects an option; `count` is the number of values\n * selected after the change.\n * @default (label, count) => `${label} removed, ${count} selected`\n */\n removed?: (label: string, count: number) => string;\n}\n\n/** Properties for the Listbox component. */\nexport interface ListboxProps<M extends boolean = false> extends Omit<\n React.HTMLAttributes<HTMLUListElement>,\n 'onChange' | 'defaultValue'\n> {\n /**\n * Several options can be selected (Fluent's `multiselect`; List's `selectionMode=\"multiple\"` is\n * the other widget): the value is an array, options draw a checkbox, Space, Enter and a click\n * toggle an option, and each toggle is announced. A non-literal `multiselect={flag}` is a type\n * error: render two elements, one for each mode.\n * @default false\n */\n multiselect?: M;\n /**\n * Controlled selected value (`''` for none), or with `multiselect` the selected values in\n * selection order (Fluent's `selectedOptions`).\n */\n value?: M extends true ? readonly string[] : string;\n /**\n * Initial selected value for uncontrolled usage, which a form reset restores.\n * @default '' (`[]` with `multiselect`)\n */\n defaultValue?: M extends true ? readonly string[] : string;\n /**\n * Called with the new value when it changes (a new array with `multiselect`; Fluent's\n * `onOptionSelect`, under WaveUI's value/onValueChange naming). In single-select mode, selecting\n * the selected option again changes nothing: the Listbox never deselects it.\n */\n onValueChange?: M extends true ? (value: string[]) => void : (value: string) => void;\n /**\n * Called after the active (highlighted) option changes — focus, arrow keys, typeahead, the\n * pointer — and with `null` when focus leaves the list (a switch to another window keeps the\n * active option). It reports what `aria-activedescendant` points at, from an effect once the\n * change commits. Fluent's `onActiveOptionChange` reports neither the pointer (its options have\n * no hover highlight) nor the loss of focus.\n */\n onActiveOptionChange?: (value: string | null) => void;\n /**\n * Takes the list out of the tab order (a click does not focus it either, as a disabled native\n * `<select>`) and dims it: its options take no pointer input, nothing can be selected, and\n * nothing is submitted or validated. Renders `aria-disabled` and `data-disabled`. An\n * `aria-disabled` of your own without `disabled` is passed through as it is: the list stays\n * interactive.\n * @default false\n */\n disabled?: boolean;\n /**\n * Focuses the list when it mounts in the browser (React focuses only form controls itself), not\n * while `disabled`. Server-rendered HTML carries the `autofocus` attribute for the browser's own\n * autofocus, so a hydrating list takes no focus, as React leaves a hydrated form control alone.\n * @default false\n */\n autoFocus?: boolean;\n /**\n * Keeps disabled options in the arrow-key, Home/End, PageUp/PageDown and typeahead order (the\n * option that is active on focus may then be a disabled one too); they still cannot be\n * selected (Space, Enter and a click do nothing). Unlike Fluent, which always keeps disabled\n * options reachable, WaveUI skips them by default.\n * @default false\n */\n disabledOptionsFocusable?: boolean;\n /** The `multiselect` toggle announcements, for localization. Unset members keep their English defaults. */\n labels?: ListboxLabels;\n /**\n * Name of the value in form submissions (renders a hidden input inside the list; one per value\n * with `multiselect`).\n */\n name?: string;\n /** Id of the form the value belongs to, when the Listbox is outside it. */\n form?: string;\n /**\n * A value is required to submit the form (native constraint validation); when validation finds\n * it empty, focus moves to the list.\n */\n required?: boolean;\n /**\n * Called on a key press on the list, before the built-in keys; `event.preventDefault()` skips\n * them.\n */\n onKeyDown?: React.KeyboardEventHandler<HTMLUListElement>;\n /** Ref to the `<ul role=\"listbox\">`. */\n ref?: React.Ref<HTMLUListElement>;\n}\n\n/** The Listbox component's type: a multi-select signature, then the single-select one. */\nexport interface ListboxComponent {\n (props: ListboxProps<true> & { multiselect: true }): React.ReactNode;\n (props: ListboxProps): React.ReactNode;\n displayName?: string;\n Option: typeof Option;\n OptionGroup: typeof OptionGroup;\n}\n\nconst UNNAMED_WARNING =\n 'Listbox: the listbox has no accessible name. Pass `aria-label` or `aria-labelledby`, or ' +\n 'render it inside a Field.';\n\n/** The state attributes of a disabled list, rendered only while `disabled` (C-DISABLED). */\nconst DISABLED_ATTRIBUTES = { 'aria-disabled': true, 'data-disabled': '' } as const;\n\nconst ListboxRoot = (props: ListboxProps<boolean>) => {\n const {\n multiselect = false,\n value: valueProp,\n defaultValue,\n onValueChange,\n onActiveOptionChange,\n disabled = false,\n disabledOptionsFocusable = false,\n autoFocus = false,\n labels,\n name,\n form,\n required,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired,\n onFocus,\n onBlur,\n onKeyDown,\n onKeyUp,\n className,\n children,\n ref,\n ...rest\n } = props;\n\n const field = useFieldContext();\n // `<label for>` does not reach a listbox, so a Field names it through aria-labelledby. An\n // explicit `required={false}` wins over a required Field, so aria-required matches the native\n // requirement below.\n const fieldProps = useFieldControl(\n {\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired ?? required,\n },\n { labelable: false },\n );\n\n const [value, setValue] = useControllable<string | readonly string[]>(\n valueProp,\n defaultValue ?? (multiselect ? EMPTY_VALUES : ''),\n (next) => {\n // The two call signatures make `onValueChange` a union of incompatible functions from here:\n // the root itself is written against the wider, internal shape (D9).\n (onValueChange as ((value: string | string[]) => void) | undefined)?.(\n typeof next === 'string' ? next : [...next],\n );\n },\n );\n // Normalised for the listbox, the hidden inputs and the reset: a single value is its own\n // one-element array, and a `value` passed as `null` from JavaScript is none rather than a crash.\n const values = toValues(value);\n\n // The focus of the list itself (not of anything inside it): an option is active only while the\n // list has focus, so its outline never shows on a list the user is not in (D17).\n const [focused, setFocused] = React.useState(false);\n const listRef = React.useRef<HTMLUListElement | null>(null);\n const isClient = useIsClient();\n // Whether the mount's autoFocus was handled: a later change never focuses the list.\n const autoFocusHandledRef = React.useRef(false);\n\n // The focus state follows the DOM, not only focus events, on mount, once hydrated and whenever\n // `disabled` changes: a list focused before hydration (a tab, the browser's autofocus) has focus\n // without a focus event React saw, and a browser that moves focus off a list whose tab stop went\n // away fires no blur. React focuses only form controls for `autoFocus`, so a list mounted in the\n // browser focuses itself; a hydrating one leaves focus where it is, as React does for a control.\n React.useLayoutEffect(() => {\n const list = listRef.current;\n if (!list) return;\n if (!autoFocusHandledRef.current) {\n autoFocusHandledRef.current = true;\n if (autoFocus && !disabled && isClient) list.focus();\n }\n setFocused(!disabled && isFocused(list));\n }, [autoFocus, disabled, isClient]);\n\n const listbox = useListbox({\n open: focused && !disabled,\n mode: 'standalone',\n multiselect,\n selectedValues: values,\n // APG listbox: the arrows stop at the ends.\n loop: false,\n disabledOptionsFocusable,\n onSelect: (next, details) => {\n if (disabled) return;\n if (!multiselect) {\n // Selecting the selected option again is no change: useControllable skips it.\n setValue(next);\n return;\n }\n const { values: updated, added } = toggleValue(values, next);\n setValue(updated);\n // A toggle the user made (D41): a controlled change and a form reset never reach this\n // callback. `details` carries the registered option, whose label is its text.\n announceToggle(labels, details?.item.label ?? next, added, updated.length);\n },\n onActiveValueChange: onActiveOptionChange,\n idPrefix: 'listbox',\n });\n // The hook's ref must reach the list: a pointer press on an option focuses the list through it.\n const { ref: listElementRef, ...listProps } = listbox.getListboxProps();\n const mergedRef = useMergedRefs<HTMLUListElement>(ref, listRef, listElementRef);\n\n // The active option's outline shows focus only while the option is in the list's view: scrolled\n // away (the wheel, a smaller list), the list draws its own ring as well (WCAG 2.4.7). A new active\n // option counts as shown until the browser reports otherwise, since the keys scroll it into view\n // (adjust-during-render pattern, C-HOOKS); without IntersectionObserver nothing is observed.\n const activeId = listProps['aria-activedescendant'];\n const [activeOutOfView, setActiveOutOfView] = React.useState(false);\n const [observedId, setObservedId] = React.useState(activeId);\n if (observedId !== activeId) {\n setObservedId(activeId);\n setActiveOutOfView(false);\n }\n React.useEffect(() => {\n const list = listRef.current;\n if (activeId === undefined || !list || typeof IntersectionObserver === 'undefined') return;\n const option = Array.from(list.querySelectorAll('[role=\"option\"]')).find(\n (el) => el.id === activeId,\n );\n if (!option) return;\n const observer = new IntersectionObserver(\n (entries) => {\n const entry = entries[entries.length - 1];\n if (entry) setActiveOutOfView(!entry.isIntersecting);\n },\n { root: list },\n );\n observer.observe(option);\n return () => observer.disconnect();\n }, [activeId]);\n\n useFormReset(\n listRef,\n () => {\n if (!multiselect) {\n setValue(defaultValue ?? '');\n return;\n }\n // Compared by content (C-FORMS), so a reset that keeps the same values reports nothing.\n setValue((current) => resetValues(current, defaultValue));\n },\n form,\n );\n\n // C-DEV: a listbox needs a name; a blank one names nothing.\n const unnamed = !fieldProps['aria-label']?.trim() && !fieldProps['aria-labelledby']?.trim();\n React.useEffect(() => {\n if (unnamed) warnOnce('Listbox:unnamed', UNNAMED_WARNING);\n }, [unnamed]);\n\n // C-COMPOSE: keys typed in a portal rendered inside the list bubble through it in React; they\n // are not the list's.\n const handleKeyDown = (event: React.KeyboardEvent<HTMLUListElement>) => {\n if (disabled || !isOwnEvent(event)) return;\n listbox.onKeyDown(event);\n };\n // Only the list's own focus counts: focus inside a portal rendered in it, or on its hidden\n // input (which hands focus back to the list), is not the list's.\n const handleFocus = (event: React.FocusEvent<HTMLUListElement>) => {\n if (event.target === event.currentTarget) setFocused(true);\n };\n // A switch to another window blurs the list but leaves it the active element, so the list keeps\n // its active option for the return, as a native `<select size>` keeps its keyboard position;\n // focus that moves elsewhere in the page changes the active element before the blur.\n const handleBlur = (event: React.FocusEvent<HTMLUListElement>) => {\n const list = event.currentTarget;\n if (event.target === list && !isFocused(list)) setFocused(false);\n };\n\n return (\n <ul\n {...rest}\n {...fieldProps}\n {...listProps}\n // The consumer's id (or the Field's control id), else the hook's; the option ids keep the\n // hook's prefix.\n id={fieldProps.id ?? listProps.id}\n tabIndex={disabled ? undefined : listProps.tabIndex}\n aria-activedescendant={listProps['aria-activedescendant']}\n aria-multiselectable={listProps['aria-multiselectable']}\n // Rendered only while disabled, so a consumer `aria-disabled` on an enabled list passes\n // through as it is (C-DISABLED: the list stays interactive).\n {...(disabled ? DISABLED_ATTRIBUTES : undefined)}\n // The server renders the `autofocus` attribute for the browser; the effect above focuses a\n // list mounted in the browser. Without autoFocus the prop stays out of hydration's check.\n autoFocus={autoFocus || undefined}\n ref={mergedRef}\n onKeyDown={composeEventHandlers(onKeyDown, handleKeyDown)}\n onKeyUp={composeEventHandlers(onKeyUp, listbox.onKeyUp)}\n // Bookkeeping that mirrors the DOM: it runs even when a consumer handler prevents the event.\n onFocus={composeEventHandlers(onFocus, handleFocus, { checkDefaultPrevented: false })}\n onBlur={composeEventHandlers(onBlur, handleBlur, { checkDefaultPrevented: false })}\n className={cn(\n listboxClassNames.root,\n // The list's own margin, padding and markers are set here, not left to the native reset\n // (C-NATIVE).\n 'relative m-0 flex list-none flex-col overflow-y-auto px-0 py-1 text-foreground',\n // The active option's outline shows focus; while no option can be active (an empty list,\n // every option hidden, or every option disabled without disabledOptionsFocusable), or the\n // active one is scrolled out of view, the list's own ring does (WCAG 2.4.7). The outline\n // is hidden only while focused, so forced colors still draw one (C-FOCUS).\n listbox.activeValue === null || activeOutOfView ? focusRing : 'focus:outline-hidden',\n // Disabled: the options take no pointer input (inherited by the options of a group), so\n // none hovers and the list's own not-allowed cursor shows over them.\n disabled && 'cursor-not-allowed opacity-50 *:pointer-events-none',\n className,\n )}\n >\n {multiselect && <PickerAnnouncer />}\n <ListboxProvider value={listbox.context}>{children}</ListboxProvider>\n {/* Inside the list: a focused hidden input hands focus back to its parent element. */}\n <HiddenInput\n name={name}\n form={form}\n disabled={disabled}\n value={multiselect ? values : (values[0] ?? '')}\n type=\"text\"\n required={required ?? field?.required ?? false}\n onInvalid={() => listRef.current?.focus()}\n />\n </ul>\n );\n};\nListboxRoot.displayName = 'Listbox';\n\n/** Flat name of `Listbox.Option` for React Server Components. */\nexport const ListboxOption = Option;\n/** Flat name of `Listbox.OptionGroup` for React Server Components. */\nexport const ListboxOptionGroup = OptionGroup;\n\n/**\n * A list of options that holds focus itself (APG listbox): one `<ul role=\"listbox\">` of\n * `Option`s, whose `aria-activedescendant` points at the active option while the list has focus.\n * It is the picker option model shown in the page — typeahead, groups, disabled options and the\n * option look of Dropdown and Combobox. Use `List` with `selectable` (`selectionMode`) instead\n * when each item needs real focus, actions of its own or interactive content.\n *\n * - **Focus.** One tab stop. The active option exists only while the list has focus, and a\n * switch to another window keeps it: the selected option (with `multiselect`, the first\n * selected one in list order), else the first. While no option can be active (an empty list,\n * every option hidden, or every option disabled without `disabledOptionsFocusable`), and while\n * the active option is scrolled out of the list's view, the list draws its own focus ring. A\n * press on an option with the primary button focuses the list and makes that option active\n * without scrolling, so the click selects it even while the selected option is scrolled out of\n * view; a right or middle press is left to the browser. `autoFocus` focuses the list when it\n * mounts.\n * - **Keys.** ArrowDown and ArrowUp move without wrapping, Home and End go to the first and last\n * option, PageUp and PageDown move ten options, and typing moves to the matching option\n * (typeahead). Space and Enter select the active option: the selection does not follow the\n * active option. Tab, Escape and Alt+Arrow keys are left to the page, so an enclosing Dialog\n * closes on Escape.\n * - **Selection.** `value`, `defaultValue` and `onValueChange` are Fluent's `selectedOptions`,\n * `defaultSelectedOptions` and `onOptionSelect` under WaveUI's value naming. A single-select\n * Listbox keeps the selected option when it is selected again (no deselection). `multiselect`\n * turns the value into an array: options draw a checkbox, Space, Enter and a click toggle an\n * option, the value keeps selection order, and every toggle the user makes is announced\n * (`labels.added`/`labels.removed`; never a controlled change or a form reset). A non-literal\n * `multiselect={flag}` is a type error: render two elements, one for each mode.\n * - **Disabled.** `disabled` takes the list out of the tab order (a click does not focus it\n * either), dims it, takes pointer input off its options, selects nothing and submits nothing.\n * Disabled options are skipped by the keys unless `disabledOptionsFocusable`, and are never\n * selected.\n * - **Forms and Field.** With `name` the value is submitted with its form (one entry, or one per\n * value with `multiselect`), and `required` needs a value (native validation; a missing value\n * moves focus to the list). A reset of its form restores `defaultValue`, with or without a\n * `name` (a `multiselect` reset is compared by content, so restoring the same values reports\n * nothing). Inside a `Field` the list is labelled by its label, described by its message and\n * hint, and takes its invalid and required state; otherwise name it with `aria-label` or\n * `aria-labelledby` (development warns once when it has no name).\n * - It has no built-in height: give it one through `className` and it scrolls.\n *\n * Every prop, the `ref` and the handlers go to the `<ul>`. Sub-components: `Listbox.Option`,\n * `Listbox.OptionGroup`. React Server Components import the flat names `ListboxOption` /\n * `ListboxOptionGroup` (dotted access needs a client file).\n *\n * @example\n * <Listbox aria-label=\"Fruit\" name=\"fruit\" defaultValue=\"banana\">\n * <Listbox.Option value=\"apple\">Apple</Listbox.Option>\n * <Listbox.Option value=\"banana\">Banana</Listbox.Option>\n * </Listbox>\n */\nexport const Listbox = /* @__PURE__ */ Object.assign(ListboxRoot, {\n Option,\n OptionGroup,\n}) as ListboxComponent;\n"],"mappings":"+wBAuIA,IAAM0C,EACJ,oHAIIC,EAAsB,CAAE,gBAAiB,GAAM,gBAAiB,EAAG,EAEnEC,EAAe,GAAiC,CACpD,GAAM,CACJ,cAAc,GACd,MAAOC,EACP,eACA,gBACA,wBACA,WAAW,GACX,4BAA2B,GAC3B,YAAY,GACZ,UACA,QACA,OACA,WACA,KACA,aAAcC,EACd,kBAAmBC,EACnB,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SAAUP,GAAYF,IAAO,UAAY,GACzC,cAAiBY,EAAQ,SAAS,MAAM,CACzC,CAAA,CACC,GAER,EACA,EAAY,YAAc,UAG1B,IAAasC,EAAgBnF,EAAAA,OAEhBoF,EAAqBnF,EAAAA,YAqDrBoF,EAA0B,OAAO,OAAO7D,EAAa,CAChE,OAAAR,EAAA,OACA,YAAAA,EAAA,WACF,CAAC"}
1
+ {"version":3,"file":"Listbox.cjs","names":["useFieldContext","useFieldControl","useControllable","EMPTY_VALUES","toValues","React","useIsClient","isFocused","useListbox","toggleValue","useMergedRefs","resetValues","isOwnEvent","composeEventHandlers","cn","listboxClassNames","focusRing","PickerAnnouncer","ListboxProvider","renderListboxWindow","renderListboxItems","HiddenInput","Option","OptionGroup","require_runtime","require_cn","require_dev","require_composeEventHandlers","require_classNames","require_useControllable","require_focus","require_useMergedRefs","require_useIsClient","require_useFieldControl","require_useListbox","require_styles","require_useFormReset","require_HiddenInput","require_Option","require_Option_data","require_pickerLabels","require_pickerValues","require_events","react","react_jsx_runtime","UNNAMED_WARNING","DISABLED_ATTRIBUTES","ListboxRoot","valueProp","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaInvalid","ariaRequired","rest","props","field","fieldProps","required","value","setValue","defaultValue","multiselect","onValueChange","next","values","focused","setFocused","listRef","isClient","autoFocusHandledRef","list","autoFocus","disabled","activeWindow","items","virtualWindow","listbox","index","updated","labels","details","added","onActiveOptionChange","listElementRef","listProps","mergedRef","ref","activeId","activeOutOfView","setActiveOutOfView","observedId","setObservedId","option","el","observer","entry","entries","current","form","unnamed","children","handleKeyDown","event","handleFocus","handleBlur","optionsState","onKeyDown","onKeyUp","onFocus","onBlur","className","ListboxOption","ListboxOptionGroup","Listbox"],"sources":["../../../src/components/input/Listbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { listboxClassNames } from '../../lib/classNames';\nimport { cn } from '../../lib/cn';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { warnOnce } from '../../lib/dev';\nimport { isOwnEvent } from '../../lib/events';\nimport { isFocused } from '../../lib/focus';\nimport { focusRing } from '../../lib/styles';\nimport { useControllable } from '../../hooks/useControllable';\nimport { useFieldContext, useFieldControl } from '../../hooks/useFieldControl';\nimport { useFormReset } from '../../hooks/useFormReset';\nimport { useIsClient } from '../../hooks/useIsClient';\nimport { useListbox, type ListboxItem } from '../../hooks/useListbox';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport type { VirtualWindow } from '../../hooks/useVirtualWindow';\nimport { HiddenInput } from '../internal/HiddenInput';\nimport { ListboxProvider, Option, OptionGroup, type ListboxOptionRenderState } from './Option';\nimport {\n renderListboxItems,\n renderListboxWindow,\n useDataModeWarnings,\n useItemsAndChildrenWarning,\n} from './Option.data';\nimport { announceToggle, PickerAnnouncer } from './pickerLabels';\nimport { EMPTY_VALUES, resetValues, toggleValue, toValues } from './pickerValues';\n\n/* ------------------------------------------------------------------ */\n/* Listbox */\n/* ------------------------------------------------------------------ */\n\n/**\n * The Listbox's built-in texts, for localization: the announcements of a `multiselect` toggle.\n * Each member is optional and falls back to its English default.\n */\nexport interface ListboxLabels {\n /**\n * Announced when a `multiselect` toggle selects an option; `count` is the number of values\n * selected after the change.\n * @default (label, count) => `${label} added, ${count} selected`\n */\n added?: (label: string, count: number) => string;\n /**\n * Announced when a `multiselect` toggle deselects an option; `count` is the number of values\n * selected after the change.\n * @default (label, count) => `${label} removed, ${count} selected`\n */\n removed?: (label: string, count: number) => string;\n}\n\n/** Properties for the Listbox component. */\nexport interface ListboxProps<M extends boolean = false> extends Omit<\n React.HTMLAttributes<HTMLUListElement>,\n 'onChange' | 'defaultValue'\n> {\n /**\n * Several options can be selected (Fluent's `multiselect`; List's `selectionMode=\"multiple\"` is\n * the other widget): the value is an array, options draw a checkbox, Space, Enter and a click\n * toggle an option, and each toggle is announced. A non-literal `multiselect={flag}` is a type\n * error: render two elements, one for each mode.\n * @default false\n */\n multiselect?: M;\n /**\n * Controlled selected value (`''` for none), or with `multiselect` the selected values in\n * selection order (Fluent's `selectedOptions`).\n */\n value?: M extends true ? readonly string[] : string;\n /**\n * Initial selected value for uncontrolled usage, which a form reset restores.\n * @default '' (`[]` with `multiselect`)\n */\n defaultValue?: M extends true ? readonly string[] : string;\n /**\n * Called with the new value when it changes (a new array with `multiselect`; Fluent's\n * `onOptionSelect`, under WaveUI's value/onValueChange naming). In single-select mode, selecting\n * the selected option again changes nothing: the Listbox never deselects it.\n */\n onValueChange?: M extends true ? (value: string[]) => void : (value: string) => void;\n /**\n * Called after the active (highlighted) option changes — focus, arrow keys, typeahead, the\n * pointer — and with `null` when focus leaves the list (a switch to another window keeps the\n * active option). It reports what `aria-activedescendant` points at, from an effect once the\n * change commits. Fluent's `onActiveOptionChange` reports neither the pointer (its options have\n * no hover highlight) nor the loss of focus.\n */\n onActiveOptionChange?: (value: string | null) => void;\n /**\n * Takes the list out of the tab order (a click does not focus it either, as a disabled native\n * `<select>`) and dims it: its options take no pointer input, nothing can be selected, and\n * nothing is submitted or validated. Renders `aria-disabled` and `data-disabled`. An\n * `aria-disabled` of your own without `disabled` is passed through as it is: the list stays\n * interactive.\n * @default false\n */\n disabled?: boolean;\n /**\n * Focuses the list when it mounts in the browser (React focuses only form controls itself), not\n * while `disabled`. Server-rendered HTML carries the `autofocus` attribute for the browser's own\n * autofocus, so a hydrating list takes no focus, as React leaves a hydrated form control alone.\n * @default false\n */\n autoFocus?: boolean;\n /**\n * Keeps disabled options in the arrow-key, Home/End, PageUp/PageDown and typeahead order (the\n * option that is active on focus may then be a disabled one too); they still cannot be\n * selected (Space, Enter and a click do nothing). Unlike Fluent, which always keeps disabled\n * options reachable, WaveUI skips them by default.\n * @default false\n */\n disabledOptionsFocusable?: boolean;\n /** The `multiselect` toggle announcements, for localization. Unset members keep their English defaults. */\n labels?: ListboxLabels;\n /**\n * Data mode: the options as data, in list order (`value`, `label`, and optionally `textValue`,\n * `disabled` and `hidden`; values unique). The list renders one option per item that is not\n * `hidden` (see `renderOption`), and the keys, typeahead and the selection follow `items`. The\n * children are neither read nor rendered: passing both warns once in development. Each option\n * gets `aria-posinset` and `aria-setsize` from its place among the shown items, and keeps one id\n * per value. Without it, the options are the `Option` children.\n */\n items?: readonly ListboxItem[];\n /**\n * Data mode: renders the option of an item, given its state (`selected`, `active`, and `index`\n * among the shown options). Return an `Option`, or an option component of your own on\n * `useListboxOption`, with the item's `value` (and its `disabled`); its position is set for you,\n * and in a windowed list (`virtualWindow`) its height. It is called again only when the item, its\n * state, its position (`aria-posinset` and `aria-setsize`, which new `items` change) or the\n * function itself changes, so pass a stable function in a long list. Ignored without `items`,\n * with a development warning.\n * @default an `Option` with the item's `value`, `label` (also its text), `textValue` and `disabled`\n */\n renderOption?: (item: ListboxItem, state: ListboxOptionRenderState) => React.ReactNode;\n /**\n * Data mode: renders only the options in view of a long list, plus an overscan, and spacers\n * (`aria-hidden`, `data-virtual-spacer`) as tall as the options they stand for: pass the result\n * of `useVirtualWindow({ itemSize })`, or an object of your own that implements `VirtualWindow`.\n * It needs `items`: without them, or beside `OptionGroup` children, it is ignored with a\n * development warning (a window renders a flat list).\n *\n * The list element is the window's scroller: give it a bounded height (a height or a maximum\n * height, through `className` or `style`); without one the window measures the whole list and\n * renders every option. While windowed the list has no block padding (add none through\n * `className`), so the options start at its top, where the window counts them, and no scroll\n * anchoring of the browser (the window lays the options out). Every option is exactly\n * `itemSize` tall (the list sets its height, after the option's own `style`), so an option's\n * content must fit in it: the default `Option` with one line of text is 32 pixels tall.\n *\n * The window counts the shown options (the items that are not `hidden`). The keys and typeahead\n * move over all of them (Home and End to the first and the last, PageUp and PageDown by ten); the\n * active option stays rendered while it is scrolled away, so `aria-activedescendant` always names\n * an element, and when the list gains focus or a key makes it active the list and the window\n * move to it in the same update (a pointer press moves neither). The server renders the first\n * window.\n */\n virtualWindow?: VirtualWindow;\n /**\n * Name of the value in form submissions (renders a hidden input inside the list; one per value\n * with `multiselect`).\n */\n name?: string;\n /** Id of the form the value belongs to, when the Listbox is outside it. */\n form?: string;\n /**\n * A value is required to submit the form (native constraint validation); when validation finds\n * it empty, focus moves to the list.\n */\n required?: boolean;\n /**\n * Called on a key press on the list, before the built-in keys; `event.preventDefault()` skips\n * them.\n */\n onKeyDown?: React.KeyboardEventHandler<HTMLUListElement>;\n /** Ref to the `<ul role=\"listbox\">`. */\n ref?: React.Ref<HTMLUListElement>;\n}\n\n/** The Listbox component's type: a multi-select signature, then the single-select one. */\nexport interface ListboxComponent {\n (props: ListboxProps<true> & { multiselect: true }): React.ReactNode;\n (props: ListboxProps): React.ReactNode;\n displayName?: string;\n Option: typeof Option;\n OptionGroup: typeof OptionGroup;\n}\n\nconst UNNAMED_WARNING =\n 'Listbox: the listbox has no accessible name. Pass `aria-label` or `aria-labelledby`, or ' +\n 'render it inside a Field.';\n\n/** The state attributes of a disabled list, rendered only while `disabled` (C-DISABLED). */\nconst DISABLED_ATTRIBUTES = { 'aria-disabled': true, 'data-disabled': '' } as const;\n\nconst ListboxRoot = (props: ListboxProps<boolean>) => {\n const {\n multiselect = false,\n value: valueProp,\n defaultValue,\n onValueChange,\n onActiveOptionChange,\n disabled = false,\n disabledOptionsFocusable = false,\n autoFocus = false,\n labels,\n items,\n renderOption,\n virtualWindow,\n name,\n form,\n required,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired,\n onFocus,\n onBlur,\n onKeyDown,\n onKeyUp,\n className,\n children,\n ref,\n ...rest\n } = props;\n\n const field = useFieldContext();\n // `<label for>` does not reach a listbox, so a Field names it through aria-labelledby. An\n // explicit `required={false}` wins over a required Field, so aria-required matches the native\n // requirement below.\n const fieldProps = useFieldControl(\n {\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired ?? required,\n },\n { labelable: false },\n );\n\n const [value, setValue] = useControllable<string | readonly string[]>(\n valueProp,\n defaultValue ?? (multiselect ? EMPTY_VALUES : ''),\n (next) => {\n // The two call signatures make `onValueChange` a union of incompatible functions from here:\n // the root itself is written against the wider, internal shape (D9).\n (onValueChange as ((value: string | string[]) => void) | undefined)?.(\n typeof next === 'string' ? next : [...next],\n );\n },\n );\n // Normalised for the listbox, the hidden inputs and the reset: a single value is its own\n // one-element array, and a `value` passed as `null` from JavaScript is none rather than a crash.\n const values = toValues(value);\n\n // The focus of the list itself (not of anything inside it): an option is active only while the\n // list has focus, so its outline never shows on a list the user is not in (D17).\n const [focused, setFocused] = React.useState(false);\n const listRef = React.useRef<HTMLUListElement | null>(null);\n const isClient = useIsClient();\n // Whether the mount's autoFocus was handled: a later change never focuses the list.\n const autoFocusHandledRef = React.useRef(false);\n\n // The focus state follows the DOM, not only focus events, on mount, once hydrated and whenever\n // `disabled` changes: a list focused before hydration (a tab, the browser's autofocus) has focus\n // without a focus event React saw, and a browser that moves focus off a list whose tab stop went\n // away fires no blur. React focuses only form controls for `autoFocus`, so a list mounted in the\n // browser focuses itself; a hydrating one leaves focus where it is, as React does for a control.\n React.useLayoutEffect(() => {\n const list = listRef.current;\n if (!list) return;\n if (!autoFocusHandledRef.current) {\n autoFocusHandledRef.current = true;\n if (autoFocus && !disabled && isClient) list.focus();\n }\n setFocused(!disabled && isFocused(list));\n }, [autoFocus, disabled, isClient]);\n\n // A window renders data mode only; the list is its scroller.\n const activeWindow = items === undefined ? undefined : virtualWindow;\n\n const listbox = useListbox({\n open: focused && !disabled,\n mode: 'standalone',\n multiselect,\n selectedValues: values,\n // APG listbox: the arrows stop at the ends.\n loop: false,\n disabledOptionsFocusable,\n items,\n // An active option that the window does not render (an adapter that keeps nothing): scrolled\n // to by its index among the shown options, the window's count.\n onScrollToItem: activeWindow\n ? (index) => activeWindow.scrollToIndex(index, { align: 'auto' })\n : undefined,\n onSelect: (next, details) => {\n if (disabled) return;\n if (!multiselect) {\n // Selecting the selected option again is no change: useControllable skips it.\n setValue(next);\n return;\n }\n const { values: updated, added } = toggleValue(values, next);\n setValue(updated);\n // A toggle the user made (D41): a controlled change and a form reset never reach this\n // callback. `details` carries the registered option (or the item), whose label is its text.\n announceToggle(labels, details?.item.label ?? next, added, updated.length);\n },\n onActiveValueChange: onActiveOptionChange,\n idPrefix: 'listbox',\n });\n // The hook's ref must reach the list: a pointer press on an option focuses the list through it.\n const { ref: listElementRef, ...listProps } = listbox.getListboxProps();\n const mergedRef = useMergedRefs<HTMLUListElement>(\n ref,\n listRef,\n listElementRef,\n activeWindow?.scrollRef,\n );\n\n // The active option's outline shows focus only while the option is in the list's view: scrolled\n // away (the wheel, a smaller list), the list draws its own ring as well (WCAG 2.4.7). A new active\n // option counts as shown until the browser reports otherwise, since the keys scroll it into view\n // (adjust-during-render pattern, C-HOOKS); without IntersectionObserver nothing is observed.\n const activeId = listProps['aria-activedescendant'];\n const [activeOutOfView, setActiveOutOfView] = React.useState(false);\n const [observedId, setObservedId] = React.useState(activeId);\n if (observedId !== activeId) {\n setObservedId(activeId);\n setActiveOutOfView(false);\n }\n React.useEffect(() => {\n const list = listRef.current;\n if (activeId === undefined || !list || typeof IntersectionObserver === 'undefined') return;\n const option = Array.from(list.querySelectorAll('[role=\"option\"]')).find(\n (el) => el.id === activeId,\n );\n if (!option) return;\n const observer = new IntersectionObserver(\n (entries) => {\n const entry = entries[entries.length - 1];\n if (entry) setActiveOutOfView(!entry.isIntersecting);\n },\n { root: list },\n );\n observer.observe(option);\n return () => observer.disconnect();\n }, [activeId]);\n\n useFormReset(\n listRef,\n () => {\n if (!multiselect) {\n setValue(defaultValue ?? '');\n return;\n }\n // Compared by content (C-FORMS), so a reset that keeps the same values reports nothing.\n setValue((current) => resetValues(current, defaultValue));\n },\n form,\n );\n\n // C-DEV: a listbox needs a name; a blank one names nothing.\n const unnamed = !fieldProps['aria-label']?.trim() && !fieldProps['aria-labelledby']?.trim();\n React.useEffect(() => {\n if (unnamed) warnOnce('Listbox:unnamed', UNNAMED_WARNING);\n }, [unnamed]);\n useItemsAndChildrenWarning('Listbox', items, children);\n useDataModeWarnings('Listbox', { items, renderOption, virtualWindow, children });\n\n // C-COMPOSE: keys typed in a portal rendered inside the list bubble through it in React; they\n // are not the list's.\n const handleKeyDown = (event: React.KeyboardEvent<HTMLUListElement>) => {\n if (disabled || !isOwnEvent(event)) return;\n listbox.onKeyDown(event);\n };\n // Only the list's own focus counts: focus inside a portal rendered in it, or on its hidden\n // input (which hands focus back to the list), is not the list's.\n const handleFocus = (event: React.FocusEvent<HTMLUListElement>) => {\n if (event.target === event.currentTarget) setFocused(true);\n };\n // A switch to another window blurs the list but leaves it the active element, so the list keeps\n // its active option for the return, as a native `<select size>` keeps its keyboard position;\n // focus that moves elsewhere in the page changes the active element before the blur.\n const handleBlur = (event: React.FocusEvent<HTMLUListElement>) => {\n const list = event.currentTarget;\n if (event.target === list && !isFocused(list)) setFocused(false);\n };\n\n // What every option of data mode is drawn from, besides its item.\n const optionsState = {\n selected: new Set(values),\n activeValue: listbox.activeValue,\n renderOption,\n };\n\n return (\n <ul\n {...rest}\n {...fieldProps}\n {...listProps}\n // The consumer's id (or the Field's control id), else the hook's; the option ids keep the\n // hook's prefix.\n id={fieldProps.id ?? listProps.id}\n tabIndex={disabled ? undefined : listProps.tabIndex}\n aria-activedescendant={listProps['aria-activedescendant']}\n aria-multiselectable={listProps['aria-multiselectable']}\n // Rendered only while disabled, so a consumer `aria-disabled` on an enabled list passes\n // through as it is (C-DISABLED: the list stays interactive).\n {...(disabled ? DISABLED_ATTRIBUTES : undefined)}\n // The server renders the `autofocus` attribute for the browser; the effect above focuses a\n // list mounted in the browser. Without autoFocus the prop stays out of hydration's check.\n autoFocus={autoFocus || undefined}\n ref={mergedRef}\n onKeyDown={composeEventHandlers(onKeyDown, handleKeyDown)}\n onKeyUp={composeEventHandlers(onKeyUp, listbox.onKeyUp)}\n // Bookkeeping that mirrors the DOM: it runs even when a consumer handler prevents the event.\n onFocus={composeEventHandlers(onFocus, handleFocus, { checkDefaultPrevented: false })}\n onBlur={composeEventHandlers(onBlur, handleBlur, { checkDefaultPrevented: false })}\n className={cn(\n listboxClassNames.root,\n // The list's own margin, padding and markers are set here, not left to the native reset\n // (C-NATIVE).\n 'relative m-0 flex list-none flex-col overflow-y-auto px-0 py-1 text-foreground',\n // The active option's outline shows focus; while no option can be active (an empty list,\n // every option hidden, or every option disabled without disabledOptionsFocusable), or the\n // active one is scrolled out of view, the list's own ring does (WCAG 2.4.7). The outline\n // is hidden only while focused, so forced colors still draw one (C-FOCUS).\n listbox.activeValue === null || activeOutOfView ? focusRing : 'focus:outline-hidden',\n // Disabled: the options take no pointer input (inherited by the options of a group), so\n // none hovers and the list's own not-allowed cursor shows over them.\n disabled && 'cursor-not-allowed opacity-50 *:pointer-events-none',\n // Windowed: the options start at the top of the scroller, where the window counts them,\n // and the window lays them out (the browser's scroll anchoring only fights it).\n activeWindow && 'py-0 [overflow-anchor:none]',\n className,\n )}\n >\n {multiselect && <PickerAnnouncer />}\n <ListboxProvider value={listbox.context}>\n {/* Data mode: the options of the shown items, or the window's; the children are ignored. */}\n {items === undefined\n ? children\n : activeWindow\n ? renderListboxWindow(\n listbox.items,\n activeWindow,\n optionsState,\n listboxClassNames.spacer,\n )\n : renderListboxItems(listbox.items, optionsState)}\n </ListboxProvider>\n {/* Inside the list: a focused hidden input hands focus back to its parent element. */}\n <HiddenInput\n name={name}\n form={form}\n disabled={disabled}\n value={multiselect ? values : (values[0] ?? '')}\n type=\"text\"\n required={required ?? field?.required ?? false}\n onInvalid={() => listRef.current?.focus()}\n />\n </ul>\n );\n};\nListboxRoot.displayName = 'Listbox';\n\n/** Flat name of `Listbox.Option` for React Server Components. */\nexport const ListboxOption = Option;\n/** Flat name of `Listbox.OptionGroup` for React Server Components. */\nexport const ListboxOptionGroup = OptionGroup;\n\n/**\n * A list of options that holds focus itself (APG listbox): one `<ul role=\"listbox\">` of\n * `Option`s, whose `aria-activedescendant` points at the active option while the list has focus.\n * It is the picker option model shown in the page — typeahead, groups, disabled options and the\n * option look of Dropdown and Combobox. Use `List` with `selectable` (`selectionMode`) instead\n * when each item needs real focus, actions of its own or interactive content.\n *\n * - **Focus.** One tab stop. The active option exists only while the list has focus, and a\n * switch to another window keeps it: the selected option (with `multiselect`, the first\n * selected one in list order), else the first. While no option can be active (an empty list,\n * every option hidden, or every option disabled without `disabledOptionsFocusable`), and while\n * the active option is scrolled out of the list's view, the list draws its own focus ring. A\n * press on an option with the primary button focuses the list and makes that option active\n * without scrolling, so the click selects it even while the selected option is scrolled out of\n * view; a right or middle press is left to the browser. `autoFocus` focuses the list when it\n * mounts.\n * - **Keys.** ArrowDown and ArrowUp move without wrapping, Home and End go to the first and last\n * option, PageUp and PageDown move ten options, and typing moves to the matching option\n * (typeahead). Space and Enter select the active option: the selection does not follow the\n * active option. Tab, Escape and Alt+Arrow keys are left to the page, so an enclosing Dialog\n * closes on Escape.\n * - **Selection.** `value`, `defaultValue` and `onValueChange` are Fluent's `selectedOptions`,\n * `defaultSelectedOptions` and `onOptionSelect` under WaveUI's value naming. A single-select\n * Listbox keeps the selected option when it is selected again (no deselection). `multiselect`\n * turns the value into an array: options draw a checkbox, Space, Enter and a click toggle an\n * option, the value keeps selection order, and every toggle the user makes is announced\n * (`labels.added`/`labels.removed`; never a controlled change or a form reset). A non-literal\n * `multiselect={flag}` is a type error: render two elements, one for each mode.\n * - **Disabled.** `disabled` takes the list out of the tab order (a click does not focus it\n * either), dims it, takes pointer input off its options, selects nothing and submits nothing.\n * Disabled options are skipped by the keys unless `disabledOptionsFocusable`, and are never\n * selected.\n * - **Data mode.** `items` passes the options as data instead of children: the list renders an\n * option per item (`renderOption` draws it, an `Option` with the item's label by default), the\n * keys, typeahead and the selection follow the data, and each option carries `aria-posinset`\n * and `aria-setsize`. A long list takes a `virtualWindow` (from `useVirtualWindow({ itemSize\n * })`): the list then renders only the options in view, plus an overscan, with spacers for the\n * others, every option `itemSize` tall, and the active option stays rendered.\n * - **Forms and Field.** With `name` the value is submitted with its form (one entry, or one per\n * value with `multiselect`), and `required` needs a value (native validation; a missing value\n * moves focus to the list). A reset of its form restores `defaultValue`, with or without a\n * `name` (a `multiselect` reset is compared by content, so restoring the same values reports\n * nothing). Inside a `Field` the list is labelled by its label, described by its message and\n * hint, and takes its invalid and required state; otherwise name it with `aria-label` or\n * `aria-labelledby` (development warns once when it has no name).\n * - It has no built-in height: give it one through `className` and it scrolls.\n *\n * Every prop, the `ref` and the handlers go to the `<ul>`. Sub-components: `Listbox.Option`,\n * `Listbox.OptionGroup`. React Server Components import the flat names `ListboxOption` /\n * `ListboxOptionGroup` (dotted access needs a client file).\n *\n * @example\n * <Listbox aria-label=\"Fruit\" name=\"fruit\" defaultValue=\"banana\">\n * <Listbox.Option value=\"apple\">Apple</Listbox.Option>\n * <Listbox.Option value=\"banana\">Banana</Listbox.Option>\n * </Listbox>\n *\n * @example\n * // Data mode\n * <Listbox aria-label=\"City\" items={cities.map((c) => ({ value: c.id, label: c.name }))} />\n */\nexport const Listbox = /* @__PURE__ */ Object.assign(ListboxRoot, {\n Option,\n OptionGroup,\n}) as ListboxComponent;\n"],"mappings":"gzBAyLA,IAAM6C,GACJ,oHAIIC,GAAsB,CAAE,gBAAiB,GAAM,gBAAiB,EAAG,EAEnEC,EAAe,GAAiC,CACpD,GAAM,CACJ,cAAc,GACd,MAAOC,EACP,eACA,gBACA,wBACA,WAAW,GACX,4BAA2B,GAC3B,YAAY,GACZ,SACA,QACA,eACA,gBACA,QACA,OACA,WACA,MACA,aAAcC,GACd,kBAAmBC,GACnB,mBAAoBC,EACpB,eAAgBC,EAChB,gBAAiBC,EACjB,UACA,SACA,YACA,UACA,YACA,WACA,MACA,GAAGC,GACDC,EAEEC,EAAQxD,EAAAA,gBAAgB,EAIxByD,EAAaxD,EAAAA,gBACjB,CACE,MACA,aAAcgD,GACd,kBAAmBC,GACnB,mBAAoBC,EACpB,eAAgBC,EAChB,gBAAiBC,GAAgBK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,GACP0B,EACA3B,EACEvD,EAAAA,oBACE0D,EAAQ,MACRH,EACAgC,EACA3F,EAAAA,kBAAkB,MACpB,EACAK,EAAAA,mBAAmByD,EAAQ,MAAO6B,CAAY,CACrC,CAAA,GAEjB,EAAA9D,EAAA,IAAA,CAACvB,GAAAA,YAAD,CACQ,QACA,OACI,WACV,MAAOyC,EAAcG,EAAUA,EAAO,IAAM,GAC5C,KAAK,OACL,SAAUP,GAAYF,GAAO,UAAY,GACzC,cAAiBY,EAAQ,SAAS,MAAM,CACzC,CAAA,CACC,GAER,EACA,EAAY,YAAc,UAG1B,IAAa4C,EAAgB1F,EAAAA,OAEhB2F,EAAqB1F,EAAAA,YA+DrB2F,EAA0B,OAAO,OAAOnE,EAAa,CAChE,OAAAT,EAAA,OACA,YAAAA,EAAA,WACF,CAAC"}
@@ -8,125 +8,137 @@ import { isFocused as a } from "../../lib/focus.mjs";
8
8
  import { useMergedRefs as o } from "../../hooks/useMergedRefs.mjs";
9
9
  import { useIsClient as ee } from "../../hooks/useIsClient.mjs";
10
10
  import { useFieldContext as te, useFieldControl as ne } from "../../hooks/useFieldControl.mjs";
11
- import { useListbox as s } from "../../hooks/useListbox.mjs";
12
- import { focusRing as c } from "../../lib/styles.mjs";
13
- import { useFormReset as l } from "../../hooks/useFormReset.mjs";
14
- import { HiddenInput as u } from "../internal/HiddenInput.mjs";
15
- import { ListboxProvider as d, Option as f, OptionGroup as p } from "./Option.mjs";
16
- import { PickerAnnouncer as m, announceToggle as re } from "./pickerLabels.mjs";
17
- import { EMPTY_VALUES as ie, resetValues as ae, toValues as oe, toggleValue as se } from "./pickerValues.mjs";
18
- import { isOwnEvent as ce } from "../../lib/events.mjs";
11
+ import { useListbox as re } from "../../hooks/useListbox.mjs";
12
+ import { focusRing as ie } from "../../lib/styles.mjs";
13
+ import { useFormReset as ae } from "../../hooks/useFormReset.mjs";
14
+ import { HiddenInput as s } from "../internal/HiddenInput.mjs";
15
+ import { ListboxProvider as c, Option as l, OptionGroup as u } from "./Option.mjs";
16
+ import { renderListboxItems as d, renderListboxWindow as f, useDataModeWarnings as p, useItemsAndChildrenWarning as m } from "./Option.data.mjs";
17
+ import { PickerAnnouncer as oe, announceToggle as se } from "./pickerLabels.mjs";
18
+ import { EMPTY_VALUES as ce, resetValues as le, toValues as ue, toggleValue as de } from "./pickerValues.mjs";
19
+ import { isOwnEvent as fe } from "../../lib/events.mjs";
19
20
  import * as h from "react";
20
- import { jsx as g, jsxs as le } from "react/jsx-runtime";
21
+ import { jsx as g, jsxs as pe } from "react/jsx-runtime";
21
22
  //#region src/components/input/Listbox.tsx
22
- var ue = "Listbox: the listbox has no accessible name. Pass `aria-label` or `aria-labelledby`, or render it inside a Field.", de = {
23
+ var me = "Listbox: the listbox has no accessible name. Pass `aria-label` or `aria-labelledby`, or render it inside a Field.", he = {
23
24
  "aria-disabled": !0,
24
25
  "data-disabled": ""
25
- }, _ = (f) => {
26
- let { multiselect: p = !1, value: _, defaultValue: v, onValueChange: y, onActiveOptionChange: b, disabled: x = !1, disabledOptionsFocusable: S = !1, autoFocus: C = !1, labels: w, name: T, form: E, required: D, id: O, "aria-label": k, "aria-labelledby": A, "aria-describedby": j, "aria-invalid": M, "aria-required": N, onFocus: P, onBlur: F, onKeyDown: I, onKeyUp: L, className: fe, children: R, ref: z, ...B } = f, V = te(), H = ne({
27
- id: O,
28
- "aria-label": k,
29
- "aria-labelledby": A,
30
- "aria-describedby": j,
31
- "aria-invalid": M,
32
- "aria-required": N ?? D
33
- }, { labelable: !1 }), [pe, U] = i(_, v ?? (p ? ie : ""), (e) => {
26
+ }, _ = (l) => {
27
+ let { multiselect: u = !1, value: _, defaultValue: v, onValueChange: y, onActiveOptionChange: b, disabled: x = !1, disabledOptionsFocusable: S = !1, autoFocus: C = !1, labels: w, items: T, renderOption: E, virtualWindow: D, name: O, form: k, required: A, id: j, "aria-label": M, "aria-labelledby": N, "aria-describedby": P, "aria-invalid": F, "aria-required": I, onFocus: L, onBlur: R, onKeyDown: ge, onKeyUp: _e, className: ve, children: z, ref: ye, ...be } = l, xe = te(), B = ne({
28
+ id: j,
29
+ "aria-label": M,
30
+ "aria-labelledby": N,
31
+ "aria-describedby": P,
32
+ "aria-invalid": F,
33
+ "aria-required": I ?? A
34
+ }, { labelable: !1 }), [Se, V] = i(_, v ?? (u ? ce : ""), (e) => {
34
35
  y?.(typeof e == "string" ? e : [...e]);
35
- }), W = oe(pe), [me, G] = h.useState(!1), K = h.useRef(null), q = ee(), J = h.useRef(!1);
36
+ }), H = ue(Se), [Ce, U] = h.useState(!1), W = h.useRef(null), G = ee(), K = h.useRef(!1);
36
37
  h.useLayoutEffect(() => {
37
- let e = K.current;
38
- e && (J.current || (J.current = !0, C && !x && q && e.focus()), G(!x && a(e)));
38
+ let e = W.current;
39
+ e && (K.current || (K.current = !0, C && !x && G && e.focus()), U(!x && a(e)));
39
40
  }, [
40
41
  C,
41
42
  x,
42
- q
43
+ G
43
44
  ]);
44
- let Y = s({
45
- open: me && !x,
45
+ let q = T === void 0 ? void 0 : D, J = re({
46
+ open: Ce && !x,
46
47
  mode: "standalone",
47
- multiselect: p,
48
- selectedValues: W,
48
+ multiselect: u,
49
+ selectedValues: H,
49
50
  loop: !1,
50
51
  disabledOptionsFocusable: S,
52
+ items: T,
53
+ onScrollToItem: q ? (e) => q.scrollToIndex(e, { align: "auto" }) : void 0,
51
54
  onSelect: (e, t) => {
52
55
  if (x) return;
53
- if (!p) {
54
- U(e);
56
+ if (!u) {
57
+ V(e);
55
58
  return;
56
59
  }
57
- let { values: n, added: r } = se(W, e);
58
- U(n), re(w, t?.item.label ?? e, r, n.length);
60
+ let { values: n, added: r } = de(H, e);
61
+ V(n), se(w, t?.item.label ?? e, r, n.length);
59
62
  },
60
63
  onActiveValueChange: b,
61
64
  idPrefix: "listbox"
62
- }), { ref: he, ...X } = Y.getListboxProps(), ge = o(z, K, he), Z = X["aria-activedescendant"], [_e, Q] = h.useState(!1), [ve, ye] = h.useState(Z);
63
- ve !== Z && (ye(Z), Q(!1)), h.useEffect(() => {
64
- let e = K.current;
65
- if (Z === void 0 || !e || typeof IntersectionObserver > "u") return;
66
- let t = Array.from(e.querySelectorAll("[role=\"option\"]")).find((e) => e.id === Z);
65
+ }), { ref: we, ...Y } = J.getListboxProps(), Te = o(ye, W, we, q?.scrollRef), X = Y["aria-activedescendant"], [Ee, Z] = h.useState(!1), [De, Oe] = h.useState(X);
66
+ De !== X && (Oe(X), Z(!1)), h.useEffect(() => {
67
+ let e = W.current;
68
+ if (X === void 0 || !e || typeof IntersectionObserver > "u") return;
69
+ let t = Array.from(e.querySelectorAll("[role=\"option\"]")).find((e) => e.id === X);
67
70
  if (!t) return;
68
71
  let n = new IntersectionObserver((e) => {
69
72
  let t = e[e.length - 1];
70
- t && Q(!t.isIntersecting);
73
+ t && Z(!t.isIntersecting);
71
74
  }, { root: e });
72
75
  return n.observe(t), () => n.disconnect();
73
- }, [Z]), l(K, () => {
74
- if (!p) {
75
- U(v ?? "");
76
+ }, [X]), ae(W, () => {
77
+ if (!u) {
78
+ V(v ?? "");
76
79
  return;
77
80
  }
78
- U((e) => ae(e, v));
79
- }, E);
80
- let $ = !H["aria-label"]?.trim() && !H["aria-labelledby"]?.trim();
81
+ V((e) => le(e, v));
82
+ }, k);
83
+ let Q = !B["aria-label"]?.trim() && !B["aria-labelledby"]?.trim();
81
84
  h.useEffect(() => {
82
- $ && t("Listbox:unnamed", ue);
83
- }, [$]);
84
- let be = (e) => {
85
- !x && ce(e) && Y.onKeyDown(e);
86
- }, xe = (e) => {
87
- e.target === e.currentTarget && G(!0);
88
- }, Se = (e) => {
85
+ Q && t("Listbox:unnamed", me);
86
+ }, [Q]), m("Listbox", T, z), p("Listbox", {
87
+ items: T,
88
+ renderOption: E,
89
+ virtualWindow: D,
90
+ children: z
91
+ });
92
+ let ke = (e) => {
93
+ !x && fe(e) && J.onKeyDown(e);
94
+ }, Ae = (e) => {
95
+ e.target === e.currentTarget && U(!0);
96
+ }, je = (e) => {
89
97
  let t = e.currentTarget;
90
- e.target === t && !a(t) && G(!1);
98
+ e.target === t && !a(t) && U(!1);
99
+ }, $ = {
100
+ selected: new Set(H),
101
+ activeValue: J.activeValue,
102
+ renderOption: E
91
103
  };
92
- return /* @__PURE__ */ le("ul", {
104
+ return /* @__PURE__ */ pe("ul", {
105
+ ...be,
93
106
  ...B,
94
- ...H,
95
- ...X,
96
- id: H.id ?? X.id,
97
- tabIndex: x ? void 0 : X.tabIndex,
98
- "aria-activedescendant": X["aria-activedescendant"],
99
- "aria-multiselectable": X["aria-multiselectable"],
100
- ...x ? de : void 0,
107
+ ...Y,
108
+ id: B.id ?? Y.id,
109
+ tabIndex: x ? void 0 : Y.tabIndex,
110
+ "aria-activedescendant": Y["aria-activedescendant"],
111
+ "aria-multiselectable": Y["aria-multiselectable"],
112
+ ...x ? he : void 0,
101
113
  autoFocus: C || void 0,
102
- ref: ge,
103
- onKeyDown: n(I, be),
104
- onKeyUp: n(L, Y.onKeyUp),
105
- onFocus: n(P, xe, { checkDefaultPrevented: !1 }),
106
- onBlur: n(F, Se, { checkDefaultPrevented: !1 }),
107
- className: e(r.root, "relative m-0 flex list-none flex-col overflow-y-auto px-0 py-1 text-foreground", Y.activeValue === null || _e ? c : "focus:outline-hidden", x && "cursor-not-allowed opacity-50 *:pointer-events-none", fe),
114
+ ref: Te,
115
+ onKeyDown: n(ge, ke),
116
+ onKeyUp: n(_e, J.onKeyUp),
117
+ onFocus: n(L, Ae, { checkDefaultPrevented: !1 }),
118
+ onBlur: n(R, je, { checkDefaultPrevented: !1 }),
119
+ className: e(r.root, "relative m-0 flex list-none flex-col overflow-y-auto px-0 py-1 text-foreground", J.activeValue === null || Ee ? ie : "focus:outline-hidden", x && "cursor-not-allowed opacity-50 *:pointer-events-none", q && "py-0 [overflow-anchor:none]", ve),
108
120
  children: [
109
- p && /* @__PURE__ */ g(m, {}),
110
- /* @__PURE__ */ g(d, {
111
- value: Y.context,
112
- children: R
121
+ u && /* @__PURE__ */ g(oe, {}),
122
+ /* @__PURE__ */ g(c, {
123
+ value: J.context,
124
+ children: T === void 0 ? z : q ? f(J.items, q, $, r.spacer) : d(J.items, $)
113
125
  }),
114
- /* @__PURE__ */ g(u, {
115
- name: T,
116
- form: E,
126
+ /* @__PURE__ */ g(s, {
127
+ name: O,
128
+ form: k,
117
129
  disabled: x,
118
- value: p ? W : W[0] ?? "",
130
+ value: u ? H : H[0] ?? "",
119
131
  type: "text",
120
- required: D ?? V?.required ?? !1,
121
- onInvalid: () => K.current?.focus()
132
+ required: A ?? xe?.required ?? !1,
133
+ onInvalid: () => W.current?.focus()
122
134
  })
123
135
  ]
124
136
  });
125
137
  };
126
138
  _.displayName = "Listbox";
127
- var v = f, y = p, b = /* @__PURE__ */ Object.assign(_, {
128
- Option: f,
129
- OptionGroup: p
139
+ var v = l, y = u, b = /* @__PURE__ */ Object.assign(_, {
140
+ Option: l,
141
+ OptionGroup: u
130
142
  });
131
143
  //#endregion
132
144
  export { b as Listbox, v as ListboxOption, y as ListboxOptionGroup };
@@ -1 +1 @@
1
- {"version":3,"file":"Listbox.mjs","names":["React","UNNAMED_WARNING","DISABLED_ATTRIBUTES","ListboxRoot","valueProp","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaInvalid","ariaRequired","rest","props","field","useFieldContext","fieldProps","useFieldControl","required","value","setValue","useControllable","defaultValue","multiselect","EMPTY_VALUES","next","values","toValues","focused","setFocused","listRef","isClient","useIsClient","autoFocusHandledRef","list","autoFocus","disabled","isFocused","listbox","useListbox","updated","toggleValue","announceToggle","labels","details","added","onActiveOptionChange","listElementRef","listProps","mergedRef","useMergedRefs","ref","activeId","activeOutOfView","setActiveOutOfView","observedId","setObservedId","option","el","observer","entry","entries","useFormReset","resetValues","current","form","unnamed","warnOnce","handleKeyDown","isOwnEvent","event","handleFocus","handleBlur","composeEventHandlers","onKeyDown","onKeyUp","onFocus","onBlur","cn","listboxClassNames","focusRing","className","PickerAnnouncer","ListboxProvider","HiddenInput","ListboxOption","Option","ListboxOptionGroup","OptionGroup","Listbox"],"sources":["../../../src/components/input/Listbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { listboxClassNames } from '../../lib/classNames';\nimport { cn } from '../../lib/cn';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { warnOnce } from '../../lib/dev';\nimport { isOwnEvent } from '../../lib/events';\nimport { isFocused } from '../../lib/focus';\nimport { focusRing } from '../../lib/styles';\nimport { useControllable } from '../../hooks/useControllable';\nimport { useFieldContext, useFieldControl } from '../../hooks/useFieldControl';\nimport { useFormReset } from '../../hooks/useFormReset';\nimport { useIsClient } from '../../hooks/useIsClient';\nimport { useListbox } from '../../hooks/useListbox';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport { HiddenInput } from '../internal/HiddenInput';\nimport { ListboxProvider, Option, OptionGroup } from './Option';\nimport { announceToggle, PickerAnnouncer } from './pickerLabels';\nimport { EMPTY_VALUES, resetValues, toggleValue, toValues } from './pickerValues';\n\n/* ------------------------------------------------------------------ */\n/* Listbox */\n/* ------------------------------------------------------------------ */\n\n/**\n * The Listbox's built-in texts, for localization: the announcements of a `multiselect` toggle.\n * Each member is optional and falls back to its English default.\n */\nexport interface ListboxLabels {\n /**\n * Announced when a `multiselect` toggle selects an option; `count` is the number of values\n * selected after the change.\n * @default (label, count) => `${label} added, ${count} selected`\n */\n added?: (label: string, count: number) => string;\n /**\n * Announced when a `multiselect` toggle deselects an option; `count` is the number of values\n * selected after the change.\n * @default (label, count) => `${label} removed, ${count} selected`\n */\n removed?: (label: string, count: number) => string;\n}\n\n/** Properties for the Listbox component. */\nexport interface ListboxProps<M extends boolean = false> extends Omit<\n React.HTMLAttributes<HTMLUListElement>,\n 'onChange' | 'defaultValue'\n> {\n /**\n * Several options can be selected (Fluent's `multiselect`; List's `selectionMode=\"multiple\"` is\n * the other widget): the value is an array, options draw a checkbox, Space, Enter and a click\n * toggle an option, and each toggle is announced. A non-literal `multiselect={flag}` is a type\n * error: render two elements, one for each mode.\n * @default false\n */\n multiselect?: M;\n /**\n * Controlled selected value (`''` for none), or with `multiselect` the selected values in\n * selection order (Fluent's `selectedOptions`).\n */\n value?: M extends true ? readonly string[] : string;\n /**\n * Initial selected value for uncontrolled usage, which a form reset restores.\n * @default '' (`[]` with `multiselect`)\n */\n defaultValue?: M extends true ? readonly string[] : string;\n /**\n * Called with the new value when it changes (a new array with `multiselect`; Fluent's\n * `onOptionSelect`, under WaveUI's value/onValueChange naming). In single-select mode, selecting\n * the selected option again changes nothing: the Listbox never deselects it.\n */\n onValueChange?: M extends true ? (value: string[]) => void : (value: string) => void;\n /**\n * Called after the active (highlighted) option changes — focus, arrow keys, typeahead, the\n * pointer — and with `null` when focus leaves the list (a switch to another window keeps the\n * active option). It reports what `aria-activedescendant` points at, from an effect once the\n * change commits. Fluent's `onActiveOptionChange` reports neither the pointer (its options have\n * no hover highlight) nor the loss of focus.\n */\n onActiveOptionChange?: (value: string | null) => void;\n /**\n * Takes the list out of the tab order (a click does not focus it either, as a disabled native\n * `<select>`) and dims it: its options take no pointer input, nothing can be selected, and\n * nothing is submitted or validated. Renders `aria-disabled` and `data-disabled`. An\n * `aria-disabled` of your own without `disabled` is passed through as it is: the list stays\n * interactive.\n * @default false\n */\n disabled?: boolean;\n /**\n * Focuses the list when it mounts in the browser (React focuses only form controls itself), not\n * while `disabled`. Server-rendered HTML carries the `autofocus` attribute for the browser's own\n * autofocus, so a hydrating list takes no focus, as React leaves a hydrated form control alone.\n * @default false\n */\n autoFocus?: boolean;\n /**\n * Keeps disabled options in the arrow-key, Home/End, PageUp/PageDown and typeahead order (the\n * option that is active on focus may then be a disabled one too); they still cannot be\n * selected (Space, Enter and a click do nothing). Unlike Fluent, which always keeps disabled\n * options reachable, WaveUI skips them by default.\n * @default false\n */\n disabledOptionsFocusable?: boolean;\n /** The `multiselect` toggle announcements, for localization. Unset members keep their English defaults. */\n labels?: ListboxLabels;\n /**\n * Name of the value in form submissions (renders a hidden input inside the list; one per value\n * with `multiselect`).\n */\n name?: string;\n /** Id of the form the value belongs to, when the Listbox is outside it. */\n form?: string;\n /**\n * A value is required to submit the form (native constraint validation); when validation finds\n * it empty, focus moves to the list.\n */\n required?: boolean;\n /**\n * Called on a key press on the list, before the built-in keys; `event.preventDefault()` skips\n * them.\n */\n onKeyDown?: React.KeyboardEventHandler<HTMLUListElement>;\n /** Ref to the `<ul role=\"listbox\">`. */\n ref?: React.Ref<HTMLUListElement>;\n}\n\n/** The Listbox component's type: a multi-select signature, then the single-select one. */\nexport interface ListboxComponent {\n (props: ListboxProps<true> & { multiselect: true }): React.ReactNode;\n (props: ListboxProps): React.ReactNode;\n displayName?: string;\n Option: typeof Option;\n OptionGroup: typeof OptionGroup;\n}\n\nconst UNNAMED_WARNING =\n 'Listbox: the listbox has no accessible name. Pass `aria-label` or `aria-labelledby`, or ' +\n 'render it inside a Field.';\n\n/** The state attributes of a disabled list, rendered only while `disabled` (C-DISABLED). */\nconst DISABLED_ATTRIBUTES = { 'aria-disabled': true, 'data-disabled': '' } as const;\n\nconst ListboxRoot = (props: ListboxProps<boolean>) => {\n const {\n multiselect = false,\n value: valueProp,\n defaultValue,\n onValueChange,\n onActiveOptionChange,\n disabled = false,\n disabledOptionsFocusable = false,\n autoFocus = false,\n labels,\n name,\n form,\n required,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired,\n onFocus,\n onBlur,\n onKeyDown,\n onKeyUp,\n className,\n children,\n ref,\n ...rest\n } = props;\n\n const field = useFieldContext();\n // `<label for>` does not reach a listbox, so a Field names it through aria-labelledby. An\n // explicit `required={false}` wins over a required Field, so aria-required matches the native\n // requirement below.\n const fieldProps = useFieldControl(\n {\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired ?? required,\n },\n { labelable: false },\n );\n\n const [value, setValue] = useControllable<string | readonly string[]>(\n valueProp,\n defaultValue ?? (multiselect ? EMPTY_VALUES : ''),\n (next) => {\n // The two call signatures make `onValueChange` a union of incompatible functions from here:\n // the root itself is written against the wider, internal shape (D9).\n (onValueChange as ((value: string | string[]) => void) | undefined)?.(\n typeof next === 'string' ? next : [...next],\n );\n },\n );\n // Normalised for the listbox, the hidden inputs and the reset: a single value is its own\n // one-element array, and a `value` passed as `null` from JavaScript is none rather than a crash.\n const values = toValues(value);\n\n // The focus of the list itself (not of anything inside it): an option is active only while the\n // list has focus, so its outline never shows on a list the user is not in (D17).\n const [focused, setFocused] = React.useState(false);\n const listRef = React.useRef<HTMLUListElement | null>(null);\n const isClient = useIsClient();\n // Whether the mount's autoFocus was handled: a later change never focuses the list.\n const autoFocusHandledRef = React.useRef(false);\n\n // The focus state follows the DOM, not only focus events, on mount, once hydrated and whenever\n // `disabled` changes: a list focused before hydration (a tab, the browser's autofocus) has focus\n // without a focus event React saw, and a browser that moves focus off a list whose tab stop went\n // away fires no blur. React focuses only form controls for `autoFocus`, so a list mounted in the\n // browser focuses itself; a hydrating one leaves focus where it is, as React does for a control.\n React.useLayoutEffect(() => {\n const list = listRef.current;\n if (!list) return;\n if (!autoFocusHandledRef.current) {\n autoFocusHandledRef.current = true;\n if (autoFocus && !disabled && isClient) list.focus();\n }\n setFocused(!disabled && isFocused(list));\n }, [autoFocus, disabled, isClient]);\n\n const listbox = useListbox({\n open: focused && !disabled,\n mode: 'standalone',\n multiselect,\n selectedValues: values,\n // APG listbox: the arrows stop at the ends.\n loop: false,\n disabledOptionsFocusable,\n onSelect: (next, details) => {\n if (disabled) return;\n if (!multiselect) {\n // Selecting the selected option again is no change: useControllable skips it.\n setValue(next);\n return;\n }\n const { values: updated, added } = toggleValue(values, next);\n setValue(updated);\n // A toggle the user made (D41): a controlled change and a form reset never reach this\n // callback. `details` carries the registered option, whose label is its text.\n announceToggle(labels, details?.item.label ?? next, added, updated.length);\n },\n onActiveValueChange: onActiveOptionChange,\n idPrefix: 'listbox',\n });\n // The hook's ref must reach the list: a pointer press on an option focuses the list through it.\n const { ref: listElementRef, ...listProps } = listbox.getListboxProps();\n const mergedRef = useMergedRefs<HTMLUListElement>(ref, listRef, listElementRef);\n\n // The active option's outline shows focus only while the option is in the list's view: scrolled\n // away (the wheel, a smaller list), the list draws its own ring as well (WCAG 2.4.7). A new active\n // option counts as shown until the browser reports otherwise, since the keys scroll it into view\n // (adjust-during-render pattern, C-HOOKS); without IntersectionObserver nothing is observed.\n const activeId = listProps['aria-activedescendant'];\n const [activeOutOfView, setActiveOutOfView] = React.useState(false);\n const [observedId, setObservedId] = React.useState(activeId);\n if (observedId !== activeId) {\n setObservedId(activeId);\n setActiveOutOfView(false);\n }\n React.useEffect(() => {\n const list = listRef.current;\n if (activeId === undefined || !list || typeof IntersectionObserver === 'undefined') return;\n const option = Array.from(list.querySelectorAll('[role=\"option\"]')).find(\n (el) => el.id === activeId,\n );\n if (!option) return;\n const observer = new IntersectionObserver(\n (entries) => {\n const entry = entries[entries.length - 1];\n if (entry) setActiveOutOfView(!entry.isIntersecting);\n },\n { root: list },\n );\n observer.observe(option);\n return () => observer.disconnect();\n }, [activeId]);\n\n useFormReset(\n listRef,\n () => {\n if (!multiselect) {\n setValue(defaultValue ?? '');\n return;\n }\n // Compared by content (C-FORMS), so a reset that keeps the same values reports nothing.\n setValue((current) => resetValues(current, defaultValue));\n },\n form,\n );\n\n // C-DEV: a listbox needs a name; a blank one names nothing.\n const unnamed = !fieldProps['aria-label']?.trim() && !fieldProps['aria-labelledby']?.trim();\n React.useEffect(() => {\n if (unnamed) warnOnce('Listbox:unnamed', UNNAMED_WARNING);\n }, [unnamed]);\n\n // C-COMPOSE: keys typed in a portal rendered inside the list bubble through it in React; they\n // are not the list's.\n const handleKeyDown = (event: React.KeyboardEvent<HTMLUListElement>) => {\n if (disabled || !isOwnEvent(event)) return;\n listbox.onKeyDown(event);\n };\n // Only the list's own focus counts: focus inside a portal rendered in it, or on its hidden\n // input (which hands focus back to the list), is not the list's.\n const handleFocus = (event: React.FocusEvent<HTMLUListElement>) => {\n if (event.target === event.currentTarget) setFocused(true);\n };\n // A switch to another window blurs the list but leaves it the active element, so the list keeps\n // its active option for the return, as a native `<select size>` keeps its keyboard position;\n // focus that moves elsewhere in the page changes the active element before the blur.\n const handleBlur = (event: React.FocusEvent<HTMLUListElement>) => {\n const list = event.currentTarget;\n if (event.target === list && !isFocused(list)) setFocused(false);\n };\n\n return (\n <ul\n {...rest}\n {...fieldProps}\n {...listProps}\n // The consumer's id (or the Field's control id), else the hook's; the option ids keep the\n // hook's prefix.\n id={fieldProps.id ?? listProps.id}\n tabIndex={disabled ? undefined : listProps.tabIndex}\n aria-activedescendant={listProps['aria-activedescendant']}\n aria-multiselectable={listProps['aria-multiselectable']}\n // Rendered only while disabled, so a consumer `aria-disabled` on an enabled list passes\n // through as it is (C-DISABLED: the list stays interactive).\n {...(disabled ? DISABLED_ATTRIBUTES : undefined)}\n // The server renders the `autofocus` attribute for the browser; the effect above focuses a\n // list mounted in the browser. Without autoFocus the prop stays out of hydration's check.\n autoFocus={autoFocus || undefined}\n ref={mergedRef}\n onKeyDown={composeEventHandlers(onKeyDown, handleKeyDown)}\n onKeyUp={composeEventHandlers(onKeyUp, listbox.onKeyUp)}\n // Bookkeeping that mirrors the DOM: it runs even when a consumer handler prevents the event.\n onFocus={composeEventHandlers(onFocus, handleFocus, { checkDefaultPrevented: false })}\n onBlur={composeEventHandlers(onBlur, handleBlur, { checkDefaultPrevented: false })}\n className={cn(\n listboxClassNames.root,\n // The list's own margin, padding and markers are set here, not left to the native reset\n // (C-NATIVE).\n 'relative m-0 flex list-none flex-col overflow-y-auto px-0 py-1 text-foreground',\n // The active option's outline shows focus; while no option can be active (an empty list,\n // every option hidden, or every option disabled without disabledOptionsFocusable), or the\n // active one is scrolled out of view, the list's own ring does (WCAG 2.4.7). The outline\n // is hidden only while focused, so forced colors still draw one (C-FOCUS).\n listbox.activeValue === null || activeOutOfView ? focusRing : 'focus:outline-hidden',\n // Disabled: the options take no pointer input (inherited by the options of a group), so\n // none hovers and the list's own not-allowed cursor shows over them.\n disabled && 'cursor-not-allowed opacity-50 *:pointer-events-none',\n className,\n )}\n >\n {multiselect && <PickerAnnouncer />}\n <ListboxProvider value={listbox.context}>{children}</ListboxProvider>\n {/* Inside the list: a focused hidden input hands focus back to its parent element. */}\n <HiddenInput\n name={name}\n form={form}\n disabled={disabled}\n value={multiselect ? values : (values[0] ?? '')}\n type=\"text\"\n required={required ?? field?.required ?? false}\n onInvalid={() => listRef.current?.focus()}\n />\n </ul>\n );\n};\nListboxRoot.displayName = 'Listbox';\n\n/** Flat name of `Listbox.Option` for React Server Components. */\nexport const ListboxOption = Option;\n/** Flat name of `Listbox.OptionGroup` for React Server Components. */\nexport const ListboxOptionGroup = OptionGroup;\n\n/**\n * A list of options that holds focus itself (APG listbox): one `<ul role=\"listbox\">` of\n * `Option`s, whose `aria-activedescendant` points at the active option while the list has focus.\n * It is the picker option model shown in the page — typeahead, groups, disabled options and the\n * option look of Dropdown and Combobox. Use `List` with `selectable` (`selectionMode`) instead\n * when each item needs real focus, actions of its own or interactive content.\n *\n * - **Focus.** One tab stop. The active option exists only while the list has focus, and a\n * switch to another window keeps it: the selected option (with `multiselect`, the first\n * selected one in list order), else the first. While no option can be active (an empty list,\n * every option hidden, or every option disabled without `disabledOptionsFocusable`), and while\n * the active option is scrolled out of the list's view, the list draws its own focus ring. A\n * press on an option with the primary button focuses the list and makes that option active\n * without scrolling, so the click selects it even while the selected option is scrolled out of\n * view; a right or middle press is left to the browser. `autoFocus` focuses the list when it\n * mounts.\n * - **Keys.** ArrowDown and ArrowUp move without wrapping, Home and End go to the first and last\n * option, PageUp and PageDown move ten options, and typing moves to the matching option\n * (typeahead). Space and Enter select the active option: the selection does not follow the\n * active option. Tab, Escape and Alt+Arrow keys are left to the page, so an enclosing Dialog\n * closes on Escape.\n * - **Selection.** `value`, `defaultValue` and `onValueChange` are Fluent's `selectedOptions`,\n * `defaultSelectedOptions` and `onOptionSelect` under WaveUI's value naming. A single-select\n * Listbox keeps the selected option when it is selected again (no deselection). `multiselect`\n * turns the value into an array: options draw a checkbox, Space, Enter and a click toggle an\n * option, the value keeps selection order, and every toggle the user makes is announced\n * (`labels.added`/`labels.removed`; never a controlled change or a form reset). A non-literal\n * `multiselect={flag}` is a type error: render two elements, one for each mode.\n * - **Disabled.** `disabled` takes the list out of the tab order (a click does not focus it\n * either), dims it, takes pointer input off its options, selects nothing and submits nothing.\n * Disabled options are skipped by the keys unless `disabledOptionsFocusable`, and are never\n * selected.\n * - **Forms and Field.** With `name` the value is submitted with its form (one entry, or one per\n * value with `multiselect`), and `required` needs a value (native validation; a missing value\n * moves focus to the list). A reset of its form restores `defaultValue`, with or without a\n * `name` (a `multiselect` reset is compared by content, so restoring the same values reports\n * nothing). Inside a `Field` the list is labelled by its label, described by its message and\n * hint, and takes its invalid and required state; otherwise name it with `aria-label` or\n * `aria-labelledby` (development warns once when it has no name).\n * - It has no built-in height: give it one through `className` and it scrolls.\n *\n * Every prop, the `ref` and the handlers go to the `<ul>`. Sub-components: `Listbox.Option`,\n * `Listbox.OptionGroup`. React Server Components import the flat names `ListboxOption` /\n * `ListboxOptionGroup` (dotted access needs a client file).\n *\n * @example\n * <Listbox aria-label=\"Fruit\" name=\"fruit\" defaultValue=\"banana\">\n * <Listbox.Option value=\"apple\">Apple</Listbox.Option>\n * <Listbox.Option value=\"banana\">Banana</Listbox.Option>\n * </Listbox>\n */\nexport const Listbox = /* @__PURE__ */ Object.assign(ListboxRoot, {\n Option,\n OptionGroup,\n}) as ListboxComponent;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuIA,IAAMC,KACJ,qHAIIC,KAAsB;CAAE,iBAAiB;CAAM,iBAAiB;AAAG,GAEnEC,KAAe,MAAiC;CACpD,IAAM,EACJ,iBAAc,IACd,OAAOC,GACP,iBACA,kBACA,yBACA,cA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E;CACA;AACF,CAAC"}
1
+ {"version":3,"file":"Listbox.mjs","names":["React","UNNAMED_WARNING","DISABLED_ATTRIBUTES","ListboxRoot","valueProp","ariaLabel","ariaLabelledBy","ariaDescribedBy","ariaInvalid","ariaRequired","rest","props","field","useFieldContext","fieldProps","useFieldControl","required","value","setValue","useControllable","defaultValue","multiselect","EMPTY_VALUES","next","values","toValues","focused","setFocused","listRef","isClient","useIsClient","autoFocusHandledRef","list","autoFocus","disabled","isFocused","activeWindow","items","virtualWindow","listbox","useListbox","index","updated","toggleValue","announceToggle","labels","details","added","onActiveOptionChange","listElementRef","listProps","mergedRef","useMergedRefs","ref","activeId","activeOutOfView","setActiveOutOfView","observedId","setObservedId","option","el","observer","entry","entries","useFormReset","resetValues","current","form","unnamed","warnOnce","useItemsAndChildrenWarning","children","useDataModeWarnings","handleKeyDown","isOwnEvent","event","handleFocus","handleBlur","optionsState","composeEventHandlers","onKeyDown","onKeyUp","onFocus","onBlur","cn","listboxClassNames","focusRing","className","PickerAnnouncer","ListboxProvider","renderListboxWindow","renderListboxItems","HiddenInput","ListboxOption","Option","ListboxOptionGroup","OptionGroup","Listbox"],"sources":["../../../src/components/input/Listbox.tsx"],"sourcesContent":["import * as React from 'react';\nimport { listboxClassNames } from '../../lib/classNames';\nimport { cn } from '../../lib/cn';\nimport { composeEventHandlers } from '../../lib/composeEventHandlers';\nimport { warnOnce } from '../../lib/dev';\nimport { isOwnEvent } from '../../lib/events';\nimport { isFocused } from '../../lib/focus';\nimport { focusRing } from '../../lib/styles';\nimport { useControllable } from '../../hooks/useControllable';\nimport { useFieldContext, useFieldControl } from '../../hooks/useFieldControl';\nimport { useFormReset } from '../../hooks/useFormReset';\nimport { useIsClient } from '../../hooks/useIsClient';\nimport { useListbox, type ListboxItem } from '../../hooks/useListbox';\nimport { useMergedRefs } from '../../hooks/useMergedRefs';\nimport type { VirtualWindow } from '../../hooks/useVirtualWindow';\nimport { HiddenInput } from '../internal/HiddenInput';\nimport { ListboxProvider, Option, OptionGroup, type ListboxOptionRenderState } from './Option';\nimport {\n renderListboxItems,\n renderListboxWindow,\n useDataModeWarnings,\n useItemsAndChildrenWarning,\n} from './Option.data';\nimport { announceToggle, PickerAnnouncer } from './pickerLabels';\nimport { EMPTY_VALUES, resetValues, toggleValue, toValues } from './pickerValues';\n\n/* ------------------------------------------------------------------ */\n/* Listbox */\n/* ------------------------------------------------------------------ */\n\n/**\n * The Listbox's built-in texts, for localization: the announcements of a `multiselect` toggle.\n * Each member is optional and falls back to its English default.\n */\nexport interface ListboxLabels {\n /**\n * Announced when a `multiselect` toggle selects an option; `count` is the number of values\n * selected after the change.\n * @default (label, count) => `${label} added, ${count} selected`\n */\n added?: (label: string, count: number) => string;\n /**\n * Announced when a `multiselect` toggle deselects an option; `count` is the number of values\n * selected after the change.\n * @default (label, count) => `${label} removed, ${count} selected`\n */\n removed?: (label: string, count: number) => string;\n}\n\n/** Properties for the Listbox component. */\nexport interface ListboxProps<M extends boolean = false> extends Omit<\n React.HTMLAttributes<HTMLUListElement>,\n 'onChange' | 'defaultValue'\n> {\n /**\n * Several options can be selected (Fluent's `multiselect`; List's `selectionMode=\"multiple\"` is\n * the other widget): the value is an array, options draw a checkbox, Space, Enter and a click\n * toggle an option, and each toggle is announced. A non-literal `multiselect={flag}` is a type\n * error: render two elements, one for each mode.\n * @default false\n */\n multiselect?: M;\n /**\n * Controlled selected value (`''` for none), or with `multiselect` the selected values in\n * selection order (Fluent's `selectedOptions`).\n */\n value?: M extends true ? readonly string[] : string;\n /**\n * Initial selected value for uncontrolled usage, which a form reset restores.\n * @default '' (`[]` with `multiselect`)\n */\n defaultValue?: M extends true ? readonly string[] : string;\n /**\n * Called with the new value when it changes (a new array with `multiselect`; Fluent's\n * `onOptionSelect`, under WaveUI's value/onValueChange naming). In single-select mode, selecting\n * the selected option again changes nothing: the Listbox never deselects it.\n */\n onValueChange?: M extends true ? (value: string[]) => void : (value: string) => void;\n /**\n * Called after the active (highlighted) option changes — focus, arrow keys, typeahead, the\n * pointer — and with `null` when focus leaves the list (a switch to another window keeps the\n * active option). It reports what `aria-activedescendant` points at, from an effect once the\n * change commits. Fluent's `onActiveOptionChange` reports neither the pointer (its options have\n * no hover highlight) nor the loss of focus.\n */\n onActiveOptionChange?: (value: string | null) => void;\n /**\n * Takes the list out of the tab order (a click does not focus it either, as a disabled native\n * `<select>`) and dims it: its options take no pointer input, nothing can be selected, and\n * nothing is submitted or validated. Renders `aria-disabled` and `data-disabled`. An\n * `aria-disabled` of your own without `disabled` is passed through as it is: the list stays\n * interactive.\n * @default false\n */\n disabled?: boolean;\n /**\n * Focuses the list when it mounts in the browser (React focuses only form controls itself), not\n * while `disabled`. Server-rendered HTML carries the `autofocus` attribute for the browser's own\n * autofocus, so a hydrating list takes no focus, as React leaves a hydrated form control alone.\n * @default false\n */\n autoFocus?: boolean;\n /**\n * Keeps disabled options in the arrow-key, Home/End, PageUp/PageDown and typeahead order (the\n * option that is active on focus may then be a disabled one too); they still cannot be\n * selected (Space, Enter and a click do nothing). Unlike Fluent, which always keeps disabled\n * options reachable, WaveUI skips them by default.\n * @default false\n */\n disabledOptionsFocusable?: boolean;\n /** The `multiselect` toggle announcements, for localization. Unset members keep their English defaults. */\n labels?: ListboxLabels;\n /**\n * Data mode: the options as data, in list order (`value`, `label`, and optionally `textValue`,\n * `disabled` and `hidden`; values unique). The list renders one option per item that is not\n * `hidden` (see `renderOption`), and the keys, typeahead and the selection follow `items`. The\n * children are neither read nor rendered: passing both warns once in development. Each option\n * gets `aria-posinset` and `aria-setsize` from its place among the shown items, and keeps one id\n * per value. Without it, the options are the `Option` children.\n */\n items?: readonly ListboxItem[];\n /**\n * Data mode: renders the option of an item, given its state (`selected`, `active`, and `index`\n * among the shown options). Return an `Option`, or an option component of your own on\n * `useListboxOption`, with the item's `value` (and its `disabled`); its position is set for you,\n * and in a windowed list (`virtualWindow`) its height. It is called again only when the item, its\n * state, its position (`aria-posinset` and `aria-setsize`, which new `items` change) or the\n * function itself changes, so pass a stable function in a long list. Ignored without `items`,\n * with a development warning.\n * @default an `Option` with the item's `value`, `label` (also its text), `textValue` and `disabled`\n */\n renderOption?: (item: ListboxItem, state: ListboxOptionRenderState) => React.ReactNode;\n /**\n * Data mode: renders only the options in view of a long list, plus an overscan, and spacers\n * (`aria-hidden`, `data-virtual-spacer`) as tall as the options they stand for: pass the result\n * of `useVirtualWindow({ itemSize })`, or an object of your own that implements `VirtualWindow`.\n * It needs `items`: without them, or beside `OptionGroup` children, it is ignored with a\n * development warning (a window renders a flat list).\n *\n * The list element is the window's scroller: give it a bounded height (a height or a maximum\n * height, through `className` or `style`); without one the window measures the whole list and\n * renders every option. While windowed the list has no block padding (add none through\n * `className`), so the options start at its top, where the window counts them, and no scroll\n * anchoring of the browser (the window lays the options out). Every option is exactly\n * `itemSize` tall (the list sets its height, after the option's own `style`), so an option's\n * content must fit in it: the default `Option` with one line of text is 32 pixels tall.\n *\n * The window counts the shown options (the items that are not `hidden`). The keys and typeahead\n * move over all of them (Home and End to the first and the last, PageUp and PageDown by ten); the\n * active option stays rendered while it is scrolled away, so `aria-activedescendant` always names\n * an element, and when the list gains focus or a key makes it active the list and the window\n * move to it in the same update (a pointer press moves neither). The server renders the first\n * window.\n */\n virtualWindow?: VirtualWindow;\n /**\n * Name of the value in form submissions (renders a hidden input inside the list; one per value\n * with `multiselect`).\n */\n name?: string;\n /** Id of the form the value belongs to, when the Listbox is outside it. */\n form?: string;\n /**\n * A value is required to submit the form (native constraint validation); when validation finds\n * it empty, focus moves to the list.\n */\n required?: boolean;\n /**\n * Called on a key press on the list, before the built-in keys; `event.preventDefault()` skips\n * them.\n */\n onKeyDown?: React.KeyboardEventHandler<HTMLUListElement>;\n /** Ref to the `<ul role=\"listbox\">`. */\n ref?: React.Ref<HTMLUListElement>;\n}\n\n/** The Listbox component's type: a multi-select signature, then the single-select one. */\nexport interface ListboxComponent {\n (props: ListboxProps<true> & { multiselect: true }): React.ReactNode;\n (props: ListboxProps): React.ReactNode;\n displayName?: string;\n Option: typeof Option;\n OptionGroup: typeof OptionGroup;\n}\n\nconst UNNAMED_WARNING =\n 'Listbox: the listbox has no accessible name. Pass `aria-label` or `aria-labelledby`, or ' +\n 'render it inside a Field.';\n\n/** The state attributes of a disabled list, rendered only while `disabled` (C-DISABLED). */\nconst DISABLED_ATTRIBUTES = { 'aria-disabled': true, 'data-disabled': '' } as const;\n\nconst ListboxRoot = (props: ListboxProps<boolean>) => {\n const {\n multiselect = false,\n value: valueProp,\n defaultValue,\n onValueChange,\n onActiveOptionChange,\n disabled = false,\n disabledOptionsFocusable = false,\n autoFocus = false,\n labels,\n items,\n renderOption,\n virtualWindow,\n name,\n form,\n required,\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired,\n onFocus,\n onBlur,\n onKeyDown,\n onKeyUp,\n className,\n children,\n ref,\n ...rest\n } = props;\n\n const field = useFieldContext();\n // `<label for>` does not reach a listbox, so a Field names it through aria-labelledby. An\n // explicit `required={false}` wins over a required Field, so aria-required matches the native\n // requirement below.\n const fieldProps = useFieldControl(\n {\n id,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired ?? required,\n },\n { labelable: false },\n );\n\n const [value, setValue] = useControllable<string | readonly string[]>(\n valueProp,\n defaultValue ?? (multiselect ? EMPTY_VALUES : ''),\n (next) => {\n // The two call signatures make `onValueChange` a union of incompatible functions from here:\n // the root itself is written against the wider, internal shape (D9).\n (onValueChange as ((value: string | string[]) => void) | undefined)?.(\n typeof next === 'string' ? next : [...next],\n );\n },\n );\n // Normalised for the listbox, the hidden inputs and the reset: a single value is its own\n // one-element array, and a `value` passed as `null` from JavaScript is none rather than a crash.\n const values = toValues(value);\n\n // The focus of the list itself (not of anything inside it): an option is active only while the\n // list has focus, so its outline never shows on a list the user is not in (D17).\n const [focused, setFocused] = React.useState(false);\n const listRef = React.useRef<HTMLUListElement | null>(null);\n const isClient = useIsClient();\n // Whether the mount's autoFocus was handled: a later change never focuses the list.\n const autoFocusHandledRef = React.useRef(false);\n\n // The focus state follows the DOM, not only focus events, on mount, once hydrated and whenever\n // `disabled` changes: a list focused before hydration (a tab, the browser's autofocus) has focus\n // without a focus event React saw, and a browser that moves focus off a list whose tab stop went\n // away fires no blur. React focuses only form controls for `autoFocus`, so a list mounted in the\n // browser focuses itself; a hydrating one leaves focus where it is, as React does for a control.\n React.useLayoutEffect(() => {\n const list = listRef.current;\n if (!list) return;\n if (!autoFocusHandledRef.current) {\n autoFocusHandledRef.current = true;\n if (autoFocus && !disabled && isClient) list.focus();\n }\n setFocused(!disabled && isFocused(list));\n }, [autoFocus, disabled, isClient]);\n\n // A window renders data mode only; the list is its scroller.\n const activeWindow = items === undefined ? undefined : virtualWindow;\n\n const listbox = useListbox({\n open: focused && !disabled,\n mode: 'standalone',\n multiselect,\n selectedValues: values,\n // APG listbox: the arrows stop at the ends.\n loop: false,\n disabledOptionsFocusable,\n items,\n // An active option that the window does not render (an adapter that keeps nothing): scrolled\n // to by its index among the shown options, the window's count.\n onScrollToItem: activeWindow\n ? (index) => activeWindow.scrollToIndex(index, { align: 'auto' })\n : undefined,\n onSelect: (next, details) => {\n if (disabled) return;\n if (!multiselect) {\n // Selecting the selected option again is no change: useControllable skips it.\n setValue(next);\n return;\n }\n const { values: updated, added } = toggleValue(values, next);\n setValue(updated);\n // A toggle the user made (D41): a controlled change and a form reset never reach this\n // callback. `details` carries the registered option (or the item), whose label is its text.\n announceToggle(labels, details?.item.label ?? next, added, updated.length);\n },\n onActiveValueChange: onActiveOptionChange,\n idPrefix: 'listbox',\n });\n // The hook's ref must reach the list: a pointer press on an option focuses the list through it.\n const { ref: listElementRef, ...listProps } = listbox.getListboxProps();\n const mergedRef = useMergedRefs<HTMLUListElement>(\n ref,\n listRef,\n listElementRef,\n activeWindow?.scrollRef,\n );\n\n // The active option's outline shows focus only while the option is in the list's view: scrolled\n // away (the wheel, a smaller list), the list draws its own ring as well (WCAG 2.4.7). A new active\n // option counts as shown until the browser reports otherwise, since the keys scroll it into view\n // (adjust-during-render pattern, C-HOOKS); without IntersectionObserver nothing is observed.\n const activeId = listProps['aria-activedescendant'];\n const [activeOutOfView, setActiveOutOfView] = React.useState(false);\n const [observedId, setObservedId] = React.useState(activeId);\n if (observedId !== activeId) {\n setObservedId(activeId);\n setActiveOutOfView(false);\n }\n React.useEffect(() => {\n const list = listRef.current;\n if (activeId === undefined || !list || typeof IntersectionObserver === 'undefined') return;\n const option = Array.from(list.querySelectorAll('[role=\"option\"]')).find(\n (el) => el.id === activeId,\n );\n if (!option) return;\n const observer = new IntersectionObserver(\n (entries) => {\n const entry = entries[entries.length - 1];\n if (entry) setActiveOutOfView(!entry.isIntersecting);\n },\n { root: list },\n );\n observer.observe(option);\n return () => observer.disconnect();\n }, [activeId]);\n\n useFormReset(\n listRef,\n () => {\n if (!multiselect) {\n setValue(defaultValue ?? '');\n return;\n }\n // Compared by content (C-FORMS), so a reset that keeps the same values reports nothing.\n setValue((current) => resetValues(current, defaultValue));\n },\n form,\n );\n\n // C-DEV: a listbox needs a name; a blank one names nothing.\n const unnamed = !fieldProps['aria-label']?.trim() && !fieldProps['aria-labelledby']?.trim();\n React.useEffect(() => {\n if (unnamed) warnOnce('Listbox:unnamed', UNNAMED_WARNING);\n }, [unnamed]);\n useItemsAndChildrenWarning('Listbox', items, children);\n useDataModeWarnings('Listbox', { items, renderOption, virtualWindow, children });\n\n // C-COMPOSE: keys typed in a portal rendered inside the list bubble through it in React; they\n // are not the list's.\n const handleKeyDown = (event: React.KeyboardEvent<HTMLUListElement>) => {\n if (disabled || !isOwnEvent(event)) return;\n listbox.onKeyDown(event);\n };\n // Only the list's own focus counts: focus inside a portal rendered in it, or on its hidden\n // input (which hands focus back to the list), is not the list's.\n const handleFocus = (event: React.FocusEvent<HTMLUListElement>) => {\n if (event.target === event.currentTarget) setFocused(true);\n };\n // A switch to another window blurs the list but leaves it the active element, so the list keeps\n // its active option for the return, as a native `<select size>` keeps its keyboard position;\n // focus that moves elsewhere in the page changes the active element before the blur.\n const handleBlur = (event: React.FocusEvent<HTMLUListElement>) => {\n const list = event.currentTarget;\n if (event.target === list && !isFocused(list)) setFocused(false);\n };\n\n // What every option of data mode is drawn from, besides its item.\n const optionsState = {\n selected: new Set(values),\n activeValue: listbox.activeValue,\n renderOption,\n };\n\n return (\n <ul\n {...rest}\n {...fieldProps}\n {...listProps}\n // The consumer's id (or the Field's control id), else the hook's; the option ids keep the\n // hook's prefix.\n id={fieldProps.id ?? listProps.id}\n tabIndex={disabled ? undefined : listProps.tabIndex}\n aria-activedescendant={listProps['aria-activedescendant']}\n aria-multiselectable={listProps['aria-multiselectable']}\n // Rendered only while disabled, so a consumer `aria-disabled` on an enabled list passes\n // through as it is (C-DISABLED: the list stays interactive).\n {...(disabled ? DISABLED_ATTRIBUTES : undefined)}\n // The server renders the `autofocus` attribute for the browser; the effect above focuses a\n // list mounted in the browser. Without autoFocus the prop stays out of hydration's check.\n autoFocus={autoFocus || undefined}\n ref={mergedRef}\n onKeyDown={composeEventHandlers(onKeyDown, handleKeyDown)}\n onKeyUp={composeEventHandlers(onKeyUp, listbox.onKeyUp)}\n // Bookkeeping that mirrors the DOM: it runs even when a consumer handler prevents the event.\n onFocus={composeEventHandlers(onFocus, handleFocus, { checkDefaultPrevented: false })}\n onBlur={composeEventHandlers(onBlur, handleBlur, { checkDefaultPrevented: false })}\n className={cn(\n listboxClassNames.root,\n // The list's own margin, padding and markers are set here, not left to the native reset\n // (C-NATIVE).\n 'relative m-0 flex list-none flex-col overflow-y-auto px-0 py-1 text-foreground',\n // The active option's outline shows focus; while no option can be active (an empty list,\n // every option hidden, or every option disabled without disabledOptionsFocusable), or the\n // active one is scrolled out of view, the list's own ring does (WCAG 2.4.7). The outline\n // is hidden only while focused, so forced colors still draw one (C-FOCUS).\n listbox.activeValue === null || activeOutOfView ? focusRing : 'focus:outline-hidden',\n // Disabled: the options take no pointer input (inherited by the options of a group), so\n // none hovers and the list's own not-allowed cursor shows over them.\n disabled && 'cursor-not-allowed opacity-50 *:pointer-events-none',\n // Windowed: the options start at the top of the scroller, where the window counts them,\n // and the window lays them out (the browser's scroll anchoring only fights it).\n activeWindow && 'py-0 [overflow-anchor:none]',\n className,\n )}\n >\n {multiselect && <PickerAnnouncer />}\n <ListboxProvider value={listbox.context}>\n {/* Data mode: the options of the shown items, or the window's; the children are ignored. */}\n {items === undefined\n ? children\n : activeWindow\n ? renderListboxWindow(\n listbox.items,\n activeWindow,\n optionsState,\n listboxClassNames.spacer,\n )\n : renderListboxItems(listbox.items, optionsState)}\n </ListboxProvider>\n {/* Inside the list: a focused hidden input hands focus back to its parent element. */}\n <HiddenInput\n name={name}\n form={form}\n disabled={disabled}\n value={multiselect ? values : (values[0] ?? '')}\n type=\"text\"\n required={required ?? field?.required ?? false}\n onInvalid={() => listRef.current?.focus()}\n />\n </ul>\n );\n};\nListboxRoot.displayName = 'Listbox';\n\n/** Flat name of `Listbox.Option` for React Server Components. */\nexport const ListboxOption = Option;\n/** Flat name of `Listbox.OptionGroup` for React Server Components. */\nexport const ListboxOptionGroup = OptionGroup;\n\n/**\n * A list of options that holds focus itself (APG listbox): one `<ul role=\"listbox\">` of\n * `Option`s, whose `aria-activedescendant` points at the active option while the list has focus.\n * It is the picker option model shown in the page — typeahead, groups, disabled options and the\n * option look of Dropdown and Combobox. Use `List` with `selectable` (`selectionMode`) instead\n * when each item needs real focus, actions of its own or interactive content.\n *\n * - **Focus.** One tab stop. The active option exists only while the list has focus, and a\n * switch to another window keeps it: the selected option (with `multiselect`, the first\n * selected one in list order), else the first. While no option can be active (an empty list,\n * every option hidden, or every option disabled without `disabledOptionsFocusable`), and while\n * the active option is scrolled out of the list's view, the list draws its own focus ring. A\n * press on an option with the primary button focuses the list and makes that option active\n * without scrolling, so the click selects it even while the selected option is scrolled out of\n * view; a right or middle press is left to the browser. `autoFocus` focuses the list when it\n * mounts.\n * - **Keys.** ArrowDown and ArrowUp move without wrapping, Home and End go to the first and last\n * option, PageUp and PageDown move ten options, and typing moves to the matching option\n * (typeahead). Space and Enter select the active option: the selection does not follow the\n * active option. Tab, Escape and Alt+Arrow keys are left to the page, so an enclosing Dialog\n * closes on Escape.\n * - **Selection.** `value`, `defaultValue` and `onValueChange` are Fluent's `selectedOptions`,\n * `defaultSelectedOptions` and `onOptionSelect` under WaveUI's value naming. A single-select\n * Listbox keeps the selected option when it is selected again (no deselection). `multiselect`\n * turns the value into an array: options draw a checkbox, Space, Enter and a click toggle an\n * option, the value keeps selection order, and every toggle the user makes is announced\n * (`labels.added`/`labels.removed`; never a controlled change or a form reset). A non-literal\n * `multiselect={flag}` is a type error: render two elements, one for each mode.\n * - **Disabled.** `disabled` takes the list out of the tab order (a click does not focus it\n * either), dims it, takes pointer input off its options, selects nothing and submits nothing.\n * Disabled options are skipped by the keys unless `disabledOptionsFocusable`, and are never\n * selected.\n * - **Data mode.** `items` passes the options as data instead of children: the list renders an\n * option per item (`renderOption` draws it, an `Option` with the item's label by default), the\n * keys, typeahead and the selection follow the data, and each option carries `aria-posinset`\n * and `aria-setsize`. A long list takes a `virtualWindow` (from `useVirtualWindow({ itemSize\n * })`): the list then renders only the options in view, plus an overscan, with spacers for the\n * others, every option `itemSize` tall, and the active option stays rendered.\n * - **Forms and Field.** With `name` the value is submitted with its form (one entry, or one per\n * value with `multiselect`), and `required` needs a value (native validation; a missing value\n * moves focus to the list). A reset of its form restores `defaultValue`, with or without a\n * `name` (a `multiselect` reset is compared by content, so restoring the same values reports\n * nothing). Inside a `Field` the list is labelled by its label, described by its message and\n * hint, and takes its invalid and required state; otherwise name it with `aria-label` or\n * `aria-labelledby` (development warns once when it has no name).\n * - It has no built-in height: give it one through `className` and it scrolls.\n *\n * Every prop, the `ref` and the handlers go to the `<ul>`. Sub-components: `Listbox.Option`,\n * `Listbox.OptionGroup`. React Server Components import the flat names `ListboxOption` /\n * `ListboxOptionGroup` (dotted access needs a client file).\n *\n * @example\n * <Listbox aria-label=\"Fruit\" name=\"fruit\" defaultValue=\"banana\">\n * <Listbox.Option value=\"apple\">Apple</Listbox.Option>\n * <Listbox.Option value=\"banana\">Banana</Listbox.Option>\n * </Listbox>\n *\n * @example\n * // Data mode\n * <Listbox aria-label=\"City\" items={cities.map((c) => ({ value: c.id, label: c.name }))} />\n */\nexport const Listbox = /* @__PURE__ */ Object.assign(ListboxRoot, {\n Option,\n OptionGroup,\n}) as ListboxComponent;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyLA,IAAMC,KACJ,qHAIIC,KAAsB;CAAE,iBAAiB;CAAM,iBAAiB;AAAG,GAEnEC,KAAe,MAAiC;CACpD,IAAM,EACJ,iBAAc,IACd,OAAOC,GACP,iBACA,kBACA,yBACA,cAAW,IACX,8BAA2B,IAC3B,eAAY,IACZ,WACA,UACA,iBACA,kBACA,SACA,SACA,aACA,OACA,cAAcC,GACd,mBAAmBC,GACnB,oBAAoBC,GACpB,gBAAgBC,GAChB,iBAAiBC,GACjB,YACA,WACA,eACA,aACA,eACA,aACA,SACA,GAAGC,OACDC,GAEEC,KAAQC,GAAgB,GAIxBC,IAAaC,GACjB;EACE;EACA,cAAcV;EACd,mBAAmBC;EACnB,oBAAoBC;EACpB,gBAAgBC;EAChB,iBAAiBC,KAAgBO;CACnC,GACA,EAAE,WAAW,GAAM,CACrB,GAEM,CAACC,IAAOC,KAAYC,EACxBf,GACAgB,MAAiBC,IAAcC,KAAe,MAC7C,MAAS;EAGR,IACE,OAAOC,KAAS,WAAWA,IAAO,CAAC,GAAGA,CAAI,CAC5C;CACF,CACF,GAGMC,IAASC,GAASR,EAAK,GAIvB,CAACS,IAASC,KAAc3B,EAAM,SAAS,EAAK,GAC5C4B,IAAU5B,EAAM,OAAgC,IAAI,GACpD6B,IAAWC,GAAY,GAEvBC,IAAsB/B,EAAM,OAAO,EAAK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IpC,EAAW,MAAMoC,EAAU;EAC/B,UAAUhB,IAAW,KAAA,IAAYgB,EAAU;EAC3C,yBAAuBA,EAAU;EACjC,wBAAsBA,EAAU;EAGhC,GAAKhB,IAAWhC,KAAsB,KAAA;EAGtC,WAAW+B,KAAa,KAAA;EACxB,KAAKkB;EACL,WAAW4B,EAAqBC,IAAWP,EAAa;EACxD,SAASM,EAAqBE,IAAS1C,EAAQ,OAAO;EAEtD,SAASwC,EAAqBG,GAASN,IAAa,EAAE,uBAAuB,GAAM,CAAC;EACpF,QAAQG,EAAqBI,GAAQN,IAAY,EAAE,uBAAuB,GAAM,CAAC;EACjF,WAAWO,EACTC,EAAkB,MAGlB,kFAKA9C,EAAQ,gBAAgB,QAAQgB,KAAkB+B,KAAY,wBAG9DpD,KAAY,uDAGZE,KAAgB,+BAChBmD,EACF;EAvCF,UAAA;GAyCGlE,KAAe,kBAACmE,IAAD,CAAkB,CAAA;GAClC,kBAACC,GAAD;IAAiB,OAAOlD,EAAQ;IAE7B,UAAAF,MAAU,KAAA,IACPkC,IACAnC,IACEsD,EACEnD,EAAQ,OACRH,GACA0C,GACAO,EAAkB,MACpB,IACAM,EAAmBpD,EAAQ,OAAOuC,CAAY;GACrC,CAAA;GAEjB,kBAACc,GAAD;IACQ;IACA;IACI;IACV,OAAOvE,IAAcG,IAAUA,EAAO,MAAM;IAC5C,MAAK;IACL,UAAUR,KAAYJ,IAAO,YAAY;IACzC,iBAAiBgB,EAAQ,SAAS,MAAM;GACzC,CAAA;EACC;;AAER;AACA,EAAY,cAAc;AAG1B,IAAaiE,IAAgBC,GAEhBC,IAAqBC,GA+DrBC,IAA0B,uBAAO,OAAO9F,GAAa;CAChE;CACA;AACF,CAAC"}
@@ -1,2 +1,2 @@
1
- "use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/dev.cjs"),r=require("../../lib/slot.cjs"),i=require("../../lib/composeEventHandlers.cjs"),a=require("../../lib/classNames.cjs"),o=require("../../hooks/useId.cjs"),s=require("../../hooks/useMergedRefs.cjs"),c=require("../../hooks/useListbox.cjs"),l=require("../../hooks/usePopupPosition.cjs"),u=require("../../hooks/useDismiss.cjs"),d=require("../../lib/styles.cjs"),f=require("../portal/Portal.cjs"),p=require("../../lib/icons.cjs");let m=require("react");m=e.__toESM(m,1);let h=require("react/jsx-runtime");var g=m.createContext(!0);g.displayName=`OptionCheckContext`;var _=t.cn(`flex cursor-pointer select-none items-center gap-2 px-3 py-1.5 text-body-1 text-foreground`,`bg-(--option-bg) [--option-bg:transparent]`,`not-disabled:not-aria-disabled:hover:[--option-bg:var(--wave-subtle-hover)]`,`data-[selected]:[--option-bg:var(--wave-subtle-selected)]`,`data-[active]:[--option-bg:var(--wave-subtle-hover)]`,`data-[active]:outline-2 data-[active]:-outline-offset-2 data-[active]:outline-ring`,`aria-disabled:cursor-not-allowed aria-disabled:text-muted-foreground`),v=class{counts=new Map;listeners=new Set;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});add(e){return this.counts.set(e,(this.counts.get(e)??0)+1),this.notify(),()=>{let t=(this.counts.get(e)??1)-1;t>0?this.counts.set(e,t):this.counts.delete(e),this.notify()}}allHidden(e){if(e===void 0||this.counts.size===0)return!1;for(let t of this.counts.keys())if(!e.isHidden(t))return!1;return!0}notify(){for(let e of[...this.listeners])e()}},y=m.createContext([]);y.displayName=`OptionGroupContext`;var b=m.createContext(!1);b.displayName=`OptionGroupHiddenContext`;function x(e){let t=m.useContext(y);m.useLayoutEffect(()=>{if(t.length===0)return;let n=t.map(t=>t.add(e));return()=>{for(let e of n)e()}},[t,e])}var S=`forced-colors:border-[GrayText] forced-colors:bg-[Canvas]`,C=`forced-colors:text-[GrayText] forced-colors:forced-color-adjust-none`;function w(e,{selected:n,multiselect:i,disabled:o}){if(!i){let i=t.cn(a.optionClassNames.checkIcon,`shrink-0`,!n&&`invisible`);return e===void 0?(0,h.jsx)(p.CheckIcon,{className:i}):r.renderSlot(e,`span`,t.cn(`inline-flex`,i),{"aria-hidden":!0})}let s;s=o?t.cn(`border-current bg-transparent`,S):n?t.cn(`border-primary bg-primary text-primary-foreground`,d.forcedColors.selectedLeaf):t.cn(`border-stroke-accessible bg-transparent`,d.forcedColors.control);let c=o?C:void 0;return(0,h.jsx)(`span`,{"aria-hidden":`true`,"data-wave-option-box":``,className:t.cn(a.optionClassNames.indicator,`flex h-4 w-4 shrink-0 items-center justify-center rounded-xs border`,s),children:n&&(e===void 0?(0,h.jsx)(p.CheckIcon,{size:12,className:t.cn(a.optionClassNames.checkIcon,c)}):r.renderSlot(e,`span`,t.cn(a.optionClassNames.checkIcon,`inline-flex shrink-0`,c),{"aria-hidden":!0}))})}function T(e){let{value:o,label:s,textValue:l,disabled:u=!1,hidden:f=!1,checkIcon:p,className:v,children:y,onClick:S,onMouseDown:C,onPointerMove:T,ref:E,...D}=e,O=m.useContext(g),k=m.useContext(b),{selected:A,multiselect:j,optionProps:M}=c.useListboxOption({value:o,label:s,textValue:l,disabled:u,hidden:f||k},E);x(o);let{ref:N,onClick:P,onMouseDown:F,onPointerMove:I,...L}=M,R=p!=null&&r.slotRendersContent(p),z=p!=null&&!R;return m.useEffect(()=>{z&&n.warnOnce(`Option:checkIcon-empty`,"Option: `checkIcon` renders nothing, so the default check shows: a selected option must show its state. Pass a glyph, or leave it unset.")},[z]),(0,h.jsxs)(`li`,{"data-value":o,...D,...L,ref:N,onClick:i.composeEventHandlers(S,P),onMouseDown:i.composeEventHandlers(C,F),onPointerMove:i.composeEventHandlers(T,I),className:t.cn(a.optionClassNames.root,_,A&&!(j&&O)&&d.forcedColors.selectedContainer,v),children:[O&&w(R?p:void 0,{selected:A,multiselect:j,disabled:u}),(0,h.jsx)(`span`,{className:t.cn(a.optionClassNames.content,`min-w-0 flex-1`),children:y??o})]})}T.displayName=`Option`;var E=m.memo(T);E.displayName=`Option`;var D=c.markListboxElement(E,`option`),O=1,k=3;function A(e){if(e===null)return``;if(e.nodeType===k)return e.textContent??``;if(e.nodeType!==O)return``;let t=e;if(t.getAttribute(`aria-hidden`)===`true`||t.hasAttribute(`hidden`))return``;let n=t.getAttribute(`aria-label`)?.trim();if(n)return n;if(t.localName===`img`)return t.getAttribute(`alt`)??``;let r=``;for(let e of Array.from(t.childNodes))r+=A(e);return r}function j(e,t,n,r,i){return n!==void 0&&n!==r&&n.trim()!==``||t!==void 0&&t.trim()!==``?!0:n===r?typeof e==`string`||typeof e==`number`?String(e).trim()!==``:A(i).trim()!==``:!1}var M=`OptionGroup:unnamed`;function N({label:e,className:i,children:s,hidden:l,"aria-label":u,"aria-labelledby":d,ref:f,...p}){let g=o.useId(`option-group`),_=m.useContext(c.ListboxContext)?.store,x=m.useContext(y),S=m.useContext(b)||!!l,[C]=m.useState(()=>new v),w=m.useMemo(()=>[...x,C],[x,C]),T=m.useCallback(e=>{let t=C.subscribe(e),n=_?.subscribe(e);return()=>{t(),n?.()}},[C,_]),E=m.useSyncExternalStore(T,()=>C.allHidden(_),()=>!1),D=r.slotRendersContent(e),O=d??(u===void 0&&D?g:void 0),k=m.useRef(null);return m.useEffect(()=>{n.isDev&&!n.hasWarned(M)&&(j(e,u,O,g,k.current)||n.warnOnce(M,"OptionGroup: the group has no name. Give it a text `label`, `aria-label` or `aria-labelledby`."))},[e,u,O,g]),(0,h.jsxs)(`li`,{...p,ref:f,role:`presentation`,hidden:l||E||void 0,className:t.cn(a.optionGroupClassNames.root,i),children:[D&&(0,h.jsx)(`div`,{ref:k,id:g,role:`presentation`,className:t.cn(a.optionGroupClassNames.label,`px-3 py-1 text-caption-1 font-semibold text-muted-foreground`),children:r.materialiseSlotContent(e)}),(0,h.jsx)(`ul`,{role:`group`,"aria-label":u,"aria-labelledby":O,className:a.optionGroupClassNames.list,children:(0,h.jsx)(b.Provider,{value:S,children:(0,h.jsx)(y.Provider,{value:w,children:s})})})]})}N.displayName=`OptionGroup`;var P=c.markListboxElement(N,`group`);function F({value:e,children:t}){return(0,h.jsx)(c.ListboxContext.Provider,{value:e,children:t})}F.displayName=`ListboxProvider`;function I(e){let{open:t,surfaceOpen:n,onDismiss:r,rootRef:i,anchorRef:a,positioning:o}=e,c=m.useRef(null),{setReference:d,setFloating:f,floatingProps:p}=l.usePopupPosition({open:n,side:`bottom`,align:`start`,...l.resolvePositioning(o,{matchReferenceWidth:!0,fitViewport:!0})}),{layerId:h}=u.useDismiss({open:t,onDismiss:e=>r(e),refs:[i,c],anchorRef:a,kind:`listbox`,escape:n,focusOutside:!0});return{layerId:h,setReference:d,surfaceRef:s.useMergedRefs(c,f),floatingProps:p}}function L(e){e.preventDefault()}function R(e){let{listbox:n,layerId:r,surfaceRef:o,floatingProps:c,open:l,expanded:u,emptyContent:d,"aria-label":p,"aria-labelledby":m,showCheck:_=!0,listClassName:v,surfaceClassName:y,listProps:b,children:x}=e,{ref:S,onMouseDown:C,...w}=b??{},T=n.getListboxProps(),E=s.useMergedRefs(S,T.ref),D=(0,h.jsx)(g.Provider,{value:_,children:(0,h.jsx)(F,{value:n.context,children:(0,h.jsx)(`ul`,{...w,...T,"aria-multiselectable":T[`aria-multiselectable`],"aria-activedescendant":T[`aria-activedescendant`],onMouseDown:i.composeEventHandlers(C,T.onMouseDown),ref:E,"aria-label":p,"aria-labelledby":m,hidden:!u||void 0,className:t.cn(a.listboxSurfaceClassNames.list,`min-h-0 max-h-60 overflow-auto`,v),children:x})})});return!u&&(!l||u||d==null)?D:(0,h.jsxs)(h.Fragment,{children:[!u&&D,(0,h.jsx)(f.Portal,{layerId:r,children:(0,h.jsx)(`div`,{ref:o,...c,"data-wave-listbox-surface":``,onMouseDown:L,className:t.cn(a.listboxSurfaceClassNames.root,`flex flex-col overflow-hidden rounded border border-border bg-background py-1 text-foreground shadow-4`,y),children:u?D:d})})]})}R.displayName=`ListboxSurface`,exports.ListboxProvider=F,exports.ListboxSurface=R,exports.Option=D,exports.OptionGroup=P,exports.useListboxPopup=I;
1
+ "use client";const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../lib/cn.cjs"),n=require("../../lib/dev.cjs"),r=require("../../lib/slot.cjs"),i=require("../../lib/composeEventHandlers.cjs"),a=require("../../lib/classNames.cjs"),o=require("../../hooks/useId.cjs"),s=require("../../hooks/useMergedRefs.cjs"),c=require("../../hooks/useListbox.cjs"),l=require("../../hooks/usePopupPosition.cjs"),u=require("../../hooks/useDismiss.cjs"),d=require("../../lib/styles.cjs"),f=require("../portal/Portal.cjs"),p=require("../../lib/icons.cjs");let m=require("react");m=e.__toESM(m,1);let h=require("react/jsx-runtime");var g=m.createContext(!0);g.displayName=`OptionCheckContext`;var _=t.cn(`flex cursor-pointer select-none items-center gap-2 px-3 py-1.5 text-body-1 text-foreground`,`bg-(--option-bg) [--option-bg:transparent]`,`not-disabled:not-aria-disabled:hover:[--option-bg:var(--wave-subtle-hover)]`,`data-[selected]:[--option-bg:var(--wave-subtle-selected)]`,`data-[active]:[--option-bg:var(--wave-subtle-hover)]`,`data-[active]:outline-2 data-[active]:-outline-offset-2 data-[active]:outline-ring`,`aria-disabled:cursor-not-allowed aria-disabled:text-muted-foreground`),v=class{counts=new Map;listeners=new Set;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});add(e){return this.counts.set(e,(this.counts.get(e)??0)+1),this.notify(),()=>{let t=(this.counts.get(e)??1)-1;t>0?this.counts.set(e,t):this.counts.delete(e),this.notify()}}allHidden(e){if(e===void 0||this.counts.size===0)return!1;for(let t of this.counts.keys())if(!e.isHidden(t))return!1;return!0}notify(){for(let e of[...this.listeners])e()}},y=m.createContext([]);y.displayName=`OptionGroupContext`;var b=m.createContext(!1);b.displayName=`OptionGroupHiddenContext`;function x(e){let t=m.useContext(y);m.useLayoutEffect(()=>{if(t.length===0)return;let n=t.map(t=>t.add(e));return()=>{for(let e of n)e()}},[t,e])}var S=`forced-colors:border-[GrayText] forced-colors:bg-[Canvas]`,C=`forced-colors:text-[GrayText] forced-colors:forced-color-adjust-none`;function w(e,{selected:n,multiselect:i,disabled:o}){if(!i){let i=t.cn(a.optionClassNames.checkIcon,`shrink-0`,!n&&`invisible`);return e===void 0?(0,h.jsx)(p.CheckIcon,{className:i}):r.renderSlot(e,`span`,t.cn(`inline-flex`,i),{"aria-hidden":!0})}let s;s=o?t.cn(`border-current bg-transparent`,S):n?t.cn(`border-primary bg-primary text-primary-foreground`,d.forcedColors.selectedLeaf):t.cn(`border-stroke-accessible bg-transparent`,d.forcedColors.control);let c=o?C:void 0;return(0,h.jsx)(`span`,{"aria-hidden":`true`,"data-wave-option-box":``,className:t.cn(a.optionClassNames.indicator,`flex h-4 w-4 shrink-0 items-center justify-center rounded-xs border`,s),children:n&&(e===void 0?(0,h.jsx)(p.CheckIcon,{size:12,className:t.cn(a.optionClassNames.checkIcon,c)}):r.renderSlot(e,`span`,t.cn(a.optionClassNames.checkIcon,`inline-flex shrink-0`,c),{"aria-hidden":!0}))})}function T(e){let{value:o,label:s,textValue:l,disabled:u=!1,hidden:f=!1,checkIcon:p,className:v,style:y,children:S,onClick:C,onMouseDown:T,onPointerMove:E,ref:D,...O}=e,k=m.useContext(g),A=m.useContext(b),{selected:j,multiselect:M,optionProps:N}=c.useListboxOption({value:o,label:s,textValue:l,disabled:u,hidden:f||A},D);x(o);let{ref:P,onClick:F,onMouseDown:I,onPointerMove:L,style:R,...z}=N,B=p!=null&&r.slotRendersContent(p),V=p!=null&&!B;return m.useEffect(()=>{V&&n.warnOnce(`Option:checkIcon-empty`,"Option: `checkIcon` renders nothing, so the default check shows: a selected option must show its state. Pass a glyph, or leave it unset.")},[V]),(0,h.jsxs)(`li`,{"data-value":o,...O,...z,style:R?{...y,...R}:y,ref:P,onClick:i.composeEventHandlers(C,F),onMouseDown:i.composeEventHandlers(T,I),onPointerMove:i.composeEventHandlers(E,L),className:t.cn(a.optionClassNames.root,_,j&&!(M&&k)&&d.forcedColors.selectedContainer,v),children:[k&&w(B?p:void 0,{selected:j,multiselect:M,disabled:u}),(0,h.jsx)(`span`,{className:t.cn(a.optionClassNames.content,`min-w-0 flex-1`),children:S??o})]})}T.displayName=`Option`;var E=m.memo(T);E.displayName=`Option`;var D=c.markListboxElement(E,`option`),O=1,k=3;function A(e){if(e===null)return``;if(e.nodeType===k)return e.textContent??``;if(e.nodeType!==O)return``;let t=e;if(t.getAttribute(`aria-hidden`)===`true`||t.hasAttribute(`hidden`))return``;let n=t.getAttribute(`aria-label`)?.trim();if(n)return n;if(t.localName===`img`)return t.getAttribute(`alt`)??``;let r=``;for(let e of Array.from(t.childNodes))r+=A(e);return r}function j(e,t,n,r,i){return n!==void 0&&n!==r&&n.trim()!==``||t!==void 0&&t.trim()!==``?!0:n===r?typeof e==`string`||typeof e==`number`?String(e).trim()!==``:A(i).trim()!==``:!1}var M=`OptionGroup:unnamed`;function N({label:e,className:i,children:s,hidden:l,"aria-label":u,"aria-labelledby":d,ref:f,...p}){let g=o.useId(`option-group`),_=m.useContext(c.ListboxContext)?.store,x=m.useContext(y),S=m.useContext(b)||!!l,[C]=m.useState(()=>new v),w=m.useMemo(()=>[...x,C],[x,C]),T=m.useCallback(e=>{let t=C.subscribe(e),n=_?.subscribe(e);return()=>{t(),n?.()}},[C,_]),E=m.useSyncExternalStore(T,()=>C.allHidden(_),()=>!1),D=r.slotRendersContent(e),O=d??(u===void 0&&D?g:void 0),k=m.useRef(null);return m.useEffect(()=>{n.isDev&&!n.hasWarned(M)&&(j(e,u,O,g,k.current)||n.warnOnce(M,"OptionGroup: the group has no name. Give it a text `label`, `aria-label` or `aria-labelledby`."))},[e,u,O,g]),(0,h.jsxs)(`li`,{...p,ref:f,role:`presentation`,hidden:l||E||void 0,className:t.cn(a.optionGroupClassNames.root,i),children:[D&&(0,h.jsx)(`div`,{ref:k,id:g,role:`presentation`,className:t.cn(a.optionGroupClassNames.label,`px-3 py-1 text-caption-1 font-semibold text-muted-foreground`),children:r.materialiseSlotContent(e)}),(0,h.jsx)(`ul`,{role:`group`,"aria-label":u,"aria-labelledby":O,className:a.optionGroupClassNames.list,children:(0,h.jsx)(b.Provider,{value:S,children:(0,h.jsx)(y.Provider,{value:w,children:s})})})]})}N.displayName=`OptionGroup`;var P=c.markListboxElement(N,`group`);function F({value:e,children:t}){return(0,h.jsx)(c.ListboxContext.Provider,{value:e,children:t})}F.displayName=`ListboxProvider`;function I(e){let{open:t,surfaceOpen:n,onDismiss:r,rootRef:i,anchorRef:a,positioning:o}=e,c=m.useRef(null),{setReference:d,setFloating:f,floatingProps:p}=l.usePopupPosition({open:n,side:`bottom`,align:`start`,...l.resolvePositioning(o,{matchReferenceWidth:!0,fitViewport:!0})}),{layerId:h}=u.useDismiss({open:t,onDismiss:e=>r(e),refs:[i,c],anchorRef:a,kind:`listbox`,escape:n,focusOutside:!0});return{layerId:h,setReference:d,surfaceRef:s.useMergedRefs(c,f),floatingProps:p}}function L(e){e.preventDefault()}function R(e){let{listbox:n,layerId:r,surfaceRef:o,floatingProps:c,open:l,expanded:u,emptyContent:d,"aria-label":p,"aria-labelledby":m,showCheck:_=!0,listClassName:v,surfaceClassName:y,listProps:b,children:x}=e,{ref:S,onMouseDown:C,...w}=b??{},T=n.getListboxProps(),E=s.useMergedRefs(S,T.ref),D=(0,h.jsx)(g.Provider,{value:_,children:(0,h.jsx)(F,{value:n.context,children:(0,h.jsx)(`ul`,{...w,...T,"aria-multiselectable":T[`aria-multiselectable`],"aria-activedescendant":T[`aria-activedescendant`],onMouseDown:i.composeEventHandlers(C,T.onMouseDown),ref:E,"aria-label":p,"aria-labelledby":m,hidden:!u||void 0,className:t.cn(a.listboxSurfaceClassNames.list,`min-h-0 max-h-60 overflow-auto`,v),children:x})})});return!u&&(!l||u||d==null)?D:(0,h.jsxs)(h.Fragment,{children:[!u&&D,(0,h.jsx)(f.Portal,{layerId:r,children:(0,h.jsx)(`div`,{ref:o,...c,"data-wave-listbox-surface":``,onMouseDown:L,className:t.cn(a.listboxSurfaceClassNames.root,`flex flex-col overflow-hidden rounded border border-border bg-background py-1 text-foreground shadow-4`,y),children:u?D:d})})]})}R.displayName=`ListboxSurface`,exports.ListboxProvider=F,exports.ListboxSurface=R,exports.Option=D,exports.OptionGroup=P,exports.useListboxPopup=I;
2
2
  //# sourceMappingURL=Option.cjs.map