@zj-dynamics/components 0.0.0-stage → 0.1.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 (674) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.react-is +21 -0
  3. package/NOTICE.tabbable +22 -0
  4. package/README.md +23 -2
  5. package/compatibility.css +2 -0
  6. package/dist/Button.d.ts +90 -0
  7. package/dist/Button.js +58 -0
  8. package/dist/ButtonDismiss.d.ts +6 -0
  9. package/dist/ButtonDismiss.js +5 -0
  10. package/dist/Dialog.d.ts +75 -0
  11. package/dist/Dialog.js +59 -0
  12. package/dist/Icon.d.ts +20 -0
  13. package/dist/Icon.js +11 -0
  14. package/dist/InputText.d.ts +26 -0
  15. package/dist/InputText.js +63 -0
  16. package/dist/Switch.d.ts +8 -0
  17. package/dist/Switch.js +19 -0
  18. package/dist/Toast.d.ts +21 -0
  19. package/dist/Toast.js +58 -0
  20. package/dist/browserFocus.d.ts +11 -0
  21. package/dist/browserFocus.js +85 -0
  22. package/dist/browserHooks.d.ts +5 -0
  23. package/dist/browserHooks.js +4 -0
  24. package/dist/index.d.ts +100 -0
  25. package/dist/index.js +91 -0
  26. package/dist/legacyModalPortal.d.ts +1 -0
  27. package/dist/legacyModalPortal.js +2 -0
  28. package/dist/mockViewportWidth.d.ts +5 -0
  29. package/dist/mockViewportWidth.js +58 -0
  30. package/dist/slotChildren.d.ts +2 -0
  31. package/dist/slotChildren.js +6 -0
  32. package/dist/theme.d.ts +26 -0
  33. package/dist/theme.js +65 -0
  34. package/dist/unstyledPrimitives.d.ts +12 -0
  35. package/dist/unstyledPrimitives.js +12 -0
  36. package/dist/useBreakpoints.d.ts +3 -0
  37. package/dist/useBreakpoints.js +2 -0
  38. package/dist/useFocusTrap.d.ts +1 -0
  39. package/dist/useFocusTrap.js +1 -0
  40. package/dist/useInView.d.ts +1 -0
  41. package/dist/useInView.js +1 -0
  42. package/dist/useIsSmallScreen.d.ts +1 -0
  43. package/dist/useIsSmallScreen.js +1 -0
  44. package/dist/useLiveAnnounce.d.ts +1 -0
  45. package/dist/useLiveAnnounce.js +1 -0
  46. package/dist/useOnKeyDown.d.ts +1 -0
  47. package/dist/useOnKeyDown.js +1 -0
  48. package/dist/useRefocusOnActivator.d.ts +1 -0
  49. package/dist/useRefocusOnActivator.js +1 -0
  50. package/dist/useResizeObserver.d.ts +22 -0
  51. package/dist/useResizeObserver.js +47 -0
  52. package/dist/useWindowDimensions.d.ts +2 -0
  53. package/dist/useWindowDimensions.js +1 -0
  54. package/dist/viewport.d.ts +46 -0
  55. package/dist/viewport.js +141 -0
  56. package/foundation/ActivityIndicator/ActivityIndicator.d.ts +38 -0
  57. package/foundation/ActivityIndicator/index.d.mts +2 -0
  58. package/foundation/ActivityIndicator/index.mjs +6 -0
  59. package/foundation/ActivityIndicator-es.js +30 -0
  60. package/foundation/Autocomplete/Autocomplete.d.ts +8 -0
  61. package/foundation/Autocomplete/Autocomplete.types.d.ts +401 -0
  62. package/foundation/Autocomplete/hooks/useAutocompleteListNav.d.ts +30 -0
  63. package/foundation/Autocomplete/index.d.mts +3 -0
  64. package/foundation/Autocomplete/index.mjs +39 -0
  65. package/foundation/Autocomplete/utils/interactionUtils.d.ts +14 -0
  66. package/foundation/Autocomplete-es.js +1322 -0
  67. package/foundation/Avatar/Avatar.d.ts +77 -0
  68. package/foundation/Avatar/index.d.mts +1 -0
  69. package/foundation/Avatar/index.mjs +6 -0
  70. package/foundation/Avatar-es.js +80 -0
  71. package/foundation/Banner/Banner.d.ts +10 -0
  72. package/foundation/Banner/Banner.types.d.ts +165 -0
  73. package/foundation/Banner/index.d.mts +2 -0
  74. package/foundation/Banner/index.mjs +14 -0
  75. package/foundation/Banner-es.js +134 -0
  76. package/foundation/Body-es.js +45 -0
  77. package/foundation/BottomSheet-es.js +110 -0
  78. package/foundation/Box/Box.d.ts +3 -0
  79. package/foundation/Box/Box.types.d.ts +40 -0
  80. package/foundation/Box/index.d.mts +1 -0
  81. package/foundation/Box/index.mjs +4 -0
  82. package/foundation/Box-es.js +130 -0
  83. package/foundation/Button/Button.d.ts +17 -0
  84. package/foundation/Button/Button.types.d.ts +112 -0
  85. package/foundation/Button/ButtonInternals.d.ts +11 -0
  86. package/foundation/Button/ButtonProvider.d.ts +11 -0
  87. package/foundation/Button/index.d.mts +4 -0
  88. package/foundation/Button/useButtonStyles.d.ts +17 -0
  89. package/foundation/Button-es.js +122 -0
  90. package/foundation/ButtonDismiss/ButtonDismiss.d.ts +6 -0
  91. package/foundation/ButtonDismiss/index.d.mts +1 -0
  92. package/foundation/ButtonDismiss-es.js +9 -0
  93. package/foundation/Card/Card.d.ts +78 -0
  94. package/foundation/Card/cardcolors.module.d.ts +90 -0
  95. package/foundation/Card/index.d.mts +1 -0
  96. package/foundation/Card/index.mjs +37 -0
  97. package/foundation/Card/types.d.ts +63 -0
  98. package/foundation/Card-es.js +138 -0
  99. package/foundation/Checkbox/Checkbox.d.ts +7 -0
  100. package/foundation/Checkbox/Checkbox.types.d.ts +51 -0
  101. package/foundation/Checkbox/index.d.mts +2 -0
  102. package/foundation/Checkbox/index.mjs +8 -0
  103. package/foundation/Checkbox-es.js +57 -0
  104. package/foundation/Chip/Chip.d.ts +14 -0
  105. package/foundation/Chip/Chip.types.d.ts +70 -0
  106. package/foundation/Chip/components/ChipDismissible/ChipDismissible.d.ts +3 -0
  107. package/foundation/Chip/components/ChipPrefix/Chip.Prefix.d.ts +3 -0
  108. package/foundation/Chip/components/ChipSelectable/ChipSelectable.d.ts +3 -0
  109. package/foundation/Chip/components/ChipSuffix/Chip.Suffix.d.ts +9 -0
  110. package/foundation/Chip/index.d.mts +4 -0
  111. package/foundation/Chip/index.mjs +19 -0
  112. package/foundation/Chip-es.js +165 -0
  113. package/foundation/ChipDismissible-es.js +19 -0
  114. package/foundation/Chips/Chip.d.ts +9 -0
  115. package/foundation/Chips/ChipDismissible.d.ts +11 -0
  116. package/foundation/Chips/ChipTypes.d.ts +59 -0
  117. package/foundation/Chips/Chips.d.ts +8 -0
  118. package/foundation/Chips/ChipsTypes.d.ts +106 -0
  119. package/foundation/Chips/InternalChipButton.d.ts +11 -0
  120. package/foundation/Chips/index.d.mts +3 -0
  121. package/foundation/Chips/index.mjs +56 -0
  122. package/foundation/Chips-es.js +114 -0
  123. package/foundation/Cluster/Cluster.d.ts +3 -0
  124. package/foundation/Cluster/index.d.mts +2 -0
  125. package/foundation/Cluster/index.mjs +4 -0
  126. package/foundation/Cluster/types.d.ts +47 -0
  127. package/foundation/Cluster-es.js +12 -0
  128. package/foundation/Combobox/Combobox.d.ts +71 -0
  129. package/foundation/Combobox/Combobox.footer.d.ts +7 -0
  130. package/foundation/Combobox/Combobox.items.d.ts +25 -0
  131. package/foundation/Combobox/Combobox.selectAll.d.ts +4 -0
  132. package/foundation/Combobox/Combobox.slotFactory.d.ts +7 -0
  133. package/foundation/Combobox/Combobox.types.d.ts +168 -0
  134. package/foundation/Combobox/index.d.mts +2 -0
  135. package/foundation/Combobox/index.mjs +28 -0
  136. package/foundation/Combobox-es.js +782 -0
  137. package/foundation/ComboboxPrimitive-es.js +187 -0
  138. package/foundation/ComboboxSeparator-es.js +3541 -0
  139. package/foundation/ComponentSettingsContext/ComponentSettingsContext.d.ts +41 -0
  140. package/foundation/ComponentSettingsContext/index.d.mts +4 -0
  141. package/foundation/ComponentSettingsContext/index.mjs +5 -0
  142. package/foundation/ComponentSettingsContext-es.js +18 -0
  143. package/foundation/ConfirmationModal/ConfirmationModal.d.ts +79 -0
  144. package/foundation/ConfirmationModal/index.d.mts +1 -0
  145. package/foundation/ConfirmationModal/index.mjs +37 -0
  146. package/foundation/ConfirmationModal-es.js +111 -0
  147. package/foundation/Container/Container.d.ts +6 -0
  148. package/foundation/Container/index.d.mts +1 -0
  149. package/foundation/Container/index.mjs +3 -0
  150. package/foundation/Container/types.d.ts +22 -0
  151. package/foundation/Container-es.js +16 -0
  152. package/foundation/Content/Content.d.ts +22 -0
  153. package/foundation/Content/Spacing.module.d.ts +14 -0
  154. package/foundation/Content/index.d.mts +1 -0
  155. package/foundation/Content/index.mjs +3 -0
  156. package/foundation/Content-es.js +13 -0
  157. package/foundation/ContentBlock/ContentBlock.d.ts +3 -0
  158. package/foundation/ContentBlock/index.d.mts +2 -0
  159. package/foundation/ContentBlock/index.mjs +4 -0
  160. package/foundation/ContentBlock/types.d.ts +37 -0
  161. package/foundation/ContentBlock-es.js +29 -0
  162. package/foundation/Countdown/Countdown.d.ts +30 -0
  163. package/foundation/Countdown/index.d.mts +1 -0
  164. package/foundation/Countdown/index.mjs +4 -0
  165. package/foundation/Countdown-es.js +649 -0
  166. package/foundation/Cover/Cover.d.ts +6 -0
  167. package/foundation/Cover/index.d.mts +2 -0
  168. package/foundation/Cover/index.mjs +4 -0
  169. package/foundation/Cover/types.d.ts +34 -0
  170. package/foundation/Cover-es.js +14 -0
  171. package/foundation/DataDump/DataDump.d.ts +21 -0
  172. package/foundation/DataDump/index.d.mts +1 -0
  173. package/foundation/DataDump/index.mjs +40 -0
  174. package/foundation/DataDump-es.js +26 -0
  175. package/foundation/DataList/DataList.const.d.ts +22 -0
  176. package/foundation/DataList/DataList.d.ts +28 -0
  177. package/foundation/DataList/DataList.types.d.ts +323 -0
  178. package/foundation/DataList/components/DataListAction/DataListAction.d.ts +3 -0
  179. package/foundation/DataList/components/DataListAction/index.d.mts +1 -0
  180. package/foundation/DataList/components/DataListBulkActions/DataListBulkActions.d.ts +4 -0
  181. package/foundation/DataList/components/DataListBulkActions/index.d.mts +1 -0
  182. package/foundation/DataList/components/DataListEmptyState/DataListEmptyState.d.ts +4 -0
  183. package/foundation/DataList/components/DataListEmptyState/index.d.mts +1 -0
  184. package/foundation/DataList/components/DataListFilters/DataListFilters.d.ts +11 -0
  185. package/foundation/DataList/components/DataListFilters/index.d.mts +1 -0
  186. package/foundation/DataList/components/DataListItemActions/DataListItemActions.d.ts +9 -0
  187. package/foundation/DataList/components/DataListItemActions/index.d.mts +1 -0
  188. package/foundation/DataList/components/DataListLayout/DataListLayout.d.ts +3 -0
  189. package/foundation/DataList/components/DataListLayout/index.d.mts +1 -0
  190. package/foundation/DataList/components/DataListLayoutActions/DataListLayoutActions.d.ts +2 -0
  191. package/foundation/DataList/components/DataListLayoutActions/index.d.mts +1 -0
  192. package/foundation/DataList/components/DataListSearch/DataListSearch.d.ts +8 -0
  193. package/foundation/DataList/components/DataListSearch/index.d.mts +1 -0
  194. package/foundation/DataList/components/DataListStatusBar/DataListStatusBar.d.ts +11 -0
  195. package/foundation/DataList/components/DataListStatusBar/index.d.mts +1 -0
  196. package/foundation/DataList/index.d.mts +2 -0
  197. package/foundation/DataList/index.mjs +96 -0
  198. package/foundation/DataList-es.js +141 -0
  199. package/foundation/DataList.const-es.js +26 -0
  200. package/foundation/DataList.module-es.js +3 -0
  201. package/foundation/DataList.utils-es.js +167 -0
  202. package/foundation/DataListAction-es.js +43 -0
  203. package/foundation/DataListActions-es.js +53 -0
  204. package/foundation/DataListActionsMenu-es.js +52 -0
  205. package/foundation/DataListBulkActions-es.js +28 -0
  206. package/foundation/DataListContext-es.js +26 -0
  207. package/foundation/DataListEmptyState-es.js +54 -0
  208. package/foundation/DataListFilters-es.js +43 -0
  209. package/foundation/DataListHeader-es.js +130 -0
  210. package/foundation/DataListHeaderTile-es.js +86 -0
  211. package/foundation/DataListItem-es.js +118 -0
  212. package/foundation/DataListItemActions-es.js +29 -0
  213. package/foundation/DataListItemActionsOverflow-es.js +34 -0
  214. package/foundation/DataListItemClickable-es.js +45 -0
  215. package/foundation/DataListItems-es.js +19 -0
  216. package/foundation/DataListLayout-es.js +19 -0
  217. package/foundation/DataListLayoutActions-es.js +36 -0
  218. package/foundation/DataListLayoutContext-es.js +14 -0
  219. package/foundation/DataListLayoutContext-es2.js +8 -0
  220. package/foundation/DataListLoadMore-es.js +32 -0
  221. package/foundation/DataListLoadingState-es.js +22 -0
  222. package/foundation/DataListOverflowFade-es.js +22 -0
  223. package/foundation/DataListSearch-es.js +84 -0
  224. package/foundation/DataListSort-es.js +74 -0
  225. package/foundation/DataListSortingOptions-es.js +34 -0
  226. package/foundation/DataListStatusBar-es.js +22 -0
  227. package/foundation/DataListStickyHeader-es.js +23 -0
  228. package/foundation/DataListTags-es.js +62 -0
  229. package/foundation/DataListTotalCount-es.js +38 -0
  230. package/foundation/DataTable/DataTable.d.ts +74 -0
  231. package/foundation/DataTable/SortIcon.d.ts +11 -0
  232. package/foundation/DataTable/components/DataTableActions.d.ts +2 -0
  233. package/foundation/DataTable/components/DataTableBody.d.ts +2 -0
  234. package/foundation/DataTable/components/DataTableCell.d.ts +2 -0
  235. package/foundation/DataTable/components/DataTableContainer.d.ts +2 -0
  236. package/foundation/DataTable/components/DataTableFooter.d.ts +5 -0
  237. package/foundation/DataTable/components/DataTableHeader.d.ts +2 -0
  238. package/foundation/DataTable/components/DataTableHeaderCell.d.ts +5 -0
  239. package/foundation/DataTable/components/DataTablePagination.d.ts +5 -0
  240. package/foundation/DataTable/components/DataTablePaginationButton.d.ts +21 -0
  241. package/foundation/DataTable/components/DataTableRow.d.ts +2 -0
  242. package/foundation/DataTable/components/DataTableRowActions.d.ts +4 -0
  243. package/foundation/DataTable/components/DataTableSortableHeader.d.ts +24 -0
  244. package/foundation/DataTable/components/DataTableTable.d.ts +11 -0
  245. package/foundation/DataTable/components/index.d.mts +13 -0
  246. package/foundation/DataTable/index.d.mts +6 -0
  247. package/foundation/DataTable/index.mjs +29 -0
  248. package/foundation/DataTable/test-utilities/helpers.d.ts +1 -0
  249. package/foundation/DataTable/types.d.ts +83 -0
  250. package/foundation/DataTable-es.js +262 -0
  251. package/foundation/DataTableTable-es.js +117 -0
  252. package/foundation/DatePicker/DatePicker.d.ts +74 -0
  253. package/foundation/DatePicker/DatePickerActivator.d.ts +18 -0
  254. package/foundation/DatePicker/index.d.mts +1 -0
  255. package/foundation/DatePicker/index.mjs +26 -0
  256. package/foundation/DatePicker-es.js +13627 -0
  257. package/foundation/Dialog/dialogReturnFocus.d.ts +43 -0
  258. package/foundation/Disclosure/Disclosure.d.ts +68 -0
  259. package/foundation/Disclosure/index.d.mts +1 -0
  260. package/foundation/Disclosure/index.mjs +7 -0
  261. package/foundation/Disclosure-es.js +46 -0
  262. package/foundation/Divider/Divider.d.ts +39 -0
  263. package/foundation/Divider/DividerDirections.module.d.ts +6 -0
  264. package/foundation/Divider/DividerSizes.module.d.ts +8 -0
  265. package/foundation/Divider/index.d.mts +1 -0
  266. package/foundation/Divider/index.mjs +3 -0
  267. package/foundation/Divider-es.js +15 -0
  268. package/foundation/Drawer/Drawer.d.ts +14 -0
  269. package/foundation/Drawer/DrawerGrid.d.ts +7 -0
  270. package/foundation/Drawer/index.d.mts +2 -0
  271. package/foundation/Drawer/index.mjs +13 -0
  272. package/foundation/DrawerGrid-es.js +39 -0
  273. package/foundation/DrawerTitle-es.js +90 -0
  274. package/foundation/Emphasis/Emphasis.d.ts +12 -0
  275. package/foundation/Emphasis/index.d.mts +1 -0
  276. package/foundation/Emphasis/index.mjs +4 -0
  277. package/foundation/Emphasis-es.js +13 -0
  278. package/foundation/FeatureSwitch/FeatureSwitch.d.ts +52 -0
  279. package/foundation/FeatureSwitch/index.d.mts +1 -0
  280. package/foundation/FeatureSwitch/index.mjs +20 -0
  281. package/foundation/FeatureSwitch-es.js +66 -0
  282. package/foundation/FieldDescription-es.js +859 -0
  283. package/foundation/FilterPicker/FilterPicker.d.ts +11 -0
  284. package/foundation/FilterPicker/FilterPicker.types.d.ts +282 -0
  285. package/foundation/FilterPicker/FilterPickerProvider.d.ts +18 -0
  286. package/foundation/FilterPicker/components/FilterPickerAction/FilterPickerAction.d.ts +3 -0
  287. package/foundation/FilterPicker/components/FilterPickerAction/index.d.mts +1 -0
  288. package/foundation/FilterPicker/components/FilterPickerActivator/FilterPickerActivator.d.ts +3 -0
  289. package/foundation/FilterPicker/components/FilterPickerActivator/index.d.mts +1 -0
  290. package/foundation/FilterPicker/components/FilterPickerOption/FilterPickerOption.d.ts +3 -0
  291. package/foundation/FilterPicker/index.d.mts +3 -0
  292. package/foundation/FilterPicker/index.mjs +49 -0
  293. package/foundation/FilterPicker-es.js +110 -0
  294. package/foundation/FilterPicker.messages-es.js +56 -0
  295. package/foundation/FilterPickerAction-es.js +30 -0
  296. package/foundation/FilterPickerActivator-es.js +36 -0
  297. package/foundation/FilterPickerContent-es.js +180 -0
  298. package/foundation/FilterPickerContentHeader-es.js +23 -0
  299. package/foundation/FilterPickerContentList-es.js +74 -0
  300. package/foundation/FilterPickerContentSearch-es.js +35 -0
  301. package/foundation/FilterPickerLoadMore-es.js +14 -0
  302. package/foundation/FilterPickerOption-es.js +29 -0
  303. package/foundation/FilterPickerProvider-es.js +10 -0
  304. package/foundation/FilterPickerTrigger-es.js +19 -0
  305. package/foundation/Flex/Flex.d.ts +33 -0
  306. package/foundation/Flex/Flex.types.d.ts +6 -0
  307. package/foundation/Flex/index.d.mts +1 -0
  308. package/foundation/Flex/index.mjs +3 -0
  309. package/foundation/Flex-es.js +28 -0
  310. package/foundation/FormField/FormFieldAffix.d.ts +19 -0
  311. package/foundation/FormField/FormFieldTypes.d.ts +185 -0
  312. package/foundation/FormField/FormFieldWrapper.d.ts +57 -0
  313. package/foundation/FormField/hooks/useFormFieldName.d.ts +6 -0
  314. package/foundation/FormField/hooks/useFormFieldWrapperStyles.d.ts +35 -0
  315. package/foundation/FormField/index.d.mts +5 -0
  316. package/foundation/FormField/index.mjs +17 -0
  317. package/foundation/FormFieldPostFix-es.js +13 -0
  318. package/foundation/FormFieldWrapper-es.js +233 -0
  319. package/foundation/FormatFile/FormatFile.d.ts +42 -0
  320. package/foundation/FormatFile/index.d.mts +4 -0
  321. package/foundation/FormatFile/index.mjs +42 -0
  322. package/foundation/FormatFile/types.d.ts +27 -0
  323. package/foundation/FormatFile/useFormatFile.d.ts +5 -0
  324. package/foundation/FormatFile/useFormatFileStyles.d.ts +10 -0
  325. package/foundation/FormatFile-es.js +137 -0
  326. package/foundation/Frame/Frame.d.ts +3 -0
  327. package/foundation/Frame/index.d.mts +2 -0
  328. package/foundation/Frame/index.mjs +3 -0
  329. package/foundation/Frame/types.d.ts +24 -0
  330. package/foundation/Frame-es.js +10 -0
  331. package/foundation/Gallery/Gallery.d.ts +3 -0
  332. package/foundation/Gallery/GalleryTypes.d.ts +36 -0
  333. package/foundation/Gallery/index.d.mts +3 -0
  334. package/foundation/Gallery/index.mjs +64 -0
  335. package/foundation/Gallery-es.js +88 -0
  336. package/foundation/Glimmer/Glimmer.d.ts +71 -0
  337. package/foundation/Glimmer/index.d.mts +1 -0
  338. package/foundation/Glimmer/index.mjs +5 -0
  339. package/foundation/Glimmer/style/Shape.module.d.ts +9 -0
  340. package/foundation/Glimmer/style/Sizes.module.d.ts +10 -0
  341. package/foundation/Glimmer/style/Timing.module.d.ts +6 -0
  342. package/foundation/Glimmer-es.js +53 -0
  343. package/foundation/Grid/Grid.d.ts +32 -0
  344. package/foundation/Grid/GridAlign.module.d.ts +8 -0
  345. package/foundation/Grid/GridCell/GridCell.d.ts +23 -0
  346. package/foundation/Grid/GridCell/index.d.mts +1 -0
  347. package/foundation/Grid/index.d.mts +1 -0
  348. package/foundation/Grid/index.mjs +5 -0
  349. package/foundation/Grid-es.js +30 -0
  350. package/foundation/GridCell-es.js +34 -0
  351. package/foundation/Heading/Heading.d.ts +41 -0
  352. package/foundation/Heading/index.d.mts +2 -0
  353. package/foundation/Heading/index.mjs +4 -0
  354. package/foundation/Heading-es.js +55 -0
  355. package/foundation/HelperText-es.js +19 -0
  356. package/foundation/Icon/Icon.d.ts +47 -0
  357. package/foundation/Icon/index.d.mts +1 -0
  358. package/foundation/Icon-es.js +22 -0
  359. package/foundation/InlineLabel/InlineLabel.d.ts +18 -0
  360. package/foundation/InlineLabel/index.d.mts +1 -0
  361. package/foundation/InlineLabel/index.mjs +4 -0
  362. package/foundation/InlineLabel-es.js +19 -0
  363. package/foundation/InputAvatar/InputAvatar.d.ts +23 -0
  364. package/foundation/InputAvatar/index.d.mts +1 -0
  365. package/foundation/InputAvatar/index.mjs +22 -0
  366. package/foundation/InputAvatar-es.js +64 -0
  367. package/foundation/InputDate/InputDate.d.ts +3 -0
  368. package/foundation/InputDate/InputDate.types.d.ts +36 -0
  369. package/foundation/InputDate/index.d.mts +2 -0
  370. package/foundation/InputDate/index.mjs +39 -0
  371. package/foundation/InputDate-es.js +104 -0
  372. package/foundation/InputEmail/InputEmail.d.ts +3 -0
  373. package/foundation/InputEmail/InputEmail.types.d.ts +16 -0
  374. package/foundation/InputEmail/index.d.mts +2 -0
  375. package/foundation/InputEmail/index.mjs +22 -0
  376. package/foundation/InputEmail-es.js +105 -0
  377. package/foundation/InputFile/FileTypes.d.ts +17 -0
  378. package/foundation/InputFile/InputFile.d.ts +187 -0
  379. package/foundation/InputFile/InputFileButton.d.ts +6 -0
  380. package/foundation/InputFile/InputFileContentContext.d.ts +12 -0
  381. package/foundation/InputFile/InputFileDescription.d.ts +4 -0
  382. package/foundation/InputFile/InputFileDropzoneWrapper.d.ts +4 -0
  383. package/foundation/InputFile/InputFileHintText.d.ts +4 -0
  384. package/foundation/InputFile/index.d.mts +3 -0
  385. package/foundation/InputFile/index.mjs +16 -0
  386. package/foundation/InputFile-es.js +1780 -0
  387. package/foundation/InputGroup/InputGroup.d.ts +12 -0
  388. package/foundation/InputGroup/index.d.mts +1 -0
  389. package/foundation/InputGroup/index.mjs +3 -0
  390. package/foundation/InputGroup-es.js +26 -0
  391. package/foundation/InputNumber/InputNumber.d.ts +77 -0
  392. package/foundation/InputNumber/index.d.mts +2 -0
  393. package/foundation/InputNumber/index.mjs +33 -0
  394. package/foundation/InputNumber/types.d.ts +197 -0
  395. package/foundation/InputNumber-es.js +348 -0
  396. package/foundation/InputPhoneNumber/InputPhoneNumber.d.ts +3 -0
  397. package/foundation/InputPhoneNumber/InputPhoneNumber.types.d.ts +24 -0
  398. package/foundation/InputPhoneNumber/index.d.mts +2 -0
  399. package/foundation/InputPhoneNumber/index.mjs +22 -0
  400. package/foundation/InputPhoneNumber-es.js +188 -0
  401. package/foundation/InputText/InputText.d.ts +3 -0
  402. package/foundation/InputText/InputText.types.d.ts +58 -0
  403. package/foundation/InputText/index.d.mts +2 -0
  404. package/foundation/InputText/index.mjs +23 -0
  405. package/foundation/InputText-es.js +196 -0
  406. package/foundation/InputTime/InputTime.d.ts +3 -0
  407. package/foundation/InputTime/InputTime.types.d.ts +34 -0
  408. package/foundation/InputTime/index.d.mts +2 -0
  409. package/foundation/InputTime/index.mjs +23 -0
  410. package/foundation/InputTime-es.js +297 -0
  411. package/foundation/InputValidation/InputValidation.d.ts +10 -0
  412. package/foundation/InputValidation/index.d.mts +1 -0
  413. package/foundation/InputValidation/index.mjs +8 -0
  414. package/foundation/InputValidation-es.js +22 -0
  415. package/foundation/InternalChipDismissible-es.js +68 -0
  416. package/foundation/LICENSE +21 -0
  417. package/foundation/LegacySelect/LegacySelect.d.ts +7 -0
  418. package/foundation/LegacySelect/LegacySelect.types.d.ts +18 -0
  419. package/foundation/LegacySelect/Option.d.ts +18 -0
  420. package/foundation/LegacySelect/OptionGroup.d.ts +29 -0
  421. package/foundation/LegacySelect/index.d.mts +3 -0
  422. package/foundation/LegacySelect/index.mjs +23 -0
  423. package/foundation/LegacySelect-es.js +76 -0
  424. package/foundation/LegacyThemeContext/LegacyThemeContext.d.ts +5 -0
  425. package/foundation/LegacyThemeContext/index.d.mts +3 -0
  426. package/foundation/LegacyThemeContext/index.mjs +12 -0
  427. package/foundation/LegacyThemeContext/types.d.ts +59 -0
  428. package/foundation/LegacyThemeContext/updateTheme.d.ts +7 -0
  429. package/foundation/LegacyThemeContext-es.js +457 -0
  430. package/foundation/LightBox/LightBox.d.ts +165 -0
  431. package/foundation/LightBox/LightBox.types.d.ts +153 -0
  432. package/foundation/LightBox/LightBoxContext.d.ts +5 -0
  433. package/foundation/LightBox/index.d.mts +3 -0
  434. package/foundation/LightBox/index.mjs +50 -0
  435. package/foundation/LightBox-es.js +454 -0
  436. package/foundation/Link/Link.d.ts +9 -0
  437. package/foundation/Link/index.d.mts +2 -0
  438. package/foundation/Link/index.mjs +2 -0
  439. package/foundation/Link-es.js +12 -0
  440. package/foundation/List/List.d.ts +41 -0
  441. package/foundation/List/ListItem.d.ts +59 -0
  442. package/foundation/List/index.d.mts +2 -0
  443. package/foundation/List/index.mjs +22 -0
  444. package/foundation/List-es.js +199 -0
  445. package/foundation/Markdown/Markdown.d.ts +24 -0
  446. package/foundation/Markdown/index.d.mts +1 -0
  447. package/foundation/Markdown/index.mjs +10 -0
  448. package/foundation/Markdown-es.js +20558 -0
  449. package/foundation/Menu/Menu.d.ts +89 -0
  450. package/foundation/Menu/Menu.types.d.ts +105 -0
  451. package/foundation/Menu/index.d.mts +2 -0
  452. package/foundation/Menu/index.mjs +35 -0
  453. package/foundation/Menu/menuComposableTypes.d.ts +103 -0
  454. package/foundation/Menu-es.js +1033 -0
  455. package/foundation/MenuSubmenuTrigger-es.js +3088 -0
  456. package/foundation/Modal/Modal.rebuilt.d.ts +16 -0
  457. package/foundation/Modal/Modal.types.d.ts +138 -0
  458. package/foundation/Modal/ModalContext.rebuilt.d.ts +19 -0
  459. package/foundation/Modal/ModalSizes.module.d.ts +7 -0
  460. package/foundation/Modal/index.d.mts +17 -0
  461. package/foundation/Modal/index.mjs +302 -0
  462. package/foundation/Modal/useModalStyles.d.ts +12 -0
  463. package/foundation/MultiSelect/MultiSelect.d.ts +30 -0
  464. package/foundation/MultiSelect/index.d.mts +1 -0
  465. package/foundation/MultiSelect/index.mjs +9 -0
  466. package/foundation/MultiSelect/types.d.ts +13 -0
  467. package/foundation/MultiSelect-es.js +172 -0
  468. package/foundation/OverlaySeparator-es.js +13 -0
  469. package/foundation/Page/Page.d.ts +74 -0
  470. package/foundation/Page/index.d.mts +2 -0
  471. package/foundation/Page/index.mjs +42 -0
  472. package/foundation/Page/types.d.ts +123 -0
  473. package/foundation/Page-es.js +196 -0
  474. package/foundation/Popover/Popover.d.ts +9 -0
  475. package/foundation/Popover/Popover.types.d.ts +109 -0
  476. package/foundation/Popover/PopoverContext.d.ts +18 -0
  477. package/foundation/Popover/index.d.mts +4 -0
  478. package/foundation/Popover/index.mjs +27 -0
  479. package/foundation/Popover/usePopoverStyles.d.ts +5 -0
  480. package/foundation/Popover-es.js +166 -0
  481. package/foundation/ProgressBar/ProgressBar.d.ts +41 -0
  482. package/foundation/ProgressBar/ProgressBarSizes.module.d.ts +7 -0
  483. package/foundation/ProgressBar/index.d.mts +1 -0
  484. package/foundation/ProgressBar/index.mjs +5 -0
  485. package/foundation/ProgressBar-es.js +48 -0
  486. package/foundation/ProgressIndicator/ProgressIndicator.d.ts +60 -0
  487. package/foundation/ProgressIndicator/index.d.mts +1 -0
  488. package/foundation/ProgressIndicator/index.mjs +3 -0
  489. package/foundation/ProgressIndicator-es.js +41 -0
  490. package/foundation/RadioGroup/RadioGroup.d.ts +33 -0
  491. package/foundation/RadioGroup/RadioOption.d.ts +48 -0
  492. package/foundation/RadioGroup/index.d.mts +2 -0
  493. package/foundation/RadioGroup/index.mjs +5 -0
  494. package/foundation/RadioGroup-es.js +42 -0
  495. package/foundation/ResponsiveSwitcher/ResponsiveSwitcher.d.ts +3 -0
  496. package/foundation/ResponsiveSwitcher/index.d.mts +2 -0
  497. package/foundation/ResponsiveSwitcher/index.mjs +4 -0
  498. package/foundation/ResponsiveSwitcher/types.d.ts +26 -0
  499. package/foundation/ResponsiveSwitcher-es.js +11 -0
  500. package/foundation/RulnarPortalContent-es.js +1 -0
  501. package/foundation/ScrollAreaViewport-es.js +3959 -0
  502. package/foundation/SegmentedControl/SegmentedControl.d.ts +39 -0
  503. package/foundation/SegmentedControl/SegmentedControlBase.d.ts +7 -0
  504. package/foundation/SegmentedControl/SegmentedControlOption.d.ts +15 -0
  505. package/foundation/SegmentedControl/SegmentedControlProvider.d.ts +17 -0
  506. package/foundation/SegmentedControl/index.d.mts +2 -0
  507. package/foundation/SegmentedControl/index.mjs +3 -0
  508. package/foundation/SegmentedControl-es.js +64 -0
  509. package/foundation/Select/Select.d.ts +31 -0
  510. package/foundation/Select/Select.types.d.ts +145 -0
  511. package/foundation/Select/index.d.mts +2 -0
  512. package/foundation/Select/index.mjs +29 -0
  513. package/foundation/Select-es.js +227 -0
  514. package/foundation/SelectGroupLabel-es.js +1763 -0
  515. package/foundation/SelectPrimitive-es.js +126 -0
  516. package/foundation/Separator-es.js +33 -0
  517. package/foundation/SideDrawer/SideDrawer.d.ts +56 -0
  518. package/foundation/SideDrawer/SideDrawerActions.d.ts +3 -0
  519. package/foundation/SideDrawer/SideDrawerBackButton.d.ts +3 -0
  520. package/foundation/SideDrawer/SideDrawerFooter.d.ts +3 -0
  521. package/foundation/SideDrawer/SideDrawerTitle.d.ts +3 -0
  522. package/foundation/SideDrawer/SideDrawerToolbar.d.ts +2 -0
  523. package/foundation/SideDrawer/index.d.mts +1 -0
  524. package/foundation/SideDrawer/index.mjs +16 -0
  525. package/foundation/SideDrawer-es.js +198 -0
  526. package/foundation/SideKick/SideKick.d.ts +3 -0
  527. package/foundation/SideKick/index.d.mts +2 -0
  528. package/foundation/SideKick/index.mjs +4 -0
  529. package/foundation/SideKick/types.d.ts +35 -0
  530. package/foundation/SideKick-es.js +15 -0
  531. package/foundation/Spinner/Spinner.d.ts +22 -0
  532. package/foundation/Spinner/index.d.mts +1 -0
  533. package/foundation/Spinner/index.mjs +6 -0
  534. package/foundation/Spinner-es.js +21 -0
  535. package/foundation/Stack/Stack.d.ts +3 -0
  536. package/foundation/Stack/index.d.mts +2 -0
  537. package/foundation/Stack/index.mjs +4 -0
  538. package/foundation/Stack/types.d.ts +32 -0
  539. package/foundation/Stack-es.js +13 -0
  540. package/foundation/StatusIndicator/StatusIndicator.d.ts +7 -0
  541. package/foundation/StatusIndicator/StatusIndicator.type.d.ts +1 -0
  542. package/foundation/StatusIndicator/index.d.mts +2 -0
  543. package/foundation/StatusIndicator/index.mjs +2 -0
  544. package/foundation/StatusIndicator-es.js +9 -0
  545. package/foundation/StatusLabel/StatusLabel.d.ts +26 -0
  546. package/foundation/StatusLabel/index.d.mts +1 -0
  547. package/foundation/StatusLabel/index.mjs +5 -0
  548. package/foundation/StatusLabel-es.js +16 -0
  549. package/foundation/Table/Body.d.ts +7 -0
  550. package/foundation/Table/Cells/Cell.d.ts +8 -0
  551. package/foundation/Table/Cells/CellCurrency.d.ts +9 -0
  552. package/foundation/Table/Cells/CellNumeric.d.ts +5 -0
  553. package/foundation/Table/Footer.d.ts +7 -0
  554. package/foundation/Table/Header.d.ts +7 -0
  555. package/foundation/Table/Row.d.ts +7 -0
  556. package/foundation/Table/Table.d.ts +7 -0
  557. package/foundation/Table/index.d.mts +8 -0
  558. package/foundation/Table/index.mjs +4 -0
  559. package/foundation/Tabs/Tabs.d.ts +38 -0
  560. package/foundation/Tabs/index.d.mts +1 -0
  561. package/foundation/Tabs/index.mjs +8 -0
  562. package/foundation/Tabs-es.js +227 -0
  563. package/foundation/Text/Text.d.ts +29 -0
  564. package/foundation/Text/index.d.mts +2 -0
  565. package/foundation/Text/index.mjs +4 -0
  566. package/foundation/Text-es.js +25 -0
  567. package/foundation/Thumbnail/Thumbnail.d.ts +25 -0
  568. package/foundation/Thumbnail/index.d.mts +1 -0
  569. package/foundation/Thumbnail/index.mjs +9 -0
  570. package/foundation/Thumbnail-es.js +119 -0
  571. package/foundation/Tiles/Tiles.d.ts +3 -0
  572. package/foundation/Tiles/index.d.mts +2 -0
  573. package/foundation/Tiles/index.mjs +4 -0
  574. package/foundation/Tiles/types.d.ts +34 -0
  575. package/foundation/Tiles-es.js +11 -0
  576. package/foundation/Tooltip/Tooltip.d.ts +18 -0
  577. package/foundation/Tooltip/Tooltip.types.d.ts +1 -0
  578. package/foundation/Tooltip/index.d.mts +1 -0
  579. package/foundation/Tooltip/index.mjs +8 -0
  580. package/foundation/Tooltip-es.js +137 -0
  581. package/foundation/Typography/Typography.d.ts +64 -0
  582. package/foundation/Typography/css/Emphasis.module.d.ts +6 -0
  583. package/foundation/Typography/css/FontFamilies.module.d.ts +6 -0
  584. package/foundation/Typography/css/FontSizes.module.d.ts +12 -0
  585. package/foundation/Typography/css/FontWeights.module.d.ts +10 -0
  586. package/foundation/Typography/css/TextAlignment.module.d.ts +7 -0
  587. package/foundation/Typography/css/TextCases.module.d.ts +8 -0
  588. package/foundation/Typography/css/TextColors.module.d.ts +69 -0
  589. package/foundation/Typography/index.d.mts +1 -0
  590. package/foundation/Typography/index.mjs +3 -0
  591. package/foundation/Typography/types.d.ts +7 -0
  592. package/foundation/Typography-es.js +53 -0
  593. package/foundation/_baseAssignValue-es.js +29 -0
  594. package/foundation/_baseEach-es.js +1028 -0
  595. package/foundation/_baseFlatten-es.js +65 -0
  596. package/foundation/_baseFor-es.js +45 -0
  597. package/foundation/_commonjsHelpers-es.js +7 -0
  598. package/foundation/_getAllKeys-es.js +506 -0
  599. package/foundation/_getTag-es.js +133 -0
  600. package/foundation/_isIterateeCall-es.js +55 -0
  601. package/foundation/_setToString-es.js +168 -0
  602. package/foundation/buttonRenderAdapter-es.js +52 -0
  603. package/foundation/buttonStyles.d.mts +1 -0
  604. package/foundation/buttonStyles.mjs +1 -0
  605. package/foundation/clearable.d.ts +1 -0
  606. package/foundation/common.messages-es.js +18 -0
  607. package/foundation/compatHooks.mjs +2 -0
  608. package/foundation/constants-es.js +3 -0
  609. package/foundation/dateLocale-es.js +1142 -0
  610. package/foundation/debounce-es.js +329 -0
  611. package/foundation/dialogFocus.d.mts +1 -0
  612. package/foundation/dialogFocus.mjs +66 -0
  613. package/foundation/filterDataAttributes-es.js +24 -0
  614. package/foundation/floating-ui.react-es.js +6174 -0
  615. package/foundation/getMappedSpaceToken-es.js +18 -0
  616. package/foundation/helpers-es.js +15 -0
  617. package/foundation/identity-es.js +809 -0
  618. package/foundation/imageTypes.d.mts +1 -0
  619. package/foundation/imageTypes.mjs +1 -0
  620. package/foundation/index-es.js +1186 -0
  621. package/foundation/isObjectLike-es.js +190 -0
  622. package/foundation/isSymbol-es.js +33 -0
  623. package/foundation/isTypedArray-es.js +589 -0
  624. package/foundation/keysIn-es.js +385 -0
  625. package/foundation/linkEvents.d.mts +1 -0
  626. package/foundation/linkEvents.mjs +9 -0
  627. package/foundation/maxHeight-es.js +22 -0
  628. package/foundation/mergeClassName-es.js +10 -0
  629. package/foundation/mergeRefs-es.js +18 -0
  630. package/foundation/nestedEscape-es.js +91 -0
  631. package/foundation/noop-es.js +24 -0
  632. package/foundation/primitives/BottomSheet/BottomSheet.d.ts +37 -0
  633. package/foundation/primitives/BottomSheet/BottomSheet.types.d.ts +36 -0
  634. package/foundation/primitives/BottomSheet/index.d.mts +2 -0
  635. package/foundation/primitives/ComboboxPrimitive/ComboboxPrimitive.d.ts +32 -0
  636. package/foundation/primitives/ComboboxPrimitive/ComboboxPrimitive.types.d.ts +30 -0
  637. package/foundation/primitives/ComboboxPrimitive/index.d.mts +2 -0
  638. package/foundation/primitives/HelperText/HelperText.d.ts +25 -0
  639. package/foundation/primitives/HelperText/index.d.mts +1 -0
  640. package/foundation/primitives/OverlaySeparator/OverlaySeparator.d.ts +6 -0
  641. package/foundation/primitives/OverlaySeparator/index.d.mts +1 -0
  642. package/foundation/primitives/SelectPrimitive/SelectPrimitive.d.ts +74 -0
  643. package/foundation/primitives/SelectPrimitive/index.d.mts +2 -0
  644. package/foundation/primitives/SelectPrimitive/types.d.ts +31 -0
  645. package/foundation/primitives/index.d.mts +12 -0
  646. package/foundation/primitives/index.mjs +29 -0
  647. package/foundation/routerLink.d.mts +3 -0
  648. package/foundation/routerLink.mjs +1 -0
  649. package/foundation/scrollEdges-es.js +64 -0
  650. package/foundation/scrollable-es.js +54 -0
  651. package/foundation/sharedHelpers/getMappedBreakpointWidth.d.ts +8 -0
  652. package/foundation/sharedHelpers/types.d.ts +254 -0
  653. package/foundation/stringifyLocale-es.js +11 -0
  654. package/foundation/styles.css +16646 -0
  655. package/foundation/tslib.es6-es.js +97 -0
  656. package/foundation/unstyledPrimitives/index.d.mts +22 -0
  657. package/foundation/useActiveLayout-es.js +14 -0
  658. package/foundation/useBatchSelect-es.js +36 -0
  659. package/foundation/useChildComponent-es.js +15 -0
  660. package/foundation/useComponentMessages-es.js +86 -0
  661. package/foundation/useCompositeListItem-es.js +3955 -0
  662. package/foundation/useFormFieldFocus-es.js +37 -0
  663. package/foundation/useFormFieldName-es.js +11 -0
  664. package/foundation/useLabel-es.js +81 -0
  665. package/foundation/useRenderElement-es.js +628 -0
  666. package/foundation/useResponsiveSizing-es.js +8 -0
  667. package/foundation/useScrollLock-es.js +5746 -0
  668. package/foundation/useScrollToActive-es.js +581 -0
  669. package/foundation/utils/isNormalClick.d.ts +6 -0
  670. package/foundation/utils/isPreviewableImage.d.ts +1 -0
  671. package/foundation/utils/meta/meta.json +298 -0
  672. package/foundation.css +67 -0
  673. package/package.json +540 -4
  674. package/src/styles.css +181 -0
@@ -0,0 +1,3541 @@
1
+ import * as React from 'react';
2
+ import { bU as getGridNavigatedIndex, aO as isIndexOutOfListBounds, a7 as useDirection, v as useControlled, bV as Store, d as useStableCallback, U as useStore, w as useValueAsRef, s as useTransitionStatus, R as useOpenInteractionType, G as createGenericEventDetails, z as none, M as inputClear, O as inputChange, aE as getOverflowAncestors, i as isHTMLElement, a0 as contains, bu as escapeKey, h as createChangeEventDetails, Y as focusOut, Z as outsidePress, e as getTarget, ad as itemPress, l as useOpenChangeComplete, c as useIsoLayoutEffect, L as useValueChanged, V as useClick, bW as inputPress, W as useDismiss, F as FOCUSABLE_POPUP_PROPS, B as visuallyHiddenInput, C as visuallyHidden, P as keyboard, bX as pointer, _ as pressableTriggerOpenStateMapping, q as useTimeout, f as useButton, o as ownerDocument, aR as stopEvent, aS as listNavigation, a1 as cancelOpen, j as closePress, u as useBaseUiId, bg as android, bY as gecko, au as isElement, bv as isInteractiveElement, bZ as clearPress, t as transitionStatusMapping, be as triggerOpenStateMapping, x as ios, a2 as FloatingPortal, a6 as popupStateMapping, a3 as InternalBackdrop, a4 as inertValue, a5 as DROPDOWN_COLLISION_AVOIDANCE, n as FloatingFocusManager, S as SafeReact, r as error, b_ as chipRemovePress } from './useScrollLock-es.js';
3
+ import { f as formatErrorMessage, c as EMPTY_ARRAY, a as useRefWithInit, E as EMPTY_OBJECT, N as NOOP, m as mergeProps, b as useMergedRefs, u as useRenderElement } from './useRenderElement-es.js';
4
+ import { h as hasNullItemLabel, e as compareItemEquality, n as stringifyAsLabel, a as useFormContext, b as useFieldRootContext, c as useLabelableId, E as isGroupedItems, G as findSelectionIndex, s as stringifyAsValue, d as useRegisterFieldControl, H as selectedValueIncludes, B as removeItem, i as useFloatingRootContext, j as useListNavigation, l as useOnFirstRender, m as defaultItemEquality, o as areArraysEqual, f as fieldValidityMapping, u as useLabelableContext, k as useTypeahead, r as resolveAriaLabelledBy, p as isMouseWithinBounds, F as FieldRootContext, I as DEFAULT_FIELD_ROOT_CONTEXT, J as DEFAULT_FIELD_STATE_ATTRIBUTES, C as CompositeList, w as useAnchorPositioning, v as useAnchoredPopupScrollLock, x as usePositioner, z as getDisabledMountTransitionStyles, A as useCompositeListItem, g as findItemIndex, K as getDefaultLabelId, q as resolveMultipleLabels, t as resolveSelectedLabel } from './useCompositeListItem-es.js';
5
+ import { jsx, jsxs } from 'react/jsx-runtime';
6
+ import * as ReactDOM from 'react-dom';
7
+ import { s as stringifyLocale } from './stringifyLocale-es.js';
8
+ import { i as isScrollableY } from './scrollable-es.js';
9
+ import { u as useLabel } from './useLabel-es.js';
10
+
11
+ /**
12
+ * Positional arguments are deliberate: property names of an options object
13
+ * don't minify, and the signature is locked to the caller via `typeof` on the
14
+ * `grid` option of `useListNavigation`.
15
+ *
16
+ * The injected grid navigator only ever operates on a uniform 1x1 grid (sizes are
17
+ * always `1x1` and packing is never dense), so the cell-map machinery that supports
18
+ * multi-cell items collapses to an identity transform over the item list. Calling
19
+ * `getGridNavigatedIndex` directly keeps the cell-map helpers
20
+ * (`createGridCellMap`/`getGridCellIndexOfCorner`/`getGridCellIndices`) out of
21
+ * grid-combobox bundles.
22
+ */
23
+ function gridNavigation(event, prevIndex, listRef, orientation, loopFocus, rtl, disabledIndices, minIndex, maxIndex, cols = 2) {
24
+ const nextIndex = getGridNavigatedIndex(listRef.current, {
25
+ event,
26
+ orientation,
27
+ loopFocus,
28
+ rtl,
29
+ cols,
30
+ disabledIndices,
31
+ minIndex,
32
+ maxIndex,
33
+ // An out-of-range previous index falls back to the first enabled item.
34
+ prevIndex: prevIndex > maxIndex ? minIndex : prevIndex,
35
+ stopEvent: true
36
+ });
37
+
38
+ // `getGridNavigatedIndex` can return an out-of-bounds sentinel (e.g. `-1` when there is no
39
+ // previous item to move from); surface that as `undefined` so the caller treats it as
40
+ // "no navigation" rather than highlighting index `-1`.
41
+ return isIndexOutOfListBounds(listRef.current, nextIndex) ? undefined : nextIndex;
42
+ }
43
+
44
+ const ComboboxRootContext = /*#__PURE__*/React.createContext(undefined);
45
+ if (process.env.NODE_ENV !== "production") ComboboxRootContext.displayName = "ComboboxRootContext";
46
+ const ComboboxFloatingContext = /*#__PURE__*/React.createContext(undefined);
47
+ if (process.env.NODE_ENV !== "production") ComboboxFloatingContext.displayName = "ComboboxFloatingContext";
48
+ const ComboboxDerivedItemsContext = /*#__PURE__*/React.createContext(undefined);
49
+ if (process.env.NODE_ENV !== "production") ComboboxDerivedItemsContext.displayName = "ComboboxDerivedItemsContext";
50
+ const ComboboxHasItemsContext = /*#__PURE__*/React.createContext(false);
51
+ // `inputValue` can't be placed in the store.
52
+ // https://github.com/mui/base-ui/issues/2703
53
+ if (process.env.NODE_ENV !== "production") ComboboxHasItemsContext.displayName = "ComboboxHasItemsContext";
54
+ const ComboboxInputValueContext = /*#__PURE__*/React.createContext('');
55
+ if (process.env.NODE_ENV !== "production") ComboboxInputValueContext.displayName = "ComboboxInputValueContext";
56
+ function useComboboxRootContext() {
57
+ const context = React.useContext(ComboboxRootContext);
58
+ if (!context) {
59
+ throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: ComboboxRootContext is missing. Combobox parts must be placed within <Combobox.Root>.' : formatErrorMessage(22));
60
+ }
61
+ return context;
62
+ }
63
+ function useComboboxFloatingContext() {
64
+ const context = React.useContext(ComboboxFloatingContext);
65
+ if (!context) {
66
+ throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: ComboboxFloatingContext is missing. Combobox parts must be placed within <Combobox.Root>.' : formatErrorMessage(23));
67
+ }
68
+ return context;
69
+ }
70
+ function useComboboxDerivedItemsContext() {
71
+ const context = React.useContext(ComboboxDerivedItemsContext);
72
+ if (!context) {
73
+ throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: ComboboxItemsContext is missing. Combobox parts must be placed within <Combobox.Root>.' : formatErrorMessage(24));
74
+ }
75
+ return context;
76
+ }
77
+ function useComboboxInputValueContext() {
78
+ return React.useContext(ComboboxInputValueContext);
79
+ }
80
+ function useComboboxHasItemsContext() {
81
+ return React.useContext(ComboboxHasItemsContext);
82
+ }
83
+
84
+ const selectors = {
85
+ id: state => state.id,
86
+ labelId: state => state.labelId,
87
+ items: state => state.items,
88
+ selectedValue: state => state.selectedValue,
89
+ hasSelectionChips: state => {
90
+ const selectedValue = state.selectedValue;
91
+ return Array.isArray(selectedValue) && selectedValue.length > 0;
92
+ },
93
+ hasSelectedValue: state => {
94
+ const {
95
+ selectedValue,
96
+ selectionMode
97
+ } = state;
98
+ if (selectedValue == null) {
99
+ return false;
100
+ }
101
+ if (selectionMode === 'multiple' && Array.isArray(selectedValue)) {
102
+ return selectedValue.length > 0;
103
+ }
104
+ return true;
105
+ },
106
+ hasNullItemLabel: (state, enabled) => {
107
+ return enabled ? hasNullItemLabel(state.items) : false;
108
+ },
109
+ open: state => state.open,
110
+ mounted: state => state.mounted,
111
+ forceMounted: state => state.forceMounted,
112
+ inline: state => state.inline,
113
+ activeIndex: state => state.activeIndex,
114
+ selectedIndex: state => state.selectedIndex,
115
+ isActive: (state, index) => state.activeIndex === index,
116
+ isSelected: (state, itemValue) => {
117
+ const comparer = state.isItemEqualToValue;
118
+ const selectedValue = state.selectedValue;
119
+ if (Array.isArray(selectedValue)) {
120
+ return selectedValue.some(selectedItem => compareItemEquality(itemValue, selectedItem, comparer));
121
+ }
122
+ return compareItemEquality(itemValue, selectedValue, comparer);
123
+ },
124
+ transitionStatus: state => state.transitionStatus,
125
+ popupProps: state => state.popupProps,
126
+ listProps: state => state.listProps,
127
+ inputProps: state => state.inputProps,
128
+ triggerProps: state => state.triggerProps,
129
+ itemProps: state => state.itemProps,
130
+ positionerElement: state => state.positionerElement,
131
+ listElement: state => state.listElement,
132
+ popupId: state => state.popupId,
133
+ triggerElement: state => state.triggerElement,
134
+ inputElement: state => state.inputElement,
135
+ inputGroupElement: state => state.inputGroupElement,
136
+ popupSide: state => state.popupSide,
137
+ openMethod: state => state.openMethod,
138
+ inputInsidePopup: state => state.inputInsidePopup,
139
+ inputOwnsFormValue: state => state.inputOwnsFormValue,
140
+ selectionMode: state => state.selectionMode,
141
+ name: state => state.name,
142
+ form: state => state.form,
143
+ disabled: state => state.disabled,
144
+ readOnly: state => state.readOnly,
145
+ required: state => state.required,
146
+ grid: state => state.grid,
147
+ virtualized: state => state.virtualized,
148
+ itemToStringLabel: state => state.itemToStringLabel,
149
+ isItemEqualToValue: state => state.isItemEqualToValue,
150
+ modal: state => state.modal,
151
+ autoHighlight: state => state.autoHighlight
152
+ };
153
+
154
+ /**
155
+ * Derives the default id assigned to `Combobox.Popup` when the input is rendered inside it.
156
+ * Shared by the popup (which applies it) and the trigger (which references it via `aria-controls`)
157
+ * so the convention only lives in one place.
158
+ */
159
+ function getComboboxPopupId(rootId) {
160
+ return rootId == null ? undefined : `${rootId}-popup`;
161
+ }
162
+
163
+ /**
164
+ * Enhanced filter using Intl.Collator for more robust string matching.
165
+ * Uses the provided `itemToStringLabel` function if available, otherwise falls back to:
166
+ * • When `item` is an object with a `value` property, that property is used.
167
+ * • When `item` is a primitive (e.g. `string`), it is used directly.
168
+ */
169
+ function createCollatorItemFilter(collatorFilter, itemToStringLabel) {
170
+ return (item, query) => {
171
+ if (item == null) {
172
+ return false;
173
+ }
174
+ return collatorFilter.contains(item, query, itemToStringLabel);
175
+ };
176
+ }
177
+
178
+ /**
179
+ * Enhanced filter for single selection mode using Intl.Collator that shows all items
180
+ * when query is empty or matches the current selection, making it easier to browse options.
181
+ */
182
+ function createSingleSelectionCollatorFilter(collatorFilter, itemToStringLabel, selectedValue) {
183
+ return (item, query) => {
184
+ if (item == null) {
185
+ return false;
186
+ }
187
+ if (!query) {
188
+ return true;
189
+ }
190
+ const selectedString = selectedValue != null ? stringifyAsLabel(selectedValue, itemToStringLabel) : '';
191
+
192
+ // Handle case-insensitive matching consistently
193
+ if (selectedString && collatorFilter.contains(selectedString, query) && selectedString.length === query.length) {
194
+ return true;
195
+ }
196
+ return collatorFilter.contains(item, query, itemToStringLabel);
197
+ };
198
+ }
199
+
200
+ const filterCache = new Map();
201
+ function getFilter(options = {}) {
202
+ const mergedOptions = {
203
+ usage: 'search',
204
+ sensitivity: 'base',
205
+ ignorePunctuation: true,
206
+ ...options
207
+ };
208
+ const cacheKey = `${stringifyLocale(options.locale)}|${JSON.stringify(mergedOptions)}`;
209
+ const cachedFilter = filterCache.get(cacheKey);
210
+ if (cachedFilter) {
211
+ return cachedFilter;
212
+ }
213
+ const collator = new Intl.Collator(options.locale, mergedOptions);
214
+ const filter = {
215
+ contains(item, query, itemToString) {
216
+ if (!query) {
217
+ return true;
218
+ }
219
+ const itemString = stringifyAsLabel(item, itemToString);
220
+ for (let i = 0; i <= itemString.length - query.length; i += 1) {
221
+ if (collator.compare(itemString.slice(i, i + query.length), query) === 0) {
222
+ return true;
223
+ }
224
+ }
225
+ return false;
226
+ },
227
+ startsWith(item, query, itemToString) {
228
+ if (!query) {
229
+ return true;
230
+ }
231
+ const itemString = stringifyAsLabel(item, itemToString);
232
+ return collator.compare(itemString.slice(0, query.length), query) === 0;
233
+ },
234
+ endsWith(item, query, itemToString) {
235
+ if (!query) {
236
+ return true;
237
+ }
238
+ const itemString = stringifyAsLabel(item, itemToString);
239
+ const queryLength = query.length;
240
+ return itemString.length >= queryLength && collator.compare(itemString.slice(itemString.length - queryLength), query) === 0;
241
+ }
242
+ };
243
+ filterCache.set(cacheKey, filter);
244
+ return filter;
245
+ }
246
+
247
+ /**
248
+ * Matches items against a query using `Intl.Collator` for robust string matching.
249
+ */
250
+ const useCoreFilter = getFilter;
251
+ /**
252
+ * Matches items against a query using `Intl.Collator` for robust string matching.
253
+ */
254
+ function useComboboxFilter(options = {}) {
255
+ const {
256
+ multiple = false,
257
+ value,
258
+ ...collatorOptions
259
+ } = options;
260
+ const coreFilter = getFilter(collatorOptions);
261
+ const contains = React.useCallback((item, query, itemToString) => {
262
+ if (multiple) {
263
+ return createCollatorItemFilter(coreFilter, itemToString)(item, query);
264
+ }
265
+ return createSingleSelectionCollatorFilter(coreFilter, itemToString, value)(item, query);
266
+ }, [coreFilter, value, multiple]);
267
+ return React.useMemo(() => ({
268
+ ...coreFilter,
269
+ contains
270
+ }), [contains, coreFilter]);
271
+ }
272
+
273
+ const NO_ACTIVE_VALUE = Symbol('none');
274
+ const INITIAL_LAST_HIGHLIGHT = {
275
+ value: NO_ACTIVE_VALUE,
276
+ index: -1
277
+ };
278
+
279
+ function AriaCombobox(props) {
280
+ const {
281
+ id: idProp,
282
+ onOpenChangeComplete: onOpenChangeCompleteProp,
283
+ defaultSelectedValue = null,
284
+ selectedValue: selectedValueProp,
285
+ onSelectedValueChange,
286
+ defaultInputValue: defaultInputValueProp,
287
+ inputValue: inputValueProp,
288
+ open: openProp,
289
+ defaultOpen = false,
290
+ selectionMode,
291
+ onItemHighlighted: onItemHighlightedProp,
292
+ name: nameProp,
293
+ form,
294
+ disabled: disabledProp = false,
295
+ readOnly = false,
296
+ required = false,
297
+ inputRef: inputRefProp,
298
+ grid = false,
299
+ items,
300
+ filteredItems: filteredItemsProp,
301
+ filter: filterProp,
302
+ openOnInputClick = true,
303
+ autoHighlight = false,
304
+ keepHighlight = false,
305
+ highlightItemOnHover = true,
306
+ loopFocus = true,
307
+ itemToStringLabel,
308
+ itemToStringValue,
309
+ isItemEqualToValue = defaultItemEquality,
310
+ virtualized = false,
311
+ inline: inlineProp = false,
312
+ fillInputOnItemPress = true,
313
+ modal = false,
314
+ limit = -1,
315
+ autoComplete = 'list',
316
+ formAutoComplete,
317
+ locale,
318
+ submitOnItemClick = false
319
+ } = props;
320
+ const {
321
+ clearErrors
322
+ } = useFormContext();
323
+ const {
324
+ setDirty,
325
+ validityData,
326
+ setFilled,
327
+ name: fieldName,
328
+ disabled: fieldDisabled,
329
+ setTouched,
330
+ setFocused,
331
+ validationMode,
332
+ validation
333
+ } = useFieldRootContext();
334
+ const direction = useDirection();
335
+ const id = useLabelableId({
336
+ id: idProp
337
+ });
338
+ const collatorFilter = useCoreFilter({
339
+ locale
340
+ });
341
+ const [queryChangedAfterOpen, setQueryChangedAfterOpen] = React.useState(false);
342
+ const [closeQuery, setCloseQuery] = React.useState(null);
343
+ const listRef = React.useRef([]);
344
+ const labelsRef = React.useRef([]);
345
+ const popupRef = React.useRef(null);
346
+ const inputRef = React.useRef(null);
347
+ const startDismissRef = React.useRef(null);
348
+ const endDismissRef = React.useRef(null);
349
+ const emptyRef = React.useRef(null);
350
+ const keyboardActiveRef = React.useRef(true);
351
+ const hadInputClearRef = React.useRef(false);
352
+ const chipsContainerRef = React.useRef(null);
353
+ const clearRef = React.useRef(null);
354
+ const selectionEventRef = React.useRef(null);
355
+ const lastHighlightRef = React.useRef(INITIAL_LAST_HIGHLIGHT);
356
+ const pendingQueryHighlightRef = React.useRef(null);
357
+
358
+ /**
359
+ * Contains the currently visible list of item values post-filtering.
360
+ */
361
+ const valuesRef = React.useRef([]);
362
+ /**
363
+ * The item element that received the last `pointerdown`, used to detect whether a
364
+ * `mouseup` on an item belongs to a drag-select gesture that started elsewhere.
365
+ */
366
+ const pointerDownItemRef = React.useRef(null);
367
+ const disabled = fieldDisabled || disabledProp;
368
+ const name = fieldName ?? nameProp;
369
+ const multiple = selectionMode === 'multiple';
370
+ const single = selectionMode === 'single';
371
+ const hasInputValue = inputValueProp !== undefined || defaultInputValueProp !== undefined;
372
+ const hasItems = items !== undefined;
373
+ const hasFilteredItemsProp = filteredItemsProp !== undefined;
374
+ let autoHighlightMode;
375
+ if (autoHighlight === 'always') {
376
+ autoHighlightMode = 'always';
377
+ } else {
378
+ autoHighlightMode = autoHighlight ? 'input-change' : false;
379
+ }
380
+ const [selectedValue, setSelectedValueUnwrapped] = useControlled({
381
+ controlled: selectedValueProp,
382
+ default: multiple ? defaultSelectedValue ?? EMPTY_ARRAY : defaultSelectedValue,
383
+ name: 'Combobox',
384
+ state: 'selectedValue'
385
+ });
386
+ const filter = React.useMemo(() => {
387
+ if (filterProp === null) {
388
+ return () => true;
389
+ }
390
+ if (filterProp !== undefined) {
391
+ return filterProp;
392
+ }
393
+ // `shouldBypassFiltering` already empties the query whenever a single selection's label
394
+ // matches it exactly, so the filter never needs a selection-aware variant here.
395
+ return createCollatorItemFilter(collatorFilter, itemToStringLabel);
396
+ }, [filterProp, collatorFilter, itemToStringLabel]);
397
+
398
+ // If neither inputValue nor defaultInputValue are provided, derive it from the
399
+ // selected value for single mode so the input reflects the selection on mount.
400
+ const initialDefaultInputValue = useRefWithInit(() => {
401
+ if (hasInputValue) {
402
+ return defaultInputValueProp ?? '';
403
+ }
404
+ if (single) {
405
+ return stringifyAsLabel(selectedValue, itemToStringLabel);
406
+ }
407
+ return '';
408
+ }).current;
409
+ const [inputValue, setInputValueUnwrapped] = useControlled({
410
+ controlled: inputValueProp,
411
+ default: initialDefaultInputValue,
412
+ name: 'Combobox',
413
+ state: 'inputValue'
414
+ });
415
+ const [open, setOpenUnwrapped] = useControlled({
416
+ controlled: openProp,
417
+ default: defaultOpen,
418
+ name: 'Combobox',
419
+ state: 'open'
420
+ });
421
+ const isGrouped = isGroupedItems(items);
422
+ const query = closeQuery ?? String(inputValue).trim();
423
+ const selectedLabelString = single ? stringifyAsLabel(selectedValue, itemToStringLabel) : '';
424
+ const shouldBypassFiltering = single && !queryChangedAfterOpen && query !== '' && selectedLabelString.length === query.length && collatorFilter.contains(selectedLabelString, query);
425
+ const filterQuery = shouldBypassFiltering ? '' : query;
426
+ const shouldIgnoreExternalFiltering = hasItems && hasFilteredItemsProp && shouldBypassFiltering;
427
+ const flatItems = React.useMemo(() => {
428
+ if (!items) {
429
+ return EMPTY_ARRAY;
430
+ }
431
+ if (isGrouped) {
432
+ return items.flatMap(group => group.items);
433
+ }
434
+ return items;
435
+ }, [items, isGrouped]);
436
+ const filteredItems = React.useMemo(() => {
437
+ if (filteredItemsProp && !shouldIgnoreExternalFiltering) {
438
+ return filteredItemsProp;
439
+ }
440
+ if (!items) {
441
+ return EMPTY_ARRAY;
442
+ }
443
+ if (isGrouped) {
444
+ const groupedItems = items;
445
+ const resultingGroups = [];
446
+ let currentCount = 0;
447
+ for (const group of groupedItems) {
448
+ if (limit > -1 && currentCount >= limit) {
449
+ break;
450
+ }
451
+ const remainingLimit = limit > -1 ? limit - currentCount : Infinity;
452
+ const itemsToTake = filterQuery === '' ? group.items.slice(0, remainingLimit) : [];
453
+ if (filterQuery !== '') {
454
+ for (const item of group.items) {
455
+ if (itemsToTake.length >= remainingLimit) {
456
+ break;
457
+ }
458
+ if (filter(item, filterQuery, itemToStringLabel)) {
459
+ itemsToTake.push(item);
460
+ }
461
+ }
462
+ }
463
+ if (itemsToTake.length > 0) {
464
+ const newGroup = {
465
+ ...group,
466
+ items: itemsToTake
467
+ };
468
+ resultingGroups.push(newGroup);
469
+ currentCount += itemsToTake.length;
470
+ }
471
+ }
472
+ return resultingGroups;
473
+ }
474
+ if (filterQuery === '') {
475
+ return limit > -1 ? flatItems.slice(0, limit) :
476
+ // The cast here is done as `flatItems` is readonly.
477
+ // valuesRef.current, a mutable ref, can be set to `flatFilteredItems`, which may
478
+ // reference this exact readonly value, creating a mutation risk.
479
+ // However, <Combobox.Item> can never mutate this value as the mutating effect
480
+ // bails early when `items` is provided, and this is only ever returned
481
+ // when `items` is provided due to the early return at the top of this hook.
482
+ flatItems;
483
+ }
484
+ const limitedItems = [];
485
+ for (const item of flatItems) {
486
+ if (limit > -1 && limitedItems.length >= limit) {
487
+ break;
488
+ }
489
+ if (filter(item, filterQuery, itemToStringLabel)) {
490
+ limitedItems.push(item);
491
+ }
492
+ }
493
+ return limitedItems;
494
+ }, [filteredItemsProp, shouldIgnoreExternalFiltering, items, isGrouped, filterQuery, limit, filter, itemToStringLabel, flatItems]);
495
+ const flatFilteredItems = React.useMemo(() => {
496
+ if (isGrouped) {
497
+ const groups = filteredItems;
498
+ return groups.flatMap(g => g.items);
499
+ }
500
+ return filteredItems;
501
+ }, [filteredItems, isGrouped]);
502
+ const store = useRefWithInit(() => {
503
+ // An inline list open on the first render never gets a closed pass of the closed-state
504
+ // sync effect below, and `items`-prop lists don't self-register their index the way
505
+ // individually rendered `<Combobox.Item>`s do, so the selected item was never highlighted.
506
+ // Seeding the index here lets list navigation highlight and scroll to the selection on
507
+ // mount. Computed once by construction, so a selection or list that resolves after mount
508
+ // doesn't move an existing highlight or scroll the list away.
509
+ let initialSelectedIndex = null;
510
+ if (inlineProp && open && hasItems && selectionMode !== 'none') {
511
+ initialSelectedIndex = findSelectionIndex(flatFilteredItems, selectedValue, isItemEqualToValue, multiple);
512
+ }
513
+ return new Store({
514
+ id,
515
+ labelId: undefined,
516
+ selectedValue,
517
+ open,
518
+ items,
519
+ selectionMode,
520
+ listRef,
521
+ labelsRef,
522
+ popupRef,
523
+ emptyRef,
524
+ inputRef,
525
+ startDismissRef,
526
+ endDismissRef,
527
+ keyboardActiveRef,
528
+ chipsContainerRef,
529
+ clearRef,
530
+ valuesRef,
531
+ pointerDownItemRef,
532
+ selectionEventRef,
533
+ name,
534
+ form,
535
+ disabled,
536
+ readOnly,
537
+ required,
538
+ grid,
539
+ virtualized,
540
+ openOnInputClick,
541
+ itemToStringLabel,
542
+ isItemEqualToValue,
543
+ modal,
544
+ autoHighlight: autoHighlightMode,
545
+ submitOnItemClick,
546
+ hasInputValue,
547
+ mounted: false,
548
+ forceMounted: false,
549
+ transitionStatus: 'idle',
550
+ inline: inlineProp,
551
+ activeIndex: null,
552
+ selectedIndex: initialSelectedIndex,
553
+ popupProps: {},
554
+ listProps: {},
555
+ inputProps: {},
556
+ triggerProps: {},
557
+ itemProps: EMPTY_OBJECT,
558
+ positionerElement: null,
559
+ listElement: null,
560
+ popupId: undefined,
561
+ triggerElement: null,
562
+ inputElement: null,
563
+ inputGroupElement: null,
564
+ popupSide: null,
565
+ openMethod: null,
566
+ inputInsidePopup: true,
567
+ // Avoid duplicate names in the server HTML. Popup inputs aren't rendered
568
+ // until after hydration, so the hidden input takes over then if needed.
569
+ inputOwnsFormValue: selectionMode === 'none',
570
+ // Placeholder callbacks replaced on first render
571
+ onOpenChangeComplete: NOOP,
572
+ setOpen: NOOP,
573
+ setInputValue: NOOP,
574
+ setSelectedValue: NOOP,
575
+ setIndices: NOOP,
576
+ handleSelection: NOOP,
577
+ forceMount: NOOP,
578
+ requestSubmit: NOOP
579
+ });
580
+ }).current;
581
+ const fieldRawValue = selectionMode === 'none' ? inputValue : selectedValue;
582
+ const fieldStringValue = React.useMemo(() => {
583
+ if (selectionMode === 'none') {
584
+ return fieldRawValue;
585
+ }
586
+ if (Array.isArray(selectedValue)) {
587
+ return selectedValue.map(value => stringifyAsValue(value, itemToStringValue));
588
+ }
589
+ return stringifyAsValue(selectedValue, itemToStringValue);
590
+ }, [fieldRawValue, itemToStringValue, selectionMode, selectedValue]);
591
+ const onItemHighlighted = useStableCallback(onItemHighlightedProp);
592
+ const onOpenChangeComplete = useStableCallback(onOpenChangeCompleteProp);
593
+ const activeIndex = useStore(store, selectors.activeIndex);
594
+ const selectedIndex = useStore(store, selectors.selectedIndex);
595
+ const positionerElement = useStore(store, selectors.positionerElement);
596
+ const listElement = useStore(store, selectors.listElement);
597
+ const triggerElement = useStore(store, selectors.triggerElement);
598
+ const inputElement = useStore(store, selectors.inputElement);
599
+ const inputGroupElement = useStore(store, selectors.inputGroupElement);
600
+ const inline = useStore(store, selectors.inline);
601
+ const inputInsidePopup = useStore(store, selectors.inputInsidePopup);
602
+ const inputOwnsFormValue = useStore(store, selectors.inputOwnsFormValue);
603
+ const triggerRef = useValueAsRef(triggerElement);
604
+ const {
605
+ mounted,
606
+ setMounted,
607
+ transitionStatus
608
+ } = useTransitionStatus(open);
609
+ const {
610
+ openMethod,
611
+ triggerProps
612
+ } = useOpenInteractionType(open);
613
+ const getStringifiedValueForForm = useStableCallback(() => fieldStringValue);
614
+ useRegisterFieldControl(inputInsidePopup ? triggerRef : inputRef, id, fieldRawValue, getStringifiedValueForForm, !disabled, nameProp);
615
+ const forceMount = useStableCallback(() => {
616
+ if (items) {
617
+ // Ensure typeahead works on a closed list.
618
+ labelsRef.current = flatFilteredItems.map(item => stringifyAsLabel(item, itemToStringLabel));
619
+ } else {
620
+ store.set('forceMounted', true);
621
+ }
622
+ });
623
+
624
+ /**
625
+ * Emits `onItemHighlighted` for the item at `index`, or clears the highlight when `index` is `-1`
626
+ * (a no-op if nothing was highlighted). Keeps `lastHighlightRef` in sync with what was emitted.
627
+ */
628
+ const emitHighlight = useStableCallback((value, index, type) => {
629
+ if (index === -1) {
630
+ if (lastHighlightRef.current === INITIAL_LAST_HIGHLIGHT) {
631
+ return;
632
+ }
633
+ lastHighlightRef.current = INITIAL_LAST_HIGHLIGHT;
634
+ } else {
635
+ lastHighlightRef.current = {
636
+ value,
637
+ index
638
+ };
639
+ }
640
+ onItemHighlighted(value, createGenericEventDetails(type, undefined, {
641
+ index
642
+ }));
643
+ });
644
+ const setIndices = useStableCallback(options => {
645
+ store.update(options);
646
+ const activeIndexOption = options.activeIndex;
647
+ if (activeIndexOption === undefined) {
648
+ return;
649
+ }
650
+ const type = options.type || none;
651
+ if (activeIndexOption === null) {
652
+ emitHighlight(undefined, -1, type);
653
+ } else {
654
+ emitHighlight(valuesRef.current[activeIndexOption], activeIndexOption, type);
655
+ }
656
+ });
657
+ const setInputValue = useStableCallback((next, eventDetails) => {
658
+ hadInputClearRef.current = eventDetails.reason === inputClear;
659
+ props.onInputValueChange?.(next, eventDetails);
660
+ if (eventDetails.isCanceled) {
661
+ return;
662
+ }
663
+
664
+ // If user is typing, ensure we don't auto-highlight on open due to a race
665
+ // with the post-open effect that sets this flag.
666
+ if (eventDetails.reason === inputChange) {
667
+ // A controlled popup may ignore a close request. Resuming input proves the popup
668
+ // is remaining open, so release the query captured for an exit animation.
669
+ if (open && closeQuery !== null) {
670
+ setCloseQuery(null);
671
+ }
672
+ const event = eventDetails.event;
673
+ const inputType = event.inputType;
674
+ // Treat composition commits as typed input; autofill may omit `inputType` or
675
+ // report `insertReplacementText`.
676
+ const isTypedInput = event.type === 'compositionend' || inputType != null && inputType !== '' && inputType !== 'insertReplacementText';
677
+ if (isTypedInput) {
678
+ const hasQuery = next.trim() !== '';
679
+ if (hasQuery) {
680
+ setQueryChangedAfterOpen(true);
681
+ }
682
+ // Defer index updates until after the filtered items have been derived to ensure
683
+ // `onItemHighlighted` receives the latest item.
684
+ pendingQueryHighlightRef.current = {
685
+ hasQuery
686
+ };
687
+
688
+ // Virtualized lists own their scroller. Reset regular lists directly so a stale
689
+ // composite registry cannot select a reordered item and scrolling cannot escape
690
+ // the popup.
691
+ const list = store.state.listElement;
692
+ if (!store.state.virtualized && list) {
693
+ const popup = popupRef.current;
694
+ for (const ancestor of getOverflowAncestors(list.firstElementChild ?? list)) {
695
+ if (!isHTMLElement(ancestor) || (popup ? !contains(popup, ancestor) : ancestor.getAttribute('role') === 'dialog')) {
696
+ break;
697
+ }
698
+ if (isScrollableY(ancestor)) {
699
+ ancestor.scrollTop = 0;
700
+ break;
701
+ }
702
+ }
703
+ }
704
+ if (hasQuery && autoHighlightMode && store.state.activeIndex == null && (open || inline)) {
705
+ store.set('activeIndex', 0);
706
+ }
707
+ }
708
+ } else if (eventDetails.reason === inputClear && next === '' && store.state.inputInsidePopup) {
709
+ // A programmatic clear of an active query (e.g. after selecting an item with the
710
+ // input inside the popup): restore the highlight to the selected item.
711
+ pendingQueryHighlightRef.current = {
712
+ hasQuery: false,
713
+ selection: true
714
+ };
715
+ }
716
+ setInputValueUnwrapped(next);
717
+ });
718
+ const setOpen = useStableCallback((nextOpen, eventDetails) => {
719
+ if (open === nextOpen) {
720
+ return;
721
+ }
722
+
723
+ // If the `Empty` component is not used, the positioner or popup should be hidden
724
+ // with CSS. In this case, allow the Escape key to bubble to close a parent popup
725
+ // if there are no items to show.
726
+ if (eventDetails.reason === escapeKey && hasItems && flatFilteredItems.length === 0 && !emptyRef.current) {
727
+ eventDetails.allowPropagation();
728
+ }
729
+ props.onOpenChange?.(nextOpen, eventDetails);
730
+ if (eventDetails.isCanceled) {
731
+ return;
732
+ }
733
+
734
+ // If reopening interrupts the close animation, handleUnmount won't run to clear the
735
+ // frozen closeQuery and pending popup input.
736
+ if (nextOpen && inputInsidePopup && !inline && closeQuery !== null) {
737
+ setQueryChangedAfterOpen(false);
738
+ setCloseQuery(null);
739
+ if (inputValue !== '' && eventDetails.reason !== inputChange) {
740
+ setInputValue('', createChangeEventDetails(inputClear, eventDetails.event));
741
+ }
742
+ }
743
+ if (!nextOpen && queryChangedAfterOpen) {
744
+ if (single) {
745
+ if (!inline) {
746
+ setCloseQuery(query);
747
+ }
748
+ // Avoid a flicker when closing the popup with an empty query.
749
+ if (query === '') {
750
+ setQueryChangedAfterOpen(false);
751
+ }
752
+ } else if (multiple) {
753
+ if (!inline) {
754
+ // Freeze the current query so filtering remains stable while exiting.
755
+ setCloseQuery(query);
756
+ }
757
+ if (inputInsidePopup) {
758
+ setIndices({
759
+ activeIndex: null
760
+ });
761
+ }
762
+
763
+ // Clear the input immediately on close while retaining filtering via closeQuery for exit animations
764
+ // if the input is outside the popup. When the input is inside the popup, defer the clear until
765
+ // unmount so the filtered list doesn't flash to unfiltered during the exit animation.
766
+ if (!inputInsidePopup || inline) {
767
+ setInputValue('', createChangeEventDetails(inputClear, eventDetails.event));
768
+ }
769
+ }
770
+ }
771
+ setOpenUnwrapped(nextOpen);
772
+ if (!nextOpen && inputInsidePopup && (eventDetails.reason === focusOut || eventDetails.reason === outsidePress)) {
773
+ setTouched(true);
774
+ setFocused(false);
775
+ if (validationMode === 'onBlur') {
776
+ const valueToValidate = selectionMode === 'none' ? inputValue : selectedValue;
777
+ validation.commit(valueToValidate);
778
+ }
779
+ }
780
+ });
781
+ const setSelectedValue = useStableCallback((nextValue, eventDetails) => {
782
+ // Cast to `any` due to conditional value type (single vs. multiple).
783
+ // The runtime implementation already ensures the correct value shape.
784
+ onSelectedValueChange?.(nextValue, eventDetails);
785
+ if (eventDetails.isCanceled) {
786
+ return;
787
+ }
788
+ setSelectedValueUnwrapped(nextValue);
789
+ const shouldFillInput = selectionMode === 'none' && popupRef.current && fillInputOnItemPress || single && !store.state.inputInsidePopup;
790
+ if (shouldFillInput) {
791
+ setInputValue(stringifyAsLabel(nextValue, itemToStringLabel), createChangeEventDetails(eventDetails.reason, eventDetails.event));
792
+ }
793
+ });
794
+ const handleSelection = useStableCallback((event, itemValue) => {
795
+ const targetEl = getTarget(event);
796
+ const overrideEvent = selectionEventRef.current ?? event;
797
+ selectionEventRef.current = null;
798
+ const eventDetails = createChangeEventDetails(itemPress, overrideEvent);
799
+
800
+ // Let the link handle the click.
801
+ const href = targetEl?.closest('a')?.getAttribute('href');
802
+ if (href) {
803
+ if (href.startsWith('#')) {
804
+ setOpen(false, eventDetails);
805
+ }
806
+ return;
807
+ }
808
+ if (multiple) {
809
+ const currentSelectedValue = Array.isArray(selectedValue) ? selectedValue : [];
810
+ const isCurrentlySelected = selectedValueIncludes(currentSelectedValue, itemValue, isItemEqualToValue);
811
+ const nextValue = isCurrentlySelected ? removeItem(currentSelectedValue, itemValue, isItemEqualToValue) : [...currentSelectedValue, itemValue];
812
+ setSelectedValue(nextValue, eventDetails);
813
+ if (eventDetails.isCanceled) {
814
+ return;
815
+ }
816
+ const wasFiltering = inputRef.current ? inputRef.current.value.trim() !== '' : false;
817
+ if (!wasFiltering) {
818
+ return;
819
+ }
820
+ if (store.state.inputInsidePopup) {
821
+ setInputValue('', createChangeEventDetails(inputClear, eventDetails.event));
822
+ } else {
823
+ setOpen(false, eventDetails);
824
+ }
825
+ } else {
826
+ setSelectedValue(itemValue, eventDetails);
827
+ if (eventDetails.isCanceled) {
828
+ return;
829
+ }
830
+ setOpen(false, eventDetails);
831
+ }
832
+ });
833
+ const requestSubmit = useStableCallback(() => {
834
+ const formElement = validation.inputRef.current?.form ?? store.state.inputElement?.form;
835
+ if (formElement && typeof formElement.requestSubmit === 'function') {
836
+ formElement.requestSubmit();
837
+ }
838
+ });
839
+ const handleUnmount = useStableCallback(() => {
840
+ setMounted(false);
841
+ onOpenChangeComplete?.(false);
842
+ setQueryChangedAfterOpen(false);
843
+ setCloseQuery(null);
844
+ if (selectionMode === 'none') {
845
+ setIndices({
846
+ activeIndex: null,
847
+ selectedIndex: null
848
+ });
849
+ } else {
850
+ setIndices({
851
+ activeIndex: null
852
+ });
853
+ }
854
+
855
+ // Multiple selection mode:
856
+ // If the user typed a filter and didn't select in multiple mode, clear the input
857
+ // after close completes to avoid mid-exit flicker and start fresh on next open.
858
+ if (multiple && inputRef.current && inputRef.current.value !== '' && !hadInputClearRef.current) {
859
+ setInputValue('', createChangeEventDetails(inputClear));
860
+ }
861
+
862
+ // Single selection mode:
863
+ // - If input is rendered inside the popup, clear it so the next open is blank
864
+ // - If input is outside the popup, sync it to the selected value
865
+ if (single) {
866
+ if (store.state.inputInsidePopup) {
867
+ if (inputRef.current && inputRef.current.value !== '') {
868
+ setInputValue('', createChangeEventDetails(inputClear));
869
+ }
870
+ } else {
871
+ const stringVal = stringifyAsLabel(selectedValue, itemToStringLabel);
872
+ if (inputRef.current && inputRef.current.value !== stringVal) {
873
+ // If no selection was made, treat this as clearing the typed filter.
874
+ const reason = stringVal === '' ? inputClear : none;
875
+ setInputValue(stringVal, createChangeEventDetails(reason));
876
+ }
877
+ }
878
+ }
879
+ });
880
+
881
+ // Support composing the Dialog component around an inline combobox.
882
+ // `[role="dialog"]` is more interoperable than using a context, e.g. it can work
883
+ // with third-party modal libraries, though the limitation is that the closest
884
+ // `role=dialog` part must be the animated element.
885
+ const resolvedPopupRef = React.useMemo(() => {
886
+ if (inline && positionerElement) {
887
+ return {
888
+ current: positionerElement.closest('[role="dialog"]')
889
+ };
890
+ }
891
+ return popupRef;
892
+ }, [inline, positionerElement]);
893
+ useOpenChangeComplete({
894
+ enabled: !props.actionsRef,
895
+ open,
896
+ ref: resolvedPopupRef,
897
+ onComplete() {
898
+ if (!open) {
899
+ handleUnmount();
900
+ }
901
+ }
902
+ });
903
+ React.useImperativeHandle(props.actionsRef, () => ({
904
+ unmount: handleUnmount
905
+ }), [handleUnmount]);
906
+ useIsoLayoutEffect(function syncClosedState() {
907
+ if (open) {
908
+ return;
909
+ }
910
+
911
+ // State-driven (not tied to the internal event path) so controlled closes
912
+ // also clear a pointerdown that never received a matching item mouseup.
913
+ pointerDownItemRef.current = null;
914
+ if (selectionMode === 'none') {
915
+ return;
916
+ }
917
+
918
+ // Without `items`, look the selection up in the live registry of mounted item
919
+ // values (the list stays mounted while closed when closed-state features need
920
+ // it — trigger interaction and rendered-label autofill force-mount it). Mounted
921
+ // items re-assert the index themselves when their registration moves; when
922
+ // nothing is mounted the lookup resolves to `null` and each item re-registers
923
+ // the index on the next open.
924
+ const registry = hasItems ? flatItems : valuesRef.current;
925
+ setIndices({
926
+ selectedIndex: findSelectionIndex(registry, selectedValue, isItemEqualToValue, multiple)
927
+ });
928
+ }, [open, selectedValue, selectionMode, multiple, hasItems, flatItems, isItemEqualToValue, setIndices]);
929
+ useIsoLayoutEffect(() => {
930
+ if (items) {
931
+ valuesRef.current = flatFilteredItems;
932
+ listRef.current.length = flatFilteredItems.length;
933
+ }
934
+ }, [items, flatFilteredItems]);
935
+ useIsoLayoutEffect(() => {
936
+ const pendingHighlight = pendingQueryHighlightRef.current;
937
+ if (pendingHighlight) {
938
+ // A directly rendered list remains visible when the popup state is closed, while a
939
+ // kept-mounted Positioner is hidden and should stay inert.
940
+ const listIsNavigable = open || inline || store.state.positionerElement?.hidden === false;
941
+ if (pendingHighlight.hasQuery) {
942
+ if (autoHighlightMode && listIsNavigable) {
943
+ store.set('activeIndex', 0);
944
+ }
945
+ pendingQueryHighlightRef.current = null;
946
+ } else if (String(inputValue).trim() === '') {
947
+ // Only handle the clear once it has committed (a controlled input may reject it),
948
+ // so a restore cannot fire while a query is still active.
949
+ pendingQueryHighlightRef.current = null;
950
+ if (listIsNavigable) {
951
+ const clearedBySelection = pendingHighlight.selection;
952
+ if (autoHighlightMode === 'always' && !clearedBySelection && store.state.selectionMode === 'none') {
953
+ // There is no selection to restore in Autocomplete. Keep the first-item reset
954
+ // synchronous so list navigation sees it before a directly rendered list closes.
955
+ store.set('activeIndex', 0);
956
+ }
957
+
958
+ // Items re-mounted by the clear publish their composite indices in a follow-up
959
+ // commit, so the item registries are mid-update here. Defer past React's cascade.
960
+ queueMicrotask(() => {
961
+ if (!store.state.open && !store.state.inline || inputRef.current && inputRef.current.value.trim() !== '') {
962
+ return;
963
+ }
964
+
965
+ // Return the highlight to the selected item, the same anchor the popup uses
966
+ // when it first opens. Read the selection through the store so consumers can
967
+ // pass an inline `isItemEqualToValue` or a fresh `selectedValue` array without
968
+ // re-running this effect on every render.
969
+ const currentSelectedValue = store.state.selectedValue;
970
+ const isMultiple = store.state.selectionMode === 'multiple';
971
+ const lastSelectedValue = isMultiple && Array.isArray(currentSelectedValue) ? currentSelectedValue[currentSelectedValue.length - 1] : currentSelectedValue;
972
+ const hasSelection = store.state.selectionMode !== 'none' && lastSelectedValue != null;
973
+ if (hasSelection || clearedBySelection) {
974
+ const registry = hasItems || hasFilteredItemsProp ? flatFilteredItems : valuesRef.current;
975
+ // A selection that is no longer in the list drops the highlight rather than
976
+ // leaving it on whichever item now occupies that index.
977
+ store.set('activeIndex', hasSelection ? findSelectionIndex(registry, currentSelectedValue, store.state.isItemEqualToValue, isMultiple) : null);
978
+ } else if (autoHighlightMode === 'always') {
979
+ store.set('activeIndex', 0);
980
+ }
981
+ });
982
+ }
983
+ }
984
+ }
985
+ if (!open && !inline) {
986
+ return;
987
+ }
988
+ const shouldUseFlatFilteredItems = hasItems || hasFilteredItemsProp;
989
+ const candidateItems = shouldUseFlatFilteredItems ? flatFilteredItems : valuesRef.current;
990
+ const storeActiveIndex = store.state.activeIndex;
991
+ if (storeActiveIndex == null) {
992
+ if (autoHighlightMode === 'always' && candidateItems.length > 0) {
993
+ store.set('activeIndex', 0);
994
+ return;
995
+ }
996
+ emitHighlight(undefined, -1, none);
997
+ return;
998
+ }
999
+ if (storeActiveIndex >= candidateItems.length) {
1000
+ emitHighlight(undefined, -1, none);
1001
+ store.set('activeIndex', null);
1002
+ return;
1003
+ }
1004
+ const itemValue = candidateItems[storeActiveIndex];
1005
+ const previouslyHighlightedItemValue = lastHighlightRef.current.value;
1006
+ const isSameItem = previouslyHighlightedItemValue !== NO_ACTIVE_VALUE && compareItemEquality(itemValue, previouslyHighlightedItemValue, store.state.isItemEqualToValue);
1007
+ if (lastHighlightRef.current.index !== storeActiveIndex || !isSameItem) {
1008
+ emitHighlight(itemValue, storeActiveIndex, none);
1009
+ }
1010
+ }, [activeIndex, autoHighlightMode, emitHighlight, hasFilteredItemsProp, hasItems, flatFilteredItems, inline, open, store,
1011
+ // Reruns the effect when the query changes without affecting the deps above, such as
1012
+ // clearing the input when no items are filtered out (individually rendered items).
1013
+ inputValue]);
1014
+ useIsoLayoutEffect(() => {
1015
+ if (selectionMode === 'none') {
1016
+ setFilled(String(inputValue) !== '');
1017
+ return;
1018
+ }
1019
+ setFilled(multiple ? Array.isArray(selectedValue) && selectedValue.length > 0 : selectedValue != null);
1020
+ }, [setFilled, selectionMode, inputValue, selectedValue, multiple]);
1021
+
1022
+ // Ensures that the active index is not set to 0 when the list is empty.
1023
+ // This avoids needing to press ArrowDown twice under certain conditions.
1024
+ React.useEffect(() => {
1025
+ if (hasItems && autoHighlightMode && flatFilteredItems.length === 0) {
1026
+ setIndices({
1027
+ activeIndex: null
1028
+ });
1029
+ }
1030
+ }, [hasItems, autoHighlightMode, flatFilteredItems.length, setIndices]);
1031
+ function isSelectedValueDirty(value) {
1032
+ const initialValue = validityData.initialValue;
1033
+ if (Array.isArray(value) && Array.isArray(initialValue)) {
1034
+ return !areArraysEqual(value, initialValue, (itemValue, initialItemValue) => compareItemEquality(itemValue, initialItemValue, isItemEqualToValue));
1035
+ }
1036
+ return value !== initialValue;
1037
+ }
1038
+ useValueChanged(query, () => {
1039
+ if (!open || query === '' || query === String(initialDefaultInputValue)) {
1040
+ return;
1041
+ }
1042
+ setQueryChangedAfterOpen(true);
1043
+ });
1044
+ function syncInputToSelectedLabel() {
1045
+ const nextInputValue = stringifyAsLabel(selectedValue, itemToStringLabel);
1046
+ if (inputValue !== nextInputValue) {
1047
+ setInputValue(nextInputValue, createChangeEventDetails(none));
1048
+ }
1049
+ }
1050
+ useValueChanged(selectedValue, () => {
1051
+ if (selectionMode === 'none') {
1052
+ return;
1053
+ }
1054
+ clearErrors(name);
1055
+ setDirty(isSelectedValueDirty(selectedValue));
1056
+ validation.change(selectedValue);
1057
+ if (single && !hasInputValue && !inputInsidePopup) {
1058
+ syncInputToSelectedLabel();
1059
+ }
1060
+ });
1061
+ useValueChanged(inputValue, () => {
1062
+ if (selectionMode !== 'none') {
1063
+ return;
1064
+ }
1065
+ clearErrors(name);
1066
+ setDirty(inputValue !== validityData.initialValue);
1067
+ validation.change(inputValue);
1068
+ });
1069
+ useValueChanged(items, () => {
1070
+ if (!single || hasInputValue || inputInsidePopup || queryChangedAfterOpen) {
1071
+ return;
1072
+ }
1073
+ syncInputToSelectedLabel();
1074
+ });
1075
+ const floatingRootContext = useFloatingRootContext({
1076
+ open: inline ? true : open,
1077
+ onOpenChange: setOpen,
1078
+ elements: {
1079
+ reference: inputInsidePopup ? triggerElement : inputElement,
1080
+ floating: positionerElement
1081
+ }
1082
+ });
1083
+ const ariaHasPopup = grid ? 'grid' : 'listbox';
1084
+ // An inline list isn't gated on `open`: it renders for as long as it's in the tree, so the
1085
+ // combobox is permanently expanded even while the internal open state is `false`.
1086
+ const expanded = open || inline;
1087
+ const ariaExpanded = expanded ? 'true' : 'false';
1088
+ const role = React.useMemo(() => {
1089
+ const isPlainInput = inputElement?.tagName === 'INPUT';
1090
+ // During SSR and initial hydration, the input ref is not available yet.
1091
+ // Assume an input-like control so combobox ARIA attributes are present.
1092
+ const shouldTreatAsInput = inputElement == null || isPlainInput;
1093
+ // A non-input control only takes on combobox semantics while the list is exposed, which for
1094
+ // an inline list is the whole time.
1095
+ const shouldApplyAria = shouldTreatAsInput || expanded;
1096
+ const reference = shouldTreatAsInput ? {
1097
+ autoComplete: 'off',
1098
+ spellCheck: 'false',
1099
+ autoCorrect: 'off',
1100
+ autoCapitalize: 'none'
1101
+ } : {};
1102
+ if (shouldApplyAria) {
1103
+ reference.role = 'combobox';
1104
+ reference['aria-expanded'] = ariaExpanded;
1105
+ reference['aria-haspopup'] = ariaHasPopup;
1106
+ reference['aria-controls'] = expanded ? listElement?.id : undefined;
1107
+ reference['aria-autocomplete'] = autoComplete;
1108
+ }
1109
+ return {
1110
+ reference,
1111
+ floating: {
1112
+ role: 'presentation'
1113
+ }
1114
+ };
1115
+ }, [inputElement, expanded, ariaExpanded, ariaHasPopup, listElement?.id, autoComplete]);
1116
+ const click = useClick(floatingRootContext, {
1117
+ enabled: !readOnly && !disabled && openOnInputClick,
1118
+ event: 'mousedown-only',
1119
+ toggle: false,
1120
+ // Apply a small delay for touch to let mobile viewport/keyboard positioning settle.
1121
+ // This avoids top-bottom flip flickers if the preferred position is "top" when first tapping.
1122
+ touchOpenDelay: inputInsidePopup ? 0 : 100,
1123
+ reason: inputPress
1124
+ });
1125
+ const dismiss = useDismiss(floatingRootContext, {
1126
+ enabled: !readOnly && !disabled && !inline,
1127
+ outsidePressEvent: {
1128
+ mouse: 'sloppy',
1129
+ // The visual viewport (affected by the mobile software keyboard) can be
1130
+ // somewhat small. The user may want to scroll the screen to see more of
1131
+ // the popup.
1132
+ touch: 'intentional'
1133
+ },
1134
+ // Without a popup, let the Escape key bubble the event up to other popups' handlers.
1135
+ bubbles: inline ? true : undefined,
1136
+ outsidePress(event) {
1137
+ const target = getTarget(event);
1138
+ return !contains(triggerElement, target) && !contains(clearRef.current, target) && !contains(chipsContainerRef.current, target) && !contains(inputGroupElement, target);
1139
+ }
1140
+ });
1141
+ const listNavigation = useListNavigation(floatingRootContext, {
1142
+ enabled: !readOnly && !disabled,
1143
+ id,
1144
+ listRef,
1145
+ activeIndex,
1146
+ selectedIndex,
1147
+ virtual: true,
1148
+ loopFocus,
1149
+ allowEscape: loopFocus && !autoHighlightMode,
1150
+ focusItemOnOpen: queryChangedAfterOpen || selectionMode === 'none' && !autoHighlightMode ? false : 'auto',
1151
+ focusItemOnHover: highlightItemOnHover,
1152
+ resetOnPointerLeave: !keepHighlight,
1153
+ orientation: grid ? 'horizontal' : undefined,
1154
+ rtl: direction === 'rtl',
1155
+ disabledIndices: EMPTY_ARRAY,
1156
+ grid: grid ? gridNavigation : undefined,
1157
+ onNavigate(nextActiveIndex, event) {
1158
+ // Retain the highlight only while actually transitioning out or closed.
1159
+ if (!event && !open || transitionStatus === 'ending') {
1160
+ return;
1161
+ }
1162
+ if (!event) {
1163
+ setIndices({
1164
+ activeIndex: nextActiveIndex
1165
+ });
1166
+ } else {
1167
+ setIndices({
1168
+ activeIndex: nextActiveIndex,
1169
+ type: keyboardActiveRef.current ? keyboard : pointer
1170
+ });
1171
+ }
1172
+ }
1173
+ });
1174
+ const inputProps = React.useMemo(() => mergeProps(listNavigation.reference, {
1175
+ onKeyDown(event) {
1176
+ // In grid mode the navigation hook treats ArrowLeft/ArrowRight as horizontal
1177
+ // grid movement. When the input has focus and no item is highlighted the user
1178
+ // is still editing the query, so let the input keep its native caret behavior.
1179
+ if (grid && store.state.activeIndex == null && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) {
1180
+ event.preventBaseUIHandler();
1181
+ }
1182
+ }
1183
+ }, dismiss.reference, click.reference, role.reference), [listNavigation.reference, dismiss.reference, click.reference, role.reference, grid, store]);
1184
+ const popupProps = React.useMemo(() => mergeProps(FOCUSABLE_POPUP_PROPS, dismiss.floating), [dismiss.floating]);
1185
+ const listProps = React.useMemo(() => mergeProps(listNavigation.floating, role.floating), [listNavigation.floating, role.floating]);
1186
+ const itemProps = React.useMemo(() => {
1187
+ const listNavigationItemProps = listNavigation.item;
1188
+ if (!listNavigationItemProps) {
1189
+ return EMPTY_OBJECT;
1190
+ }
1191
+
1192
+ // Combobox keeps focus on the input; item focus would incorrectly sync
1193
+ // list navigation state from DOM focus.
1194
+ return {
1195
+ ...listNavigationItemProps,
1196
+ onFocus: undefined
1197
+ };
1198
+ }, [listNavigation.item]);
1199
+ useOnFirstRender(() => {
1200
+ store.update({
1201
+ inline: inlineProp,
1202
+ popupProps,
1203
+ listProps,
1204
+ inputProps,
1205
+ triggerProps,
1206
+ itemProps,
1207
+ setOpen,
1208
+ setInputValue,
1209
+ setSelectedValue,
1210
+ setIndices,
1211
+ handleSelection,
1212
+ forceMount,
1213
+ requestSubmit,
1214
+ onOpenChangeComplete
1215
+ });
1216
+ });
1217
+ useIsoLayoutEffect(() => {
1218
+ store.update({
1219
+ id,
1220
+ selectedValue,
1221
+ open,
1222
+ mounted,
1223
+ transitionStatus,
1224
+ items,
1225
+ inline: inlineProp,
1226
+ popupProps,
1227
+ listProps,
1228
+ inputProps,
1229
+ triggerProps,
1230
+ openMethod,
1231
+ itemProps,
1232
+ selectionMode,
1233
+ name,
1234
+ form,
1235
+ disabled,
1236
+ readOnly,
1237
+ required,
1238
+ grid,
1239
+ virtualized,
1240
+ openOnInputClick,
1241
+ itemToStringLabel,
1242
+ modal,
1243
+ autoHighlight: autoHighlightMode,
1244
+ isItemEqualToValue,
1245
+ submitOnItemClick,
1246
+ hasInputValue,
1247
+ inputOwnsFormValue: selectionMode === 'none' && (inlineProp || !store.state.inputInsidePopup)
1248
+ });
1249
+ }, [store, id, selectedValue, open, mounted, transitionStatus, items, popupProps, listProps, inputProps, itemProps, openMethod, triggerProps, selectionMode, name, disabled, readOnly, required, grid, virtualized, openOnInputClick, itemToStringLabel, modal, isItemEqualToValue, submitOnItemClick, hasInputValue, inlineProp, autoHighlightMode, form]);
1250
+ const hiddenInputRef = useMergedRefs(inputRefProp, validation.inputRef);
1251
+ const itemsContextValue = React.useMemo(() => ({
1252
+ query,
1253
+ hasItems,
1254
+ filteredItems,
1255
+ flatFilteredItems
1256
+ }), [query, hasItems, filteredItems, flatFilteredItems]);
1257
+ const serializedValue = React.useMemo(() => {
1258
+ if (Array.isArray(fieldRawValue)) {
1259
+ return '';
1260
+ }
1261
+ return stringifyAsValue(fieldRawValue, itemToStringValue);
1262
+ }, [fieldRawValue, itemToStringValue]);
1263
+ const hasMultipleSelection = multiple && Array.isArray(selectedValue) && selectedValue.length > 0;
1264
+ const hiddenInputName = multiple || selectionMode === 'none' && inputOwnsFormValue ? undefined : name;
1265
+ const hiddenInputs = React.useMemo(() => {
1266
+ if (!multiple || !Array.isArray(selectedValue) || !name) {
1267
+ return null;
1268
+ }
1269
+ return selectedValue.map(value => {
1270
+ const currentSerializedValue = stringifyAsValue(value, itemToStringValue);
1271
+ return /*#__PURE__*/jsx("input", {
1272
+ type: "hidden",
1273
+ form: form,
1274
+ name: name,
1275
+ value: currentSerializedValue,
1276
+ disabled: disabled
1277
+ }, currentSerializedValue);
1278
+ });
1279
+ }, [multiple, selectedValue, form, name, itemToStringValue, disabled]);
1280
+ const children = /*#__PURE__*/jsxs(React.Fragment, {
1281
+ children: [props.children, /*#__PURE__*/jsx("input", {
1282
+ ...validation.getValidationProps(disabled, {
1283
+ // Move focus when the hidden input is focused.
1284
+ onFocus() {
1285
+ if (inputInsidePopup) {
1286
+ triggerElement?.focus();
1287
+ return;
1288
+ }
1289
+ (inputRef.current || triggerElement)?.focus();
1290
+ },
1291
+ // Handle browser autofill.
1292
+ onChange(event) {
1293
+ // Workaround for https://github.com/react/react/issues/9023
1294
+ if (event.nativeEvent.defaultPrevented || disabled || readOnly) {
1295
+ return;
1296
+ }
1297
+ const nextValue = event.currentTarget.value;
1298
+ const nextValueLower = nextValue.toLowerCase();
1299
+ const details = createChangeEventDetails(none, event.nativeEvent);
1300
+ const findSerializedMatchIndex = () => valuesRef.current.findIndex(candidate => stringifyAsValue(candidate, itemToStringValue).toLowerCase() === nextValueLower || stringifyAsLabel(candidate, itemToStringLabel).toLowerCase() === nextValueLower);
1301
+ function handleChange() {
1302
+ // Browser autofill only writes a single scalar value.
1303
+ if (multiple) {
1304
+ return;
1305
+ }
1306
+ if (selectionMode === 'none') {
1307
+ setInputValue(nextValue, details);
1308
+ return;
1309
+ }
1310
+
1311
+ // Preserve the original serialized matching, then fall back to rendered text,
1312
+ // which browsers can autofill for primitive values like `value="US">United States`.
1313
+ let matchingIndex = findSerializedMatchIndex();
1314
+ if (matchingIndex === -1) {
1315
+ matchingIndex = valuesRef.current.findIndex((_, index) => {
1316
+ const renderedLabel = labelsRef.current[index];
1317
+ return renderedLabel != null && renderedLabel.toLowerCase() === nextValueLower;
1318
+ });
1319
+ }
1320
+ const matchingValue = matchingIndex === -1 ? undefined : valuesRef.current[matchingIndex];
1321
+ if (matchingValue != null) {
1322
+ // `setSelectedValue` may be canceled by `onValueChange`; rely on
1323
+ // `useValueChanged` to mark the field dirty and run validation only
1324
+ // when the value actually changes.
1325
+ setSelectedValue?.(matchingValue, details);
1326
+ }
1327
+ }
1328
+
1329
+ // Only single-selection autofill matches against the registered values/labels.
1330
+ // `multiple` ignores autofill and `none` just writes the input value, so avoid the
1331
+ // sticky `forceMounted` mount (which never resets) for those modes.
1332
+ if (single) {
1333
+ forceMount();
1334
+ if (items && findSerializedMatchIndex() === -1) {
1335
+ // `forceMount` only refreshes the derived labels for the `items` prop. When
1336
+ // serialized matching misses, also mount the list so rendered labels (which can
1337
+ // differ from the serialized values) are registered for autofill matching.
1338
+ store.set('forceMounted', true);
1339
+ }
1340
+ }
1341
+ queueMicrotask(handleChange);
1342
+ }
1343
+ }),
1344
+ id: id && hiddenInputName == null ? `${id}-hidden-input` : undefined,
1345
+ form: form,
1346
+ name: hiddenInputName,
1347
+ autoComplete: formAutoComplete,
1348
+ disabled: disabled,
1349
+ required: required && !hasMultipleSelection,
1350
+ readOnly: readOnly,
1351
+ value: serializedValue,
1352
+ ref: hiddenInputRef,
1353
+ style: hiddenInputName ? visuallyHiddenInput : visuallyHidden,
1354
+ tabIndex: -1,
1355
+ "aria-hidden": true,
1356
+ suppressHydrationWarning: true
1357
+ }), hiddenInputs]
1358
+ });
1359
+ return /*#__PURE__*/jsx(ComboboxRootContext.Provider, {
1360
+ value: store,
1361
+ children: /*#__PURE__*/jsx(ComboboxFloatingContext.Provider, {
1362
+ value: floatingRootContext,
1363
+ children: /*#__PURE__*/jsx(ComboboxHasItemsContext.Provider, {
1364
+ value: hasItems,
1365
+ children: /*#__PURE__*/jsx(ComboboxDerivedItemsContext.Provider, {
1366
+ value: itemsContextValue,
1367
+ children: /*#__PURE__*/jsx(ComboboxInputValueContext.Provider, {
1368
+ value: inputValue,
1369
+ children: children
1370
+ })
1371
+ })
1372
+ })
1373
+ })
1374
+ });
1375
+ }
1376
+
1377
+ const triggerStateAttributesMapping = {
1378
+ ...pressableTriggerOpenStateMapping,
1379
+ ...fieldValidityMapping,
1380
+ popupSide: side => side ? {
1381
+ 'data-popup-side': side
1382
+ } : null,
1383
+ listEmpty: empty => empty ? {
1384
+ 'data-list-empty': ''
1385
+ } : null
1386
+ };
1387
+
1388
+ /**
1389
+ * The popup side is only meaningful while the positioner is mounted, as the store retains the
1390
+ * last resolved side after the popup unmounts.
1391
+ */
1392
+ function usePopupSide(store) {
1393
+ const mounted = useStore(store, selectors.mounted);
1394
+ const popupSide = useStore(store, selectors.popupSide);
1395
+ const positionerElement = useStore(store, selectors.positionerElement);
1396
+ return mounted && positionerElement ? popupSide : null;
1397
+ }
1398
+
1399
+ /**
1400
+ * Whether the filtered list has no items to show.
1401
+ */
1402
+ function useListEmpty() {
1403
+ return useComboboxDerivedItemsContext().filteredItems.length === 0;
1404
+ }
1405
+
1406
+ /**
1407
+ * The arrow keys that move the chip highlight backwards and forwards, in that order.
1408
+ */
1409
+ function getChipNavigationKeys(direction) {
1410
+ return direction === 'rtl' ? ['ArrowRight', 'ArrowLeft'] : ['ArrowLeft', 'ArrowRight'];
1411
+ }
1412
+
1413
+ /**
1414
+ * Where the highlight lands once the chip at `index` is removed, or `undefined` for no highlight.
1415
+ */
1416
+ function getIndexAfterChipRemoval(index, chipCount) {
1417
+ const nextIndex = index >= chipCount - 1 ? chipCount - 2 : index;
1418
+ return nextIndex >= 0 ? nextIndex : undefined;
1419
+ }
1420
+
1421
+ /**
1422
+ * Commits the highlighted item by clicking it, tagging the originating event so the item's
1423
+ * handler can attribute the selection to it.
1424
+ */
1425
+ function clickHighlightedItem(store, activeIndex, nativeEvent) {
1426
+ const listItem = store.state.listRef.current[activeIndex];
1427
+ if (listItem) {
1428
+ store.state.selectionEventRef.current = nativeEvent;
1429
+ listItem.click();
1430
+ store.state.selectionEventRef.current = null;
1431
+ }
1432
+ }
1433
+
1434
+ /**
1435
+ * A button that opens the popup.
1436
+ * Renders a `<button>` element.
1437
+ *
1438
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
1439
+ */
1440
+ const ComboboxTrigger = /*#__PURE__*/React.forwardRef(function ComboboxTrigger(componentProps, forwardedRef) {
1441
+ const {
1442
+ render,
1443
+ className,
1444
+ nativeButton = true,
1445
+ disabled: disabledProp = false,
1446
+ id: idProp,
1447
+ style,
1448
+ ...elementProps
1449
+ } = componentProps;
1450
+ const {
1451
+ state: fieldState,
1452
+ disabled: fieldDisabled,
1453
+ setTouched,
1454
+ setFocused,
1455
+ validationMode,
1456
+ validation
1457
+ } = useFieldRootContext();
1458
+ const {
1459
+ labelId: fieldLabelId
1460
+ } = useLabelableContext();
1461
+ const store = useComboboxRootContext();
1462
+ const selectionMode = useStore(store, selectors.selectionMode);
1463
+ const comboboxDisabled = useStore(store, selectors.disabled);
1464
+ const readOnly = useStore(store, selectors.readOnly);
1465
+ const required = useStore(store, selectors.required);
1466
+ const positionerElement = useStore(store, selectors.positionerElement);
1467
+ const listElement = useStore(store, selectors.listElement);
1468
+ const storedPopupId = useStore(store, selectors.popupId);
1469
+ const triggerProps = useStore(store, selectors.triggerProps);
1470
+ const inputInsidePopup = useStore(store, selectors.inputInsidePopup);
1471
+ const rootId = useStore(store, selectors.id);
1472
+ const comboboxLabelId = useStore(store, selectors.labelId);
1473
+ const open = useStore(store, selectors.open);
1474
+ const selectedValue = useStore(store, selectors.selectedValue);
1475
+ const activeIndex = useStore(store, selectors.activeIndex);
1476
+ const selectedIndex = useStore(store, selectors.selectedIndex);
1477
+ const hasSelectedValue = useStore(store, selectors.hasSelectedValue);
1478
+ const floatingRootContext = useComboboxFloatingContext();
1479
+ const inputValue = useComboboxInputValueContext();
1480
+ const focusTimeout = useTimeout();
1481
+ const disabled = fieldDisabled || comboboxDisabled || disabledProp;
1482
+ const listEmpty = useListEmpty();
1483
+ const popupSide = usePopupSide(store);
1484
+ useLabelableId({
1485
+ id: inputInsidePopup ? idProp : undefined
1486
+ });
1487
+ const id = inputInsidePopup ? idProp ?? rootId : idProp;
1488
+ const ariaLabelledBy = resolveAriaLabelledBy(fieldLabelId, comboboxLabelId);
1489
+ let ariaControls;
1490
+ if (open && inputInsidePopup) {
1491
+ // Fall back to the default id while the popup registers its own (custom ids are stored once the
1492
+ // popup mounts), so `aria-controls` is set on the same commit `open` becomes `true`.
1493
+ ariaControls = storedPopupId ?? getComboboxPopupId(rootId);
1494
+ } else if (open) {
1495
+ ariaControls = listElement?.id;
1496
+ }
1497
+ const currentPointerTypeRef = React.useRef('');
1498
+ function trackPointerType(event) {
1499
+ currentPointerTypeRef.current = event.pointerType;
1500
+ }
1501
+ const {
1502
+ reference: triggerTypeaheadProps
1503
+ } = useTypeahead(floatingRootContext, {
1504
+ enabled: !open && !readOnly && !comboboxDisabled && selectionMode === 'single',
1505
+ listRef: store.state.labelsRef,
1506
+ activeIndex,
1507
+ selectedIndex,
1508
+ onMatch(index) {
1509
+ const nextSelectedValue = store.state.valuesRef.current[index];
1510
+ if (nextSelectedValue !== undefined) {
1511
+ store.state.setSelectedValue(nextSelectedValue, createChangeEventDetails(none));
1512
+ }
1513
+ }
1514
+ });
1515
+ const {
1516
+ reference: triggerClickProps
1517
+ } = useClick(floatingRootContext, {
1518
+ enabled: !readOnly && !comboboxDisabled,
1519
+ event: 'mousedown'
1520
+ });
1521
+ const {
1522
+ buttonRef,
1523
+ getButtonProps
1524
+ } = useButton({
1525
+ native: nativeButton,
1526
+ disabled
1527
+ });
1528
+ const state = {
1529
+ ...fieldState,
1530
+ open,
1531
+ disabled,
1532
+ popupSide,
1533
+ listEmpty,
1534
+ placeholder: selectionMode === 'none' ? false : !hasSelectedValue
1535
+ };
1536
+ const setTriggerElement = useStableCallback(element => {
1537
+ store.set('triggerElement', element);
1538
+ });
1539
+ const element = useRenderElement('button', componentProps, {
1540
+ ref: [forwardedRef, buttonRef, setTriggerElement],
1541
+ state,
1542
+ props: [triggerProps, triggerClickProps, triggerTypeaheadProps, {
1543
+ id,
1544
+ tabIndex: inputInsidePopup ? 0 : -1,
1545
+ role: inputInsidePopup ? 'combobox' : undefined,
1546
+ 'aria-expanded': open,
1547
+ 'aria-haspopup': inputInsidePopup ? 'dialog' : 'listbox',
1548
+ 'aria-controls': ariaControls,
1549
+ 'aria-required': inputInsidePopup ? required || undefined : undefined,
1550
+ 'aria-labelledby': ariaLabelledBy,
1551
+ onPointerDown: trackPointerType,
1552
+ onPointerEnter: trackPointerType,
1553
+ onFocus() {
1554
+ setFocused(true);
1555
+ if (disabled || readOnly) {
1556
+ return;
1557
+ }
1558
+ focusTimeout.start(0, store.state.forceMount);
1559
+ },
1560
+ onBlur(event) {
1561
+ // If focus is moving into the popup, don't count it as a blur.
1562
+ if (contains(positionerElement, event.relatedTarget)) {
1563
+ return;
1564
+ }
1565
+ setTouched(true);
1566
+ setFocused(false);
1567
+ if (validationMode === 'onBlur') {
1568
+ const valueToValidate = selectionMode === 'none' ? inputValue : selectedValue;
1569
+ validation.commit(valueToValidate);
1570
+ }
1571
+ },
1572
+ onMouseDown(event) {
1573
+ if (disabled || readOnly) {
1574
+ return;
1575
+ }
1576
+ if (!inputInsidePopup) {
1577
+ floatingRootContext.set('domReferenceElement', event.currentTarget);
1578
+ }
1579
+
1580
+ // Ensure items are registered for initial selection highlight.
1581
+ store.state.forceMount();
1582
+ if (currentPointerTypeRef.current !== 'touch') {
1583
+ store.state.inputRef.current?.focus();
1584
+ if (!inputInsidePopup) {
1585
+ event.preventDefault();
1586
+ }
1587
+ }
1588
+ if (open) {
1589
+ return;
1590
+ }
1591
+ const doc = ownerDocument(event.currentTarget);
1592
+ function handleMouseUp(mouseEvent) {
1593
+ const currentTriggerElement = store.state.triggerElement;
1594
+ if (!currentTriggerElement) {
1595
+ return;
1596
+ }
1597
+ const mouseUpTarget = getTarget(mouseEvent);
1598
+ const positioner = store.state.positionerElement;
1599
+ const list = store.state.listElement;
1600
+ if (contains(currentTriggerElement, mouseUpTarget) || contains(positioner, mouseUpTarget) || contains(list, mouseUpTarget)) {
1601
+ return;
1602
+ }
1603
+ if (isMouseWithinBounds(mouseEvent, currentTriggerElement)) {
1604
+ return;
1605
+ }
1606
+ store.state.setOpen(false, createChangeEventDetails(cancelOpen, mouseEvent));
1607
+ }
1608
+ if (inputInsidePopup) {
1609
+ doc.addEventListener('mouseup', handleMouseUp, {
1610
+ once: true
1611
+ });
1612
+ }
1613
+ },
1614
+ onKeyDown(event) {
1615
+ if (readOnly) {
1616
+ return;
1617
+ }
1618
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
1619
+ stopEvent(event);
1620
+ store.state.setOpen(true, createChangeEventDetails(listNavigation, event.nativeEvent));
1621
+ store.state.inputRef.current?.focus();
1622
+ }
1623
+ }
1624
+ }, validation.getValidationProps(disabled, elementProps), getButtonProps],
1625
+ stateAttributesMapping: triggerStateAttributesMapping
1626
+ });
1627
+ return element;
1628
+ });
1629
+ if (process.env.NODE_ENV !== "production") ComboboxTrigger.displayName = "ComboboxTrigger";
1630
+
1631
+ const ComboboxChipsContext = /*#__PURE__*/React.createContext(undefined);
1632
+ if (process.env.NODE_ENV !== "production") ComboboxChipsContext.displayName = "ComboboxChipsContext";
1633
+ function useComboboxChipsContext() {
1634
+ return React.useContext(ComboboxChipsContext);
1635
+ }
1636
+
1637
+ const ComboboxPositionerContext = /*#__PURE__*/React.createContext(undefined);
1638
+ if (process.env.NODE_ENV !== "production") ComboboxPositionerContext.displayName = "ComboboxPositionerContext";
1639
+ function useComboboxPositionerContext(optional) {
1640
+ const context = React.useContext(ComboboxPositionerContext);
1641
+ if (context === undefined && !optional) {
1642
+ throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: <Combobox.Popup> and <Combobox.Arrow> must be used within the <Combobox.Positioner> component' : formatErrorMessage(21));
1643
+ }
1644
+ return context;
1645
+ }
1646
+
1647
+ /**
1648
+ * @internal
1649
+ */
1650
+ const ComboboxInternalDismissButton = /*#__PURE__*/React.forwardRef(function ComboboxInternalDismissButton(_, forwardedRef) {
1651
+ const store = useComboboxRootContext();
1652
+ const {
1653
+ buttonRef,
1654
+ getButtonProps
1655
+ } = useButton({
1656
+ native: false
1657
+ });
1658
+ const mergedRef = useMergedRefs(forwardedRef, buttonRef);
1659
+ function handleDismiss(event) {
1660
+ store.state.setOpen(false, createChangeEventDetails(closePress, event.nativeEvent, event.currentTarget));
1661
+ }
1662
+ const dismissProps = getButtonProps({
1663
+ onClick: handleDismiss
1664
+ });
1665
+ return /*#__PURE__*/jsx("span", {
1666
+ ref: mergedRef,
1667
+ ...dismissProps,
1668
+ "aria-label": "Dismiss",
1669
+ tabIndex: undefined,
1670
+ style: visuallyHiddenInput
1671
+ });
1672
+ });
1673
+ if (process.env.NODE_ENV !== "production") ComboboxInternalDismissButton.displayName = "ComboboxInternalDismissButton";
1674
+
1675
+ const ComboboxInput = /*#__PURE__*/React.forwardRef(function ComboboxInput(componentProps, forwardedRef) {
1676
+ const {
1677
+ render,
1678
+ className,
1679
+ disabled: disabledProp = false,
1680
+ id: idProp,
1681
+ style,
1682
+ ...elementProps
1683
+ } = componentProps;
1684
+ const {
1685
+ state: fieldState,
1686
+ disabled: fieldDisabled,
1687
+ setTouched,
1688
+ setFocused,
1689
+ validationMode,
1690
+ validation
1691
+ } = useFieldRootContext();
1692
+ const {
1693
+ labelId: fieldLabelId
1694
+ } = useLabelableContext();
1695
+ const comboboxChipsContext = useComboboxChipsContext();
1696
+ const positioning = useComboboxPositionerContext(true);
1697
+ const hasPositionerParent = Boolean(positioning);
1698
+ const store = useComboboxRootContext();
1699
+ // `inputValue` can't be placed in the store.
1700
+ // https://github.com/mui/base-ui/issues/2703
1701
+ const inputValue = useComboboxInputValueContext();
1702
+ const direction = useDirection();
1703
+ const required = useStore(store, selectors.required);
1704
+ const comboboxDisabled = useStore(store, selectors.disabled);
1705
+ const readOnly = useStore(store, selectors.readOnly);
1706
+ const name = useStore(store, selectors.name);
1707
+ const form = useStore(store, selectors.form);
1708
+ const selectionMode = useStore(store, selectors.selectionMode);
1709
+ const autoHighlightMode = useStore(store, selectors.autoHighlight);
1710
+ const inputProps = useStore(store, selectors.inputProps);
1711
+ const triggerProps = useStore(store, selectors.triggerProps);
1712
+ const open = useStore(store, selectors.open);
1713
+ const mounted = useStore(store, selectors.mounted);
1714
+ const selectedValue = useStore(store, selectors.selectedValue);
1715
+ const rootId = useStore(store, selectors.id);
1716
+ const inline = useStore(store, selectors.inline);
1717
+ const modal = useStore(store, selectors.modal);
1718
+ const autoHighlightEnabled = Boolean(autoHighlightMode);
1719
+ const popupSide = usePopupSide(store);
1720
+ const disabled = fieldDisabled || comboboxDisabled || disabledProp;
1721
+ const listEmpty = useListEmpty();
1722
+ const isInsidePopup = hasPositionerParent || inline;
1723
+ const focusManagerModal = !isInsidePopup || modal;
1724
+ const id = useBaseUiId(idProp ?? (!isInsidePopup ? rootId : undefined));
1725
+ const fieldStateForInput = hasPositionerParent ? DEFAULT_FIELD_STATE_ATTRIBUTES : fieldState;
1726
+ const [composingValue, setComposingValue] = React.useState(null);
1727
+ const isComposingRef = React.useRef(false);
1728
+ const lastActiveIndexRef = React.useRef(null);
1729
+ const shouldRestoreActiveIndexRef = React.useRef(false);
1730
+ const inputOwnsFormValue = selectionMode === 'none' && !hasPositionerParent;
1731
+ const setInputElement = useStableCallback(element => {
1732
+ const nextIsInsidePopup = hasPositionerParent || store.state.inline;
1733
+ if (nextIsInsidePopup && !store.state.hasInputValue) {
1734
+ store.state.setInputValue('', createChangeEventDetails(none));
1735
+ }
1736
+ store.update({
1737
+ inputElement: element,
1738
+ inputInsidePopup: nextIsInsidePopup,
1739
+ inputOwnsFormValue
1740
+ });
1741
+ });
1742
+ const validationProps = hasPositionerParent ? elementProps : validation.getValidationProps(disabled, elementProps);
1743
+ function clearHighlight() {
1744
+ store.state.setIndices({
1745
+ activeIndex: null,
1746
+ selectedIndex: null,
1747
+ type: store.state.keyboardActiveRef.current ? keyboard : pointer
1748
+ });
1749
+ }
1750
+ function markPointerActive() {
1751
+ store.state.keyboardActiveRef.current = false;
1752
+ }
1753
+ const state = {
1754
+ ...fieldStateForInput,
1755
+ open,
1756
+ disabled,
1757
+ readOnly,
1758
+ popupSide,
1759
+ listEmpty
1760
+ };
1761
+ function handleKeyDown(event) {
1762
+ if (!comboboxChipsContext) {
1763
+ return undefined;
1764
+ }
1765
+ let nextIndex;
1766
+ const {
1767
+ highlightedChipIndex
1768
+ } = comboboxChipsContext;
1769
+ const renderedChipsCount = comboboxChipsContext.chipsRef.current.length;
1770
+ const [previousChipKey, nextChipKey] = getChipNavigationKeys(direction);
1771
+ if (highlightedChipIndex !== undefined) {
1772
+ if (event.key === previousChipKey) {
1773
+ event.preventDefault();
1774
+ if (highlightedChipIndex > 0) {
1775
+ nextIndex = highlightedChipIndex - 1;
1776
+ } else {
1777
+ nextIndex = undefined;
1778
+ }
1779
+ } else if (event.key === nextChipKey) {
1780
+ event.preventDefault();
1781
+ if (highlightedChipIndex < renderedChipsCount - 1) {
1782
+ nextIndex = highlightedChipIndex + 1;
1783
+ } else {
1784
+ nextIndex = undefined;
1785
+ }
1786
+ } else if (event.key === 'Backspace' || event.key === 'Delete') {
1787
+ event.preventDefault();
1788
+ // Move highlight appropriately after removal.
1789
+ nextIndex = getIndexAfterChipRemoval(highlightedChipIndex, selectedValue.length);
1790
+ clearHighlight();
1791
+ }
1792
+ return nextIndex;
1793
+ }
1794
+
1795
+ // Handle navigation when no chip is highlighted
1796
+ if (event.key === previousChipKey && (event.currentTarget.selectionStart ?? 0) === 0 && selectedValue.length > 0) {
1797
+ event.preventDefault();
1798
+ nextIndex = renderedChipsCount > 0 ? renderedChipsCount - 1 : undefined;
1799
+ }
1800
+ return nextIndex;
1801
+ }
1802
+ const element = useRenderElement('input', componentProps, {
1803
+ state,
1804
+ ref: [forwardedRef, store.state.inputRef, setInputElement],
1805
+ props: [inputProps, triggerProps, {
1806
+ value: composingValue ?? inputValue,
1807
+ 'aria-readonly': readOnly || undefined,
1808
+ 'aria-required': required || undefined,
1809
+ 'aria-labelledby': fieldLabelId,
1810
+ disabled,
1811
+ readOnly,
1812
+ required: selectionMode === 'none' ? required : undefined,
1813
+ form,
1814
+ ...(inputOwnsFormValue && name && {
1815
+ name
1816
+ }),
1817
+ id,
1818
+ onFocus() {
1819
+ setFocused(true);
1820
+ if (!inline || !shouldRestoreActiveIndexRef.current) {
1821
+ return;
1822
+ }
1823
+ shouldRestoreActiveIndexRef.current = false;
1824
+ const nextActiveIndex = lastActiveIndexRef.current;
1825
+ if (nextActiveIndex == null ||
1826
+ // `valuesRef` can be sparse, so guard against restoring a removed slot.
1827
+ !Object.hasOwn(store.state.valuesRef.current, nextActiveIndex)) {
1828
+ return;
1829
+ }
1830
+ store.state.setIndices({
1831
+ activeIndex: nextActiveIndex
1832
+ });
1833
+ },
1834
+ onBlur() {
1835
+ setTouched(true);
1836
+ setFocused(false);
1837
+ const activeIndex = store.state.activeIndex;
1838
+ if (inline && activeIndex !== null && autoHighlightMode !== 'always') {
1839
+ lastActiveIndexRef.current = activeIndex;
1840
+ shouldRestoreActiveIndexRef.current = true;
1841
+ store.state.setIndices({
1842
+ activeIndex: null
1843
+ });
1844
+ }
1845
+ if (validationMode === 'onBlur') {
1846
+ const valueToValidate = selectionMode === 'none' ? inputValue : selectedValue;
1847
+ validation.commit(valueToValidate);
1848
+ }
1849
+ },
1850
+ onCompositionStart(event) {
1851
+ if (android) {
1852
+ return;
1853
+ }
1854
+ isComposingRef.current = true;
1855
+ setComposingValue(event.currentTarget.value);
1856
+ },
1857
+ onCompositionEnd(event) {
1858
+ isComposingRef.current = false;
1859
+ const next = event.currentTarget.value;
1860
+ setComposingValue(null);
1861
+ store.state.setInputValue(next, createChangeEventDetails(inputChange, event.nativeEvent));
1862
+ },
1863
+ onChange(event) {
1864
+ const nativeEvent = event.nativeEvent;
1865
+ // Autofill may not provide `inputType` (Chrome) or may report
1866
+ // `insertReplacementText` (Firefox).
1867
+ const inputType = nativeEvent.inputType;
1868
+ const autofillLikeInput = !inputType || inputType === 'insertReplacementText';
1869
+ // During composition the input is always considered typed into.
1870
+ const shouldOpenOnInput = isComposingRef.current || !autofillLikeInput;
1871
+ function maybeOpenOnInput(trimmed) {
1872
+ if (readOnly || disabled || !trimmed || !shouldOpenOnInput) {
1873
+ return;
1874
+ }
1875
+ store.state.setOpen(true, createChangeEventDetails(inputChange, nativeEvent));
1876
+ // When autoHighlight is enabled, keep the highlight (will be set to 0 in root).
1877
+ if (!autoHighlightEnabled) {
1878
+ clearHighlight();
1879
+ }
1880
+ }
1881
+
1882
+ // During IME composition, avoid propagating controlled updates to prevent
1883
+ // filtering the options prematurely so `Empty` won't show incorrectly.
1884
+ // We can't rely on this check for Android due to how it handles composition
1885
+ // events with some keyboards (e.g. Samsung keyboard with predictive text on
1886
+ // treats all text as always-composing).
1887
+ // https://github.com/mui/base-ui/issues/2942
1888
+ if (isComposingRef.current) {
1889
+ const nextVal = event.currentTarget.value;
1890
+ setComposingValue(nextVal);
1891
+ if (nextVal === '' && !store.state.openOnInputClick && !store.state.inputInsidePopup) {
1892
+ store.state.setOpen(false, createChangeEventDetails(inputClear, nativeEvent));
1893
+ }
1894
+ const trimmed = nextVal.trim();
1895
+ const shouldMaintainHighlight = autoHighlightEnabled && trimmed !== '';
1896
+ maybeOpenOnInput(trimmed);
1897
+ if (open && store.state.activeIndex !== null && !shouldMaintainHighlight) {
1898
+ clearHighlight();
1899
+ }
1900
+ return;
1901
+ }
1902
+ const inputChangeDetails = createChangeEventDetails(inputChange, nativeEvent);
1903
+ store.state.setInputValue(event.currentTarget.value, inputChangeDetails);
1904
+ if (inputChangeDetails.isCanceled) {
1905
+ return;
1906
+ }
1907
+ const empty = event.currentTarget.value === '';
1908
+ const clearDetails = createChangeEventDetails(inputClear, nativeEvent);
1909
+ if (empty && !store.state.inputInsidePopup) {
1910
+ if (selectionMode === 'single') {
1911
+ store.state.setSelectedValue(null, clearDetails);
1912
+ }
1913
+ if (!store.state.openOnInputClick) {
1914
+ store.state.setOpen(false, clearDetails);
1915
+ }
1916
+ }
1917
+ maybeOpenOnInput(event.currentTarget.value.trim());
1918
+
1919
+ // When the user types, ensure the list resets its highlight so that
1920
+ // virtual focus returns to the input (aria-activedescendant is
1921
+ // cleared).
1922
+ if (open && store.state.activeIndex !== null && !autoHighlightEnabled) {
1923
+ clearHighlight();
1924
+ }
1925
+ },
1926
+ onKeyDown(event) {
1927
+ if (disabled || readOnly) {
1928
+ return;
1929
+ }
1930
+ if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) {
1931
+ return;
1932
+ }
1933
+ store.state.keyboardActiveRef.current = true;
1934
+ const input = event.currentTarget;
1935
+ const scrollAmount = input.scrollWidth - input.clientWidth;
1936
+ const isRTL = direction === 'rtl';
1937
+ if (event.key === 'Home') {
1938
+ stopEvent(event);
1939
+ const cursor = gecko && isRTL ? input.value.length : 0;
1940
+ input.setSelectionRange(cursor, cursor);
1941
+ input.scrollLeft = 0;
1942
+ return;
1943
+ }
1944
+ if (event.key === 'End') {
1945
+ stopEvent(event);
1946
+ const cursor = gecko && isRTL ? 0 : input.value.length;
1947
+ input.setSelectionRange(cursor, cursor);
1948
+ input.scrollLeft = isRTL ? -scrollAmount : scrollAmount;
1949
+ return;
1950
+ }
1951
+ if (!mounted && event.key === 'Escape') {
1952
+ const isClear = selectionMode === 'multiple' && Array.isArray(selectedValue) ? selectedValue.length === 0 : selectedValue === null;
1953
+ const details = createChangeEventDetails(escapeKey, event.nativeEvent);
1954
+ const value = selectionMode === 'multiple' ? [] : null;
1955
+ store.state.setInputValue('', details);
1956
+ store.state.setSelectedValue(value, details);
1957
+ if (!isClear && !store.state.inline && !details.isPropagationAllowed) {
1958
+ event.stopPropagation();
1959
+ }
1960
+ return;
1961
+ }
1962
+
1963
+ // Handle deletion when no chip is highlighted and the input is empty.
1964
+ if (comboboxChipsContext && event.key === 'Backspace' && input.value === '' && comboboxChipsContext.highlightedChipIndex === undefined && Array.isArray(selectedValue) && selectedValue.length > 0) {
1965
+ const renderedChipsCount = comboboxChipsContext.chipsRef.current.length;
1966
+ const removalIndex = renderedChipsCount > 0 ? renderedChipsCount - 1 : selectedValue.length - 1;
1967
+ const newValue = selectedValue.filter((_, index) => index !== removalIndex);
1968
+ // If the removed item was also the active (highlighted) item, clear highlight
1969
+ clearHighlight();
1970
+ store.state.setSelectedValue(newValue, createChangeEventDetails(none, event.nativeEvent));
1971
+ return;
1972
+ }
1973
+ const hadHighlightedChip = comboboxChipsContext?.highlightedChipIndex !== undefined;
1974
+ const nextIndex = handleKeyDown(event);
1975
+ comboboxChipsContext?.setHighlightedChipIndex(nextIndex);
1976
+ if (nextIndex !== undefined) {
1977
+ comboboxChipsContext?.chipsRef.current[nextIndex]?.focus();
1978
+ } else if (hadHighlightedChip) {
1979
+ store.state.inputRef.current?.focus();
1980
+ }
1981
+
1982
+ // event.isComposing
1983
+ if (event.which === 229) {
1984
+ return;
1985
+ }
1986
+ if (event.key === 'Enter' && open) {
1987
+ const activeIndex = store.state.activeIndex;
1988
+ const nativeEvent = event.nativeEvent;
1989
+ if (activeIndex === null) {
1990
+ if (inline) {
1991
+ return;
1992
+ }
1993
+
1994
+ // Allow form submission when no item is highlighted.
1995
+ store.state.setOpen(false, createChangeEventDetails(none, nativeEvent));
1996
+ return;
1997
+ }
1998
+ stopEvent(event);
1999
+ clickHighlightedItem(store, activeIndex, nativeEvent);
2000
+ }
2001
+ },
2002
+ onPointerMove: markPointerActive,
2003
+ onPointerDown: markPointerActive
2004
+ }, validationProps],
2005
+ stateAttributesMapping: triggerStateAttributesMapping
2006
+ });
2007
+ const renderedInput = hasPositionerParent ? /*#__PURE__*/jsx(FieldRootContext.Provider, {
2008
+ value: DEFAULT_FIELD_ROOT_CONTEXT,
2009
+ children: element
2010
+ }) : element;
2011
+ return /*#__PURE__*/jsxs(React.Fragment, {
2012
+ children: [open && focusManagerModal && /*#__PURE__*/jsx(ComboboxInternalDismissButton, {
2013
+ ref: store.state.startDismissRef
2014
+ }), renderedInput]
2015
+ });
2016
+ });
2017
+ if (process.env.NODE_ENV !== "production") ComboboxInput.displayName = "ComboboxInput";
2018
+
2019
+ function handleInputPress(event, store, disabled, readOnly, shouldIgnoreTarget) {
2020
+ if (event.baseUIHandlerPrevented || readOnly) {
2021
+ return;
2022
+ }
2023
+ const target = getTarget(event.nativeEvent);
2024
+ const targetElement = isElement(target) ? target : null;
2025
+ if (targetElement !== event.currentTarget && (shouldIgnoreTarget?.(targetElement) || isInteractiveElement(targetElement))) {
2026
+ return;
2027
+ }
2028
+ event.preventDefault();
2029
+ if (disabled) {
2030
+ return;
2031
+ }
2032
+ store.state.inputRef.current?.focus();
2033
+ if (store.state.openOnInputClick) {
2034
+ store.state.setOpen(true, createChangeEventDetails(inputPress, event.nativeEvent));
2035
+ }
2036
+ }
2037
+
2038
+ /**
2039
+ * A wrapper for the input and its associated controls.
2040
+ * Renders a `<div>` element.
2041
+ *
2042
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
2043
+ */
2044
+ const ComboboxInputGroup = /*#__PURE__*/React.forwardRef(function ComboboxInputGroup(componentProps, forwardedRef) {
2045
+ const {
2046
+ render,
2047
+ className,
2048
+ style,
2049
+ ...elementProps
2050
+ } = componentProps;
2051
+ const {
2052
+ state: fieldState
2053
+ } = useFieldRootContext();
2054
+ const store = useComboboxRootContext();
2055
+ const open = useStore(store, selectors.open);
2056
+ const comboboxDisabled = useStore(store, selectors.disabled);
2057
+ const readOnly = useStore(store, selectors.readOnly);
2058
+ const hasSelectedValue = useStore(store, selectors.hasSelectedValue);
2059
+ const selectionMode = useStore(store, selectors.selectionMode);
2060
+ const popupSide = usePopupSide(store);
2061
+ const disabled = comboboxDisabled;
2062
+ const listEmpty = useListEmpty();
2063
+ const placeholder = selectionMode === 'none' ? false : !hasSelectedValue;
2064
+ const state = {
2065
+ ...fieldState,
2066
+ open,
2067
+ disabled,
2068
+ readOnly,
2069
+ popupSide,
2070
+ listEmpty,
2071
+ placeholder
2072
+ };
2073
+ const setInputGroupElement = useStableCallback(element => {
2074
+ store.set('inputGroupElement', element);
2075
+ });
2076
+ return useRenderElement('div', componentProps, {
2077
+ ref: [forwardedRef, setInputGroupElement],
2078
+ props: [{
2079
+ role: 'group',
2080
+ onMouseDown(event) {
2081
+ handleInputPress(event, store, disabled, readOnly, target => {
2082
+ return contains(store.state.chipsContainerRef.current, target);
2083
+ });
2084
+ }
2085
+ }, elementProps],
2086
+ state,
2087
+ stateAttributesMapping: triggerStateAttributesMapping
2088
+ });
2089
+ });
2090
+ if (process.env.NODE_ENV !== "production") ComboboxInputGroup.displayName = "ComboboxInputGroup";
2091
+
2092
+ /**
2093
+ * An icon that indicates that the trigger button opens the popup.
2094
+ * Renders a `<span>` element.
2095
+ *
2096
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
2097
+ */
2098
+ const ComboboxIcon = /*#__PURE__*/React.forwardRef(function ComboboxIcon(componentProps, forwardedRef) {
2099
+ const {
2100
+ render,
2101
+ className,
2102
+ style,
2103
+ ...elementProps
2104
+ } = componentProps;
2105
+ const element = useRenderElement('span', componentProps, {
2106
+ ref: forwardedRef,
2107
+ props: [{
2108
+ 'aria-hidden': true,
2109
+ children: '▼'
2110
+ }, elementProps]
2111
+ });
2112
+ return element;
2113
+ });
2114
+ if (process.env.NODE_ENV !== "production") ComboboxIcon.displayName = "ComboboxIcon";
2115
+
2116
+ const stateAttributesMapping$2 = {
2117
+ ...transitionStatusMapping,
2118
+ ...triggerOpenStateMapping
2119
+ };
2120
+
2121
+ /**
2122
+ * Clears the value when clicked.
2123
+ * Renders a `<button>` element.
2124
+ *
2125
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
2126
+ */
2127
+ const ComboboxClear = /*#__PURE__*/React.forwardRef(function ComboboxClear(componentProps, forwardedRef) {
2128
+ const {
2129
+ render,
2130
+ className,
2131
+ disabled: disabledProp = false,
2132
+ nativeButton = true,
2133
+ keepMounted = false,
2134
+ style,
2135
+ ...elementProps
2136
+ } = componentProps;
2137
+ const {
2138
+ disabled: fieldDisabled
2139
+ } = useFieldRootContext();
2140
+ const store = useComboboxRootContext();
2141
+ const selectionMode = useStore(store, selectors.selectionMode);
2142
+ const comboboxDisabled = useStore(store, selectors.disabled);
2143
+ const readOnly = useStore(store, selectors.readOnly);
2144
+ const open = useStore(store, selectors.open);
2145
+ const selectedValue = useStore(store, selectors.selectedValue);
2146
+ const hasSelectionChips = useStore(store, selectors.hasSelectionChips);
2147
+ const inputValue = useComboboxInputValueContext();
2148
+ let visible = false;
2149
+ if (selectionMode === 'none') {
2150
+ visible = inputValue !== '';
2151
+ } else if (selectionMode === 'single') {
2152
+ visible = selectedValue != null;
2153
+ } else {
2154
+ visible = hasSelectionChips;
2155
+ }
2156
+ const disabled = fieldDisabled || comboboxDisabled || disabledProp;
2157
+ const {
2158
+ buttonRef,
2159
+ getButtonProps
2160
+ } = useButton({
2161
+ native: nativeButton,
2162
+ disabled
2163
+ });
2164
+ const {
2165
+ mounted,
2166
+ transitionStatus,
2167
+ setMounted
2168
+ } = useTransitionStatus(visible);
2169
+ const state = {
2170
+ disabled,
2171
+ visible,
2172
+ open,
2173
+ transitionStatus
2174
+ };
2175
+ useOpenChangeComplete({
2176
+ open: visible,
2177
+ ref: store.state.clearRef,
2178
+ onComplete() {
2179
+ if (!visible) {
2180
+ setMounted(false);
2181
+ }
2182
+ }
2183
+ });
2184
+ const element = useRenderElement('button', componentProps, {
2185
+ state,
2186
+ ref: [forwardedRef, buttonRef, store.state.clearRef],
2187
+ props: [{
2188
+ tabIndex: -1,
2189
+ children: 'x',
2190
+ // Avoid stealing focus from the input.
2191
+ onMouseDown(event) {
2192
+ event.preventDefault();
2193
+ },
2194
+ onClick(event) {
2195
+ if (disabled || readOnly) {
2196
+ return;
2197
+ }
2198
+ const type = store.state.keyboardActiveRef.current ? keyboard : pointer;
2199
+ store.state.setInputValue('', createChangeEventDetails(clearPress, event.nativeEvent));
2200
+ if (selectionMode !== 'none') {
2201
+ store.state.setSelectedValue(Array.isArray(selectedValue) ? [] : null, createChangeEventDetails(clearPress, event.nativeEvent));
2202
+ // A distinct object shape: `Store.update` iterates own keys, so passing an explicit
2203
+ // `selectedIndex: undefined` would overwrite the state instead of leaving it alone.
2204
+ store.state.setIndices({
2205
+ activeIndex: null,
2206
+ selectedIndex: null,
2207
+ type
2208
+ });
2209
+ } else {
2210
+ store.state.setIndices({
2211
+ activeIndex: null,
2212
+ type
2213
+ });
2214
+ }
2215
+ store.state.inputRef.current?.focus();
2216
+ }
2217
+ }, elementProps, getButtonProps],
2218
+ stateAttributesMapping: stateAttributesMapping$2
2219
+ });
2220
+ const shouldRender = keepMounted || mounted;
2221
+ if (!shouldRender) {
2222
+ return null;
2223
+ }
2224
+ return element;
2225
+ });
2226
+ if (process.env.NODE_ENV !== "production") ComboboxClear.displayName = "ComboboxClear";
2227
+
2228
+ const GroupCollectionContext = /*#__PURE__*/React.createContext(null);
2229
+ if (process.env.NODE_ENV !== "production") GroupCollectionContext.displayName = "GroupCollectionContext";
2230
+ function useGroupCollectionContext() {
2231
+ return React.useContext(GroupCollectionContext);
2232
+ }
2233
+ function GroupCollectionProvider(props) {
2234
+ const {
2235
+ children,
2236
+ items
2237
+ } = props;
2238
+ const contextValue = React.useMemo(() => ({
2239
+ items
2240
+ }), [items]);
2241
+ return /*#__PURE__*/jsx(GroupCollectionContext.Provider, {
2242
+ value: contextValue,
2243
+ children: children
2244
+ });
2245
+ }
2246
+
2247
+ function ComboboxCollection(props) {
2248
+ const {
2249
+ children
2250
+ } = props;
2251
+ const {
2252
+ filteredItems
2253
+ } = useComboboxDerivedItemsContext();
2254
+ const groupContext = useGroupCollectionContext();
2255
+ const itemsToRender = groupContext ? groupContext.items : filteredItems;
2256
+ return /*#__PURE__*/jsx(React.Fragment, {
2257
+ children: itemsToRender.map(children)
2258
+ });
2259
+ }
2260
+
2261
+ const ComboboxList = /*#__PURE__*/React.forwardRef(function ComboboxList(componentProps, forwardedRef) {
2262
+ var _ComboboxCollection;
2263
+ const {
2264
+ render,
2265
+ className,
2266
+ style,
2267
+ children,
2268
+ ...elementProps
2269
+ } = componentProps;
2270
+ const store = useComboboxRootContext();
2271
+ const floatingRootContext = useComboboxFloatingContext();
2272
+ const hasPositionerContext = Boolean(useComboboxPositionerContext(true));
2273
+ const {
2274
+ filteredItems,
2275
+ hasItems
2276
+ } = useComboboxDerivedItemsContext();
2277
+ const selectionMode = useStore(store, selectors.selectionMode);
2278
+ const grid = useStore(store, selectors.grid);
2279
+ const listProps = useStore(store, selectors.listProps);
2280
+ const virtualized = useStore(store, selectors.virtualized);
2281
+ const forceMounted = useStore(store, selectors.forceMounted);
2282
+ const multiple = selectionMode === 'multiple';
2283
+ const empty = filteredItems.length === 0;
2284
+ const setPositionerElement = useStableCallback(element => {
2285
+ store.set('positionerElement', element);
2286
+ });
2287
+ const setListElement = useStableCallback(element => {
2288
+ store.set('listElement', element);
2289
+ });
2290
+
2291
+ // Support "closed template" API: if children is a function, implicitly wrap it
2292
+ // with a Combobox.Collection that reads items from context/root.
2293
+ // Ensures this component's `listProps` subscription does not cause <Combobox.Item>
2294
+ // to re-render on every active index change.
2295
+ const resolvedChildren = React.useMemo(() => {
2296
+ if (typeof children === 'function') {
2297
+ return _ComboboxCollection || (_ComboboxCollection = /*#__PURE__*/jsx(ComboboxCollection, {
2298
+ children: children
2299
+ }));
2300
+ }
2301
+ return children;
2302
+ }, [children]);
2303
+ const state = {
2304
+ empty
2305
+ };
2306
+ const floatingId = floatingRootContext.useState('floatingId');
2307
+ const element = useRenderElement('div', componentProps, {
2308
+ state,
2309
+ ref: [forwardedRef, setListElement, hasPositionerContext ? null : setPositionerElement],
2310
+ props: [listProps, {
2311
+ children: resolvedChildren,
2312
+ tabIndex: -1,
2313
+ id: floatingId,
2314
+ role: grid ? 'grid' : 'listbox',
2315
+ 'aria-multiselectable': multiple ? 'true' : undefined,
2316
+ onKeyDown(event) {
2317
+ if (store.state.disabled || store.state.readOnly) {
2318
+ return;
2319
+ }
2320
+ if (event.key === 'Enter') {
2321
+ const activeIndex = store.state.activeIndex;
2322
+ if (activeIndex == null) {
2323
+ // Allow form submission when no item is highlighted.
2324
+ return;
2325
+ }
2326
+ stopEvent(event);
2327
+ clickHighlightedItem(store, activeIndex, event.nativeEvent);
2328
+ }
2329
+ },
2330
+ onKeyDownCapture() {
2331
+ store.state.keyboardActiveRef.current = true;
2332
+ },
2333
+ onPointerMoveCapture() {
2334
+ store.state.keyboardActiveRef.current = false;
2335
+ }
2336
+ }, elementProps]
2337
+ });
2338
+ if (virtualized) {
2339
+ return element;
2340
+ }
2341
+
2342
+ // With the `items` prop, typeahead labels are derived from the items so they survive the list
2343
+ // unmounting (unmounting clears the registered labels). Rendered labels only need to be
2344
+ // registered when the list is force-mounted to match browser autofill against rendered text.
2345
+ const labelsRef = hasItems && !forceMounted ? undefined : store.state.labelsRef;
2346
+ return /*#__PURE__*/jsx(CompositeList, {
2347
+ elementsRef: store.state.listRef,
2348
+ labelsRef: labelsRef,
2349
+ children: element
2350
+ });
2351
+ });
2352
+ if (process.env.NODE_ENV !== "production") ComboboxList.displayName = "ComboboxList";
2353
+
2354
+ // Word Joiner is invisible and zero-width, so it forces a text mutation without shifting layout.
2355
+ const LIVE_REGION_MARKER = '\u2060';
2356
+ // Safari VoiceOver needed roughly 200ms to reliably notice the initial polite live-region change.
2357
+ const INITIAL_LIVE_REGION_TEXT_MUTATION_RESET_DELAY = 200;
2358
+ function findLastTextNode(root) {
2359
+ const walker = root.ownerDocument.createTreeWalker(root, NodeFilter.SHOW_TEXT);
2360
+ let lastTextNode = null;
2361
+ while (walker.nextNode()) {
2362
+ const textNode = walker.currentNode;
2363
+ if (textNode.nodeValue !== '') {
2364
+ lastTextNode = textNode;
2365
+ }
2366
+ }
2367
+ return lastTextNode;
2368
+ }
2369
+ function useInitialLiveRegionTextMutation() {
2370
+ const timeout = useTimeout();
2371
+ const rootRef = React.useRef(null);
2372
+
2373
+ // Only the initial mounted announcement needs the marker; later text updates announce naturally.
2374
+ React.useEffect(() => {
2375
+ if (ios) {
2376
+ return undefined;
2377
+ }
2378
+ const root = rootRef.current;
2379
+ if (root == null) {
2380
+ return undefined;
2381
+ }
2382
+ const textNode = findLastTextNode(root);
2383
+ if (textNode == null) {
2384
+ return undefined;
2385
+ }
2386
+ const originalValue = textNode.data;
2387
+ const markedValue = `${originalValue}${LIVE_REGION_MARKER}`;
2388
+ textNode.nodeValue = markedValue;
2389
+ timeout.start(INITIAL_LIVE_REGION_TEXT_MUTATION_RESET_DELAY, () => {
2390
+ if (textNode.nodeValue === markedValue) {
2391
+ textNode.nodeValue = originalValue;
2392
+ }
2393
+ });
2394
+ return () => {
2395
+ timeout.clear();
2396
+ if (textNode.nodeValue === markedValue) {
2397
+ textNode.nodeValue = originalValue;
2398
+ }
2399
+ };
2400
+ }, [rootRef, timeout]);
2401
+ return rootRef;
2402
+ }
2403
+
2404
+ /**
2405
+ * Displays a status message whose content changes are announced politely to screen readers.
2406
+ * Useful for conveying the status of an asynchronously loaded list.
2407
+ * This component's root element must remain mounted in the DOM to announce
2408
+ * changes consistently across screen readers. Avoid hiding or removing the
2409
+ * component itself with `display: none`, `hidden`, `aria-hidden`, or conditional
2410
+ * rendering. Prefer updating or conditionally rendering its children instead.
2411
+ * Renders a `<div>` element.
2412
+ *
2413
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
2414
+ */
2415
+ const ComboboxStatus = /*#__PURE__*/React.forwardRef(function ComboboxStatus(componentProps, forwardedRef) {
2416
+ const {
2417
+ render,
2418
+ className,
2419
+ style,
2420
+ children: childrenProp,
2421
+ ...elementProps
2422
+ } = componentProps;
2423
+ const statusRef = useInitialLiveRegionTextMutation();
2424
+ return useRenderElement('div', componentProps, {
2425
+ ref: [forwardedRef, statusRef],
2426
+ props: [{
2427
+ children: childrenProp,
2428
+ role: 'status',
2429
+ 'aria-live': 'polite',
2430
+ 'aria-atomic': true
2431
+ }, elementProps]
2432
+ });
2433
+ });
2434
+ if (process.env.NODE_ENV !== "production") ComboboxStatus.displayName = "ComboboxStatus";
2435
+
2436
+ const ComboboxPortalContext = /*#__PURE__*/React.createContext(undefined);
2437
+ if (process.env.NODE_ENV !== "production") ComboboxPortalContext.displayName = "ComboboxPortalContext";
2438
+ function useComboboxPortalContext() {
2439
+ const context = React.useContext(ComboboxPortalContext);
2440
+ if (context === undefined) {
2441
+ throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: <Combobox.Portal> is missing.' : formatErrorMessage(20));
2442
+ }
2443
+ return context;
2444
+ }
2445
+
2446
+ const ComboboxPortal = /*#__PURE__*/React.forwardRef(function ComboboxPortal(props, forwardedRef) {
2447
+ const {
2448
+ keepMounted = false,
2449
+ ...portalProps
2450
+ } = props;
2451
+ const store = useComboboxRootContext();
2452
+ const mounted = useStore(store, selectors.mounted);
2453
+ const forceMounted = useStore(store, selectors.forceMounted);
2454
+ const shouldRender = mounted || keepMounted || forceMounted;
2455
+ if (!shouldRender) {
2456
+ return null;
2457
+ }
2458
+ return /*#__PURE__*/jsx(ComboboxPortalContext.Provider, {
2459
+ value: keepMounted,
2460
+ children: /*#__PURE__*/jsx(FloatingPortal, {
2461
+ ref: forwardedRef,
2462
+ ...portalProps
2463
+ })
2464
+ });
2465
+ });
2466
+ if (process.env.NODE_ENV !== "production") ComboboxPortal.displayName = "ComboboxPortal";
2467
+
2468
+ const stateAttributesMapping$1 = {
2469
+ ...popupStateMapping,
2470
+ ...transitionStatusMapping
2471
+ };
2472
+
2473
+ /**
2474
+ * An overlay displayed beneath the popup.
2475
+ * Renders a `<div>` element.
2476
+ *
2477
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
2478
+ */
2479
+ const ComboboxBackdrop = /*#__PURE__*/React.forwardRef(function ComboboxBackdrop(componentProps, forwardedRef) {
2480
+ const {
2481
+ render,
2482
+ className,
2483
+ style,
2484
+ ...elementProps
2485
+ } = componentProps;
2486
+ const store = useComboboxRootContext();
2487
+ const open = useStore(store, selectors.open);
2488
+ const mounted = useStore(store, selectors.mounted);
2489
+ const transitionStatus = useStore(store, selectors.transitionStatus);
2490
+ const state = {
2491
+ open,
2492
+ transitionStatus
2493
+ };
2494
+ return useRenderElement('div', componentProps, {
2495
+ state,
2496
+ ref: forwardedRef,
2497
+ stateAttributesMapping: stateAttributesMapping$1,
2498
+ props: [{
2499
+ role: 'presentation',
2500
+ hidden: !mounted,
2501
+ style: {
2502
+ userSelect: 'none',
2503
+ WebkitUserSelect: 'none'
2504
+ }
2505
+ }, elementProps]
2506
+ });
2507
+ });
2508
+ if (process.env.NODE_ENV !== "production") ComboboxBackdrop.displayName = "ComboboxBackdrop";
2509
+
2510
+ const ComboboxPositioner = /*#__PURE__*/React.forwardRef(function ComboboxPositioner(componentProps, forwardedRef) {
2511
+ const {
2512
+ render,
2513
+ className,
2514
+ anchor,
2515
+ // `useAnchorPositioning` applies the same defaults to the undefined values; the names
2516
+ // remain destructured to exclude the props from `elementProps`.
2517
+ positionMethod,
2518
+ side,
2519
+ align,
2520
+ sideOffset,
2521
+ alignOffset,
2522
+ collisionBoundary = 'clipping-ancestors',
2523
+ collisionPadding,
2524
+ arrowPadding,
2525
+ sticky,
2526
+ disableAnchorTracking = false,
2527
+ collisionAvoidance = DROPDOWN_COLLISION_AVOIDANCE,
2528
+ style: styleProp,
2529
+ ...elementProps
2530
+ } = componentProps;
2531
+ const store = useComboboxRootContext();
2532
+ const floatingRootContext = useComboboxFloatingContext();
2533
+ const keepMounted = useComboboxPortalContext();
2534
+ const modal = useStore(store, selectors.modal);
2535
+ const open = useStore(store, selectors.open);
2536
+ const mounted = useStore(store, selectors.mounted);
2537
+ const openMethod = useStore(store, selectors.openMethod);
2538
+ const positionerElement = useStore(store, selectors.positionerElement);
2539
+ const triggerElement = useStore(store, selectors.triggerElement);
2540
+ const inputElement = useStore(store, selectors.inputElement);
2541
+ const inputGroupElement = useStore(store, selectors.inputGroupElement);
2542
+ const inputInsidePopup = useStore(store, selectors.inputInsidePopup);
2543
+ const transitionStatus = useStore(store, selectors.transitionStatus);
2544
+ const empty = useListEmpty();
2545
+ const resolvedAnchor = anchor ?? (inputInsidePopup ? triggerElement : inputGroupElement ?? inputElement);
2546
+ const positioning = useAnchorPositioning({
2547
+ anchor: resolvedAnchor,
2548
+ floatingRootContext,
2549
+ positionMethod,
2550
+ mounted,
2551
+ side,
2552
+ sideOffset,
2553
+ align,
2554
+ alignOffset,
2555
+ arrowPadding,
2556
+ collisionBoundary,
2557
+ collisionPadding,
2558
+ sticky,
2559
+ disableAnchorTracking,
2560
+ keepMounted,
2561
+ collisionAvoidance,
2562
+ lazyFlip: true
2563
+ });
2564
+ useAnchoredPopupScrollLock(open && modal, openMethod === 'touch', positionerElement, triggerElement);
2565
+ const state = {
2566
+ open,
2567
+ side: positioning.side,
2568
+ align: positioning.align,
2569
+ anchorHidden: positioning.anchorHidden,
2570
+ empty
2571
+ };
2572
+ useIsoLayoutEffect(() => {
2573
+ store.set('popupSide', positioning.side);
2574
+ }, [store, positioning.side]);
2575
+ const setPositionerElement = useStableCallback(element => {
2576
+ store.set('positionerElement', element);
2577
+ });
2578
+ const element = usePositioner(componentProps, state, {
2579
+ styles: positioning.positionerStyles,
2580
+ transitionStatus,
2581
+ props: elementProps,
2582
+ refs: [forwardedRef, setPositionerElement],
2583
+ hidden: !mounted,
2584
+ inert: !open
2585
+ });
2586
+ return /*#__PURE__*/jsxs(ComboboxPositionerContext.Provider, {
2587
+ value: positioning,
2588
+ children: [mounted && modal && /*#__PURE__*/jsx(InternalBackdrop, {
2589
+ inert: inertValue(!open),
2590
+ cutout: inputGroupElement ?? inputElement ?? triggerElement
2591
+ }), element]
2592
+ });
2593
+ });
2594
+ if (process.env.NODE_ENV !== "production") ComboboxPositioner.displayName = "ComboboxPositioner";
2595
+
2596
+ const stateAttributesMapping = {
2597
+ ...popupStateMapping,
2598
+ ...transitionStatusMapping
2599
+ };
2600
+
2601
+ /**
2602
+ * A container for the list.
2603
+ * Renders a `<div>` element.
2604
+ *
2605
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
2606
+ */
2607
+ const ComboboxPopup = /*#__PURE__*/React.forwardRef(function ComboboxPopup(componentProps, forwardedRef) {
2608
+ const {
2609
+ render,
2610
+ className,
2611
+ style,
2612
+ initialFocus,
2613
+ finalFocus,
2614
+ ...elementProps
2615
+ } = componentProps;
2616
+ const store = useComboboxRootContext();
2617
+ const positioning = useComboboxPositionerContext();
2618
+ const floatingRootContext = useComboboxFloatingContext();
2619
+ const mounted = useStore(store, selectors.mounted);
2620
+ const open = useStore(store, selectors.open);
2621
+ const openMethod = useStore(store, selectors.openMethod);
2622
+ const popupProps = useStore(store, selectors.popupProps);
2623
+ const transitionStatus = useStore(store, selectors.transitionStatus);
2624
+ const inputInsidePopup = useStore(store, selectors.inputInsidePopup);
2625
+ const inputElement = useStore(store, selectors.inputElement);
2626
+ const modal = useStore(store, selectors.modal);
2627
+ const rootId = useStore(store, selectors.id);
2628
+ const empty = useListEmpty();
2629
+ const popupId = elementProps.id ?? (inputInsidePopup ? getComboboxPopupId(rootId) : undefined);
2630
+ useIsoLayoutEffect(() => {
2631
+ // Prefer the rendered DOM id, which a `render` prop element or function may override.
2632
+ store.set('popupId', store.state.popupRef.current?.id || popupId);
2633
+ return () => {
2634
+ store.set('popupId', undefined);
2635
+ };
2636
+ }, [store, popupId]);
2637
+ useOpenChangeComplete({
2638
+ open,
2639
+ ref: store.state.popupRef,
2640
+ onComplete() {
2641
+ if (open) {
2642
+ store.state.onOpenChangeComplete(true);
2643
+ }
2644
+ }
2645
+ });
2646
+ const state = {
2647
+ open,
2648
+ side: positioning.side,
2649
+ align: positioning.align,
2650
+ anchorHidden: positioning.anchorHidden,
2651
+ transitionStatus,
2652
+ empty
2653
+ };
2654
+ const element = useRenderElement('div', componentProps, {
2655
+ state,
2656
+ ref: [forwardedRef, store.state.popupRef],
2657
+ props: [popupProps, {
2658
+ id: popupId,
2659
+ role: inputInsidePopup ? 'dialog' : 'presentation',
2660
+ onFocus(event) {
2661
+ const target = getTarget(event.nativeEvent);
2662
+ if (openMethod !== 'touch' && (contains(store.state.listElement, target) || target === event.currentTarget)) {
2663
+ store.state.inputRef.current?.focus();
2664
+ }
2665
+ }
2666
+ }, getDisabledMountTransitionStyles(transitionStatus), elementProps],
2667
+ stateAttributesMapping
2668
+ });
2669
+
2670
+ // Default initial focus logic:
2671
+ // If opened by touch, focus the popup element to prevent the virtual keyboard from opening
2672
+ // (this is required for Android specifically as iOS handles this automatically).
2673
+ const computedDefaultInitialFocus = inputInsidePopup ? interactionType => interactionType === 'touch' ? store.state.popupRef.current : inputElement : false;
2674
+ const resolvedInitialFocus = initialFocus === undefined ? computedDefaultInitialFocus : initialFocus;
2675
+ let resolvedFinalFocus;
2676
+ if (finalFocus != null) {
2677
+ resolvedFinalFocus = finalFocus;
2678
+ } else {
2679
+ resolvedFinalFocus = inputInsidePopup ? undefined : false;
2680
+ }
2681
+ const focusManagerModal = !inputInsidePopup || modal;
2682
+ return /*#__PURE__*/jsx(FloatingFocusManager, {
2683
+ context: floatingRootContext,
2684
+ disabled: !mounted,
2685
+ modal: focusManagerModal,
2686
+ openInteractionType: openMethod,
2687
+ initialFocus: resolvedInitialFocus,
2688
+ returnFocus: resolvedFinalFocus,
2689
+ getInsideElements: () => [store.state.startDismissRef.current, store.state.endDismissRef.current],
2690
+ children: /*#__PURE__*/jsxs(React.Fragment, {
2691
+ children: [element, focusManagerModal && /*#__PURE__*/jsx(ComboboxInternalDismissButton, {
2692
+ ref: store.state.endDismissRef
2693
+ })]
2694
+ })
2695
+ });
2696
+ });
2697
+ if (process.env.NODE_ENV !== "production") ComboboxPopup.displayName = "ComboboxPopup";
2698
+
2699
+ /**
2700
+ * Displays an element positioned against the anchor.
2701
+ * Renders a `<div>` element.
2702
+ *
2703
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
2704
+ */
2705
+ const ComboboxArrow = /*#__PURE__*/React.forwardRef(function ComboboxArrow(componentProps, forwardedRef) {
2706
+ const {
2707
+ render,
2708
+ className,
2709
+ style,
2710
+ ...elementProps
2711
+ } = componentProps;
2712
+ const store = useComboboxRootContext();
2713
+ const {
2714
+ arrowRef,
2715
+ side,
2716
+ align,
2717
+ arrowUncentered,
2718
+ arrowStyles
2719
+ } = useComboboxPositionerContext();
2720
+ const open = useStore(store, selectors.open);
2721
+ const state = {
2722
+ open,
2723
+ side,
2724
+ align,
2725
+ uncentered: arrowUncentered
2726
+ };
2727
+ return useRenderElement('div', componentProps, {
2728
+ ref: [arrowRef, forwardedRef],
2729
+ stateAttributesMapping: popupStateMapping,
2730
+ state,
2731
+ props: {
2732
+ style: arrowStyles,
2733
+ 'aria-hidden': true,
2734
+ ...elementProps
2735
+ }
2736
+ });
2737
+ });
2738
+ if (process.env.NODE_ENV !== "production") ComboboxArrow.displayName = "ComboboxArrow";
2739
+
2740
+ const ComboboxGroupContext = /*#__PURE__*/React.createContext(undefined);
2741
+ if (process.env.NODE_ENV !== "production") ComboboxGroupContext.displayName = "ComboboxGroupContext";
2742
+ function useComboboxGroupContext() {
2743
+ const context = React.useContext(ComboboxGroupContext);
2744
+ if (context === undefined) {
2745
+ throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: ComboboxGroupContext is missing. ComboboxGroup parts must be placed within <Combobox.Group>.' : formatErrorMessage(18));
2746
+ }
2747
+ return context;
2748
+ }
2749
+
2750
+ const ComboboxGroup = /*#__PURE__*/React.forwardRef(function ComboboxGroup(componentProps, forwardedRef) {
2751
+ const {
2752
+ render,
2753
+ className,
2754
+ style,
2755
+ items,
2756
+ ...elementProps
2757
+ } = componentProps;
2758
+ const [labelId, setLabelId] = React.useState();
2759
+ const contextValue = React.useMemo(() => ({
2760
+ labelId,
2761
+ setLabelId,
2762
+ items
2763
+ }), [labelId, setLabelId, items]);
2764
+ const element = useRenderElement('div', componentProps, {
2765
+ ref: forwardedRef,
2766
+ props: [{
2767
+ role: 'group',
2768
+ 'aria-labelledby': labelId
2769
+ }, elementProps]
2770
+ });
2771
+ const wrappedElement = /*#__PURE__*/jsx(ComboboxGroupContext.Provider, {
2772
+ value: contextValue,
2773
+ children: element
2774
+ });
2775
+ if (items) {
2776
+ return /*#__PURE__*/jsx(GroupCollectionProvider, {
2777
+ items: items,
2778
+ children: wrappedElement
2779
+ });
2780
+ }
2781
+ return wrappedElement;
2782
+ });
2783
+ if (process.env.NODE_ENV !== "production") ComboboxGroup.displayName = "ComboboxGroup";
2784
+
2785
+ /**
2786
+ * An accessible label that is automatically associated with its parent group.
2787
+ * Renders a `<div>` element.
2788
+ *
2789
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
2790
+ */
2791
+ const ComboboxGroupLabel = /*#__PURE__*/React.forwardRef(function ComboboxGroupLabel(componentProps, forwardedRef) {
2792
+ const {
2793
+ render,
2794
+ className,
2795
+ style,
2796
+ id: idProp,
2797
+ ...elementProps
2798
+ } = componentProps;
2799
+ const {
2800
+ setLabelId
2801
+ } = useComboboxGroupContext();
2802
+ const id = useBaseUiId(idProp);
2803
+ useIsoLayoutEffect(() => {
2804
+ setLabelId(id);
2805
+ return () => {
2806
+ setLabelId(currentId => currentId === id ? undefined : currentId);
2807
+ };
2808
+ }, [id, setLabelId]);
2809
+ const element = useRenderElement('div', componentProps, {
2810
+ ref: forwardedRef,
2811
+ props: [{
2812
+ id
2813
+ }, elementProps]
2814
+ });
2815
+ return element;
2816
+ });
2817
+ if (process.env.NODE_ENV !== "production") ComboboxGroupLabel.displayName = "ComboboxGroupLabel";
2818
+
2819
+ const ComboboxItemContext = /*#__PURE__*/React.createContext(undefined);
2820
+ if (process.env.NODE_ENV !== "production") ComboboxItemContext.displayName = "ComboboxItemContext";
2821
+ function useComboboxItemContext() {
2822
+ const context = React.useContext(ComboboxItemContext);
2823
+ if (!context) {
2824
+ throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: ComboboxItemContext is missing. ComboboxItem parts must be placed within <Combobox.Item>.' : formatErrorMessage(19));
2825
+ }
2826
+ return context;
2827
+ }
2828
+
2829
+ const ComboboxRowContext = /*#__PURE__*/React.createContext(false);
2830
+ if (process.env.NODE_ENV !== "production") ComboboxRowContext.displayName = "ComboboxRowContext";
2831
+ function useComboboxRowContext() {
2832
+ return React.useContext(ComboboxRowContext);
2833
+ }
2834
+
2835
+ function ComboboxItemInner(props) {
2836
+ const {
2837
+ componentProps,
2838
+ forwardedRef,
2839
+ virtualized,
2840
+ indexFromFilter
2841
+ } = props;
2842
+ const {
2843
+ render,
2844
+ className,
2845
+ style,
2846
+ value: itemValue = null,
2847
+ index: indexProp,
2848
+ disabled: disabledProp = false,
2849
+ nativeButton = false,
2850
+ ...elementProps
2851
+ } = componentProps;
2852
+ const textRef = React.useRef(null);
2853
+ const listItem = useCompositeListItem({
2854
+ guess: true,
2855
+ index: indexProp,
2856
+ textRef
2857
+ });
2858
+ const store = useComboboxRootContext();
2859
+ const isRow = useComboboxRowContext();
2860
+ const hasItems = useComboboxHasItemsContext();
2861
+ const selectionMode = useStore(store, selectors.selectionMode);
2862
+ const rootDisabled = useStore(store, selectors.disabled);
2863
+ const readOnly = useStore(store, selectors.readOnly);
2864
+ const isItemEqualToValue = useStore(store, selectors.isItemEqualToValue);
2865
+ const disabled = rootDisabled || disabledProp;
2866
+ const selectable = selectionMode !== 'none';
2867
+ const index = indexProp ?? indexFromFilter ?? listItem.index;
2868
+ const hasRegistered = index !== -1;
2869
+ const rootId = useStore(store, selectors.id);
2870
+ const highlighted = useStore(store, selectors.isActive, index);
2871
+ const matchesSelectedValue = useStore(store, selectors.isSelected, itemValue);
2872
+ const itemProps = useStore(store, selectors.itemProps);
2873
+ const itemRef = React.useRef(null);
2874
+ const id = rootId != null && hasRegistered ? `${rootId}-${index}` : undefined;
2875
+ const selected = matchesSelectedValue && selectable;
2876
+ useIsoLayoutEffect(() => {
2877
+ const shouldRun = hasRegistered && (virtualized || indexProp != null);
2878
+ if (!shouldRun) {
2879
+ return undefined;
2880
+ }
2881
+ const list = store.state.listRef.current;
2882
+ list[index] = itemRef.current;
2883
+ return () => {
2884
+ delete list[index];
2885
+ };
2886
+ }, [hasRegistered, virtualized, index, indexProp, store]);
2887
+ useIsoLayoutEffect(() => {
2888
+ if (!hasRegistered || hasItems) {
2889
+ return undefined;
2890
+ }
2891
+ const visibleMap = store.state.valuesRef.current;
2892
+ visibleMap[index] = itemValue;
2893
+ return () => {
2894
+ delete visibleMap[index];
2895
+ };
2896
+ }, [hasRegistered, hasItems, index, itemValue, store]);
2897
+ useIsoLayoutEffect(() => {
2898
+ if (!hasRegistered || hasItems) {
2899
+ return;
2900
+ }
2901
+
2902
+ // Runs while closed as well (the list can stay mounted via `keepMounted` or a
2903
+ // force-mount) so the index tracks the item's composite position, keeping features
2904
+ // like closed-trigger typeahead in sync when the rendered order changes.
2905
+ const selectedValue = store.state.selectedValue;
2906
+ const lastSelectedValue = Array.isArray(selectedValue) ? selectedValue[selectedValue.length - 1] : selectedValue;
2907
+ if (compareItemEquality(itemValue, lastSelectedValue, isItemEqualToValue)) {
2908
+ store.set('selectedIndex', index);
2909
+ }
2910
+ }, [hasRegistered, hasItems, store, index, itemValue, isItemEqualToValue]);
2911
+ const {
2912
+ getButtonProps,
2913
+ buttonRef
2914
+ } = useButton({
2915
+ disabled,
2916
+ focusableWhenDisabled: true,
2917
+ native: nativeButton,
2918
+ composite: true
2919
+ });
2920
+ const state = {
2921
+ disabled,
2922
+ selected,
2923
+ highlighted
2924
+ };
2925
+ function commitSelection(nativeEvent) {
2926
+ function selectItem() {
2927
+ store.state.handleSelection(nativeEvent, itemValue);
2928
+ }
2929
+ if (store.state.submitOnItemClick) {
2930
+ ReactDOM.flushSync(selectItem);
2931
+ store.state.requestSubmit();
2932
+ } else {
2933
+ selectItem();
2934
+ }
2935
+ }
2936
+ const defaultProps = {
2937
+ id,
2938
+ role: isRow ? 'gridcell' : 'option',
2939
+ 'aria-selected': selectable ? selected : undefined,
2940
+ // Focusable items steal focus from the input upon mouseup.
2941
+ // Warn if the user renders a natively focusable element like `<button>`,
2942
+ // as it should be a `<div>` instead.
2943
+ tabIndex: undefined,
2944
+ onPointerDownCapture(event) {
2945
+ // The compat `mouseup` only fires for the primary pointer, so a non-primary
2946
+ // touch must not overwrite the shared ref — a mismatch would make the primary
2947
+ // pointer's release read as a drag-select and commit a second time after `click`.
2948
+ if (event.isPrimary) {
2949
+ store.state.pointerDownItemRef.current = event.currentTarget;
2950
+ }
2951
+ event.preventDefault();
2952
+ },
2953
+ onMouseDown(event) {
2954
+ // iOS Safari can emit a synthetic mousedown for touch taps without a preceding
2955
+ // pointerdown. Prevent default here too so tapping an item does not blur the input.
2956
+ event.preventDefault();
2957
+ },
2958
+ onClick(event) {
2959
+ if (disabled || readOnly) {
2960
+ return;
2961
+ }
2962
+ commitSelection(event.nativeEvent);
2963
+ },
2964
+ onMouseUp(event) {
2965
+ const pointerStartedOnItem = store.state.pointerDownItemRef.current === event.currentTarget;
2966
+ store.state.pointerDownItemRef.current = null;
2967
+ if (disabled || readOnly || event.button !== 0 || pointerStartedOnItem || !highlighted) {
2968
+ return;
2969
+ }
2970
+ commitSelection(event.nativeEvent);
2971
+ }
2972
+ };
2973
+ const element = useRenderElement('div', componentProps, {
2974
+ ref: [buttonRef, forwardedRef, listItem.ref, itemRef],
2975
+ state,
2976
+ props: [itemProps, defaultProps, elementProps, getButtonProps]
2977
+ });
2978
+ const contextValue = React.useMemo(() => ({
2979
+ selected,
2980
+ textRef
2981
+ }), [selected, textRef]);
2982
+ return /*#__PURE__*/jsx(ComboboxItemContext.Provider, {
2983
+ value: contextValue,
2984
+ children: element
2985
+ });
2986
+ }
2987
+
2988
+ /**
2989
+ * Resolves the index from the filtered items for the virtualized fallback (no `index` prop).
2990
+ * Isolated here so that this per-keystroke subscription to the derived-items context is only
2991
+ * paid by virtualized items. Those re-render on every input change anyway — the parent
2992
+ * virtualizer re-windows the list as the filtered set changes — so the extra subscription costs
2993
+ * them nothing, while it keeps every non-virtualized item off that context.
2994
+ */
2995
+ function ComboboxItemVirtualizedIndex(props) {
2996
+ const {
2997
+ componentProps,
2998
+ forwardedRef
2999
+ } = props;
3000
+ const store = useComboboxRootContext();
3001
+ const isItemEqualToValue = useStore(store, selectors.isItemEqualToValue);
3002
+ const {
3003
+ flatFilteredItems
3004
+ } = useComboboxDerivedItemsContext();
3005
+ const indexFromFilter = findItemIndex(flatFilteredItems, componentProps.value ?? null, isItemEqualToValue);
3006
+
3007
+ // Only reached when `virtualized` is true (see the wrapper below).
3008
+ return /*#__PURE__*/jsx(ComboboxItemInner, {
3009
+ componentProps: componentProps,
3010
+ forwardedRef: forwardedRef,
3011
+ virtualized: true,
3012
+ indexFromFilter: indexFromFilter
3013
+ });
3014
+ }
3015
+
3016
+ /**
3017
+ * An individual item in the list.
3018
+ * Renders a `<div>` element.
3019
+ *
3020
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
3021
+ */
3022
+ const ComboboxItem = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(function ComboboxItem(componentProps, forwardedRef) {
3023
+ const store = useComboboxRootContext();
3024
+ const virtualized = useStore(store, selectors.virtualized);
3025
+
3026
+ // `virtualized` (and whether an item provides an explicit `index`) must be stable for an
3027
+ // item's lifetime: the two branches return different component types, so flipping it at
3028
+ // runtime remounts the item and resets its refs and effects.
3029
+ if (virtualized && componentProps.index == null) {
3030
+ return /*#__PURE__*/jsx(ComboboxItemVirtualizedIndex, {
3031
+ componentProps: componentProps,
3032
+ forwardedRef: forwardedRef
3033
+ });
3034
+ }
3035
+ return /*#__PURE__*/jsx(ComboboxItemInner, {
3036
+ componentProps: componentProps,
3037
+ forwardedRef: forwardedRef,
3038
+ virtualized: virtualized,
3039
+ indexFromFilter: undefined
3040
+ });
3041
+ }));
3042
+ if (process.env.NODE_ENV !== "production") ComboboxItem.displayName = "ComboboxItem";
3043
+
3044
+ const ComboboxRow = /*#__PURE__*/React.forwardRef(function ComboboxRow(componentProps, forwardedRef) {
3045
+ const {
3046
+ render,
3047
+ className,
3048
+ style,
3049
+ ...elementProps
3050
+ } = componentProps;
3051
+ const element = useRenderElement('div', componentProps, {
3052
+ ref: forwardedRef,
3053
+ props: [{
3054
+ role: 'row'
3055
+ }, elementProps]
3056
+ });
3057
+ return /*#__PURE__*/jsx(ComboboxRowContext.Provider, {
3058
+ value: true,
3059
+ children: element
3060
+ });
3061
+ });
3062
+ if (process.env.NODE_ENV !== "production") ComboboxRow.displayName = "ComboboxRow";
3063
+
3064
+ /**
3065
+ * Renders its children only when the list is empty.
3066
+ * Requires the `items` prop on the root component.
3067
+ * Announces changes politely to screen readers.
3068
+ * This component's root element must remain mounted in the DOM to announce
3069
+ * changes consistently across screen readers. Avoid hiding or removing the
3070
+ * component itself with `display: none`, `hidden`, `aria-hidden`, or conditional
3071
+ * rendering. Prefer updating or conditionally rendering its children instead.
3072
+ * Renders a `<div>` element.
3073
+ *
3074
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
3075
+ */
3076
+ const ComboboxEmpty = /*#__PURE__*/React.forwardRef(function ComboboxEmpty(componentProps, forwardedRef) {
3077
+ const {
3078
+ render,
3079
+ className,
3080
+ style,
3081
+ children: childrenProp,
3082
+ ...elementProps
3083
+ } = componentProps;
3084
+ const {
3085
+ filteredItems
3086
+ } = useComboboxDerivedItemsContext();
3087
+ const store = useComboboxRootContext();
3088
+ const emptyRef = useInitialLiveRegionTextMutation();
3089
+ const children = filteredItems.length === 0 ? childrenProp : null;
3090
+ return useRenderElement('div', componentProps, {
3091
+ ref: [forwardedRef, store.state.emptyRef, emptyRef],
3092
+ props: [{
3093
+ children,
3094
+ role: 'status',
3095
+ 'aria-live': 'polite',
3096
+ 'aria-atomic': true
3097
+ }, elementProps]
3098
+ });
3099
+ });
3100
+ if (process.env.NODE_ENV !== "production") ComboboxEmpty.displayName = "ComboboxEmpty";
3101
+
3102
+ /**
3103
+ * A visual separator between items.
3104
+ * Renders a `<div>` element.
3105
+ *
3106
+ * @internal
3107
+ */
3108
+ const ListboxSeparator = /*#__PURE__*/React.forwardRef(function ListboxSeparator(componentProps, forwardedRef) {
3109
+ const {
3110
+ className,
3111
+ render,
3112
+ orientation = 'horizontal',
3113
+ style,
3114
+ ...elementProps
3115
+ } = componentProps;
3116
+ const state = {
3117
+ orientation
3118
+ };
3119
+ return useRenderElement('div', componentProps, {
3120
+ state,
3121
+ ref: forwardedRef,
3122
+ props: [{
3123
+ role: 'presentation'
3124
+ }, elementProps]
3125
+ });
3126
+ });
3127
+ if (process.env.NODE_ENV !== "production") ListboxSeparator.displayName = "ListboxSeparator";
3128
+
3129
+ /**
3130
+ * Returns the internally filtered items.
3131
+ */
3132
+ function useFilteredItems() {
3133
+ const items = useComboboxDerivedItemsContext();
3134
+ return items.filteredItems;
3135
+ }
3136
+
3137
+ function ComboboxRoot(props) {
3138
+ const {
3139
+ multiple = false,
3140
+ defaultValue,
3141
+ value,
3142
+ onValueChange,
3143
+ autoComplete,
3144
+ ...other
3145
+ } = props;
3146
+ return /*#__PURE__*/jsx(AriaCombobox, {
3147
+ ...other,
3148
+ selectionMode: multiple ? 'multiple' : 'single',
3149
+ selectedValue: value,
3150
+ defaultSelectedValue: defaultValue,
3151
+ onSelectedValueChange: onValueChange,
3152
+ formAutoComplete: autoComplete
3153
+ });
3154
+ }
3155
+
3156
+ /**
3157
+ * An accessible label that is automatically associated with the combobox trigger.
3158
+ * Renders a `<div>` element.
3159
+ *
3160
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
3161
+ */
3162
+ const ComboboxLabel = /*#__PURE__*/React.forwardRef(function ComboboxLabel(componentProps, forwardedRef) {
3163
+ const {
3164
+ render,
3165
+ className,
3166
+ style,
3167
+ ...elementProps
3168
+ } = componentProps;
3169
+ // Keep label id derived from the root and ignore runtime `id` overrides from untyped consumers.
3170
+ const elementPropsWithoutId = elementProps;
3171
+ delete elementPropsWithoutId.id;
3172
+ const fieldRootContext = useFieldRootContext();
3173
+ const store = useComboboxRootContext();
3174
+ const inputInsidePopup = useStore(store, selectors.inputInsidePopup);
3175
+ const triggerElement = useStore(store, selectors.triggerElement);
3176
+ const inputElement = useStore(store, selectors.inputElement);
3177
+ const rootId = useStore(store, selectors.id);
3178
+ const defaultLabelId = getDefaultLabelId(rootId);
3179
+ const localControlId = triggerElement?.id ?? (inputInsidePopup ? rootId : undefined);
3180
+ if (process.env.NODE_ENV !== 'production') {
3181
+ // eslint-disable-next-line react-hooks/rules-of-hooks
3182
+ React.useEffect(() => {
3183
+ if (!inputElement || inputInsidePopup) {
3184
+ return;
3185
+ }
3186
+ const ownerStackMessage = SafeReact.captureOwnerStack?.() || '';
3187
+ const message = '<Combobox.Label> labels <Combobox.Trigger> only. ' + 'When <Combobox.Input> is the form control, use a native <label> or <Field.Label> instead.';
3188
+ error(`${message}${ownerStackMessage}`);
3189
+ }, [inputElement, inputInsidePopup]);
3190
+ }
3191
+ const labelProps = useLabel({
3192
+ id: defaultLabelId,
3193
+ fallbackControlId: localControlId,
3194
+ setLabelId(nextLabelId) {
3195
+ const resolvedLabelId = typeof nextLabelId === 'function' ? nextLabelId(store.state.labelId) : nextLabelId;
3196
+ store.set('labelId', resolvedLabelId);
3197
+ }
3198
+ });
3199
+ return useRenderElement('div', componentProps, {
3200
+ ref: forwardedRef,
3201
+ state: fieldRootContext.state,
3202
+ props: [labelProps, elementProps],
3203
+ stateAttributesMapping: fieldValidityMapping
3204
+ });
3205
+ });
3206
+ if (process.env.NODE_ENV !== "production") ComboboxLabel.displayName = "ComboboxLabel";
3207
+
3208
+ function ComboboxValue(props) {
3209
+ const {
3210
+ children: childrenProp,
3211
+ placeholder
3212
+ } = props;
3213
+ const store = useComboboxRootContext();
3214
+ const itemToStringLabel = useStore(store, selectors.itemToStringLabel);
3215
+ const selectedValue = useStore(store, selectors.selectedValue);
3216
+ const items = useStore(store, selectors.items);
3217
+ const multiple = useStore(store, selectors.selectionMode) === 'multiple';
3218
+ const hasSelectedValue = useStore(store, selectors.hasSelectedValue);
3219
+ const shouldCheckNullItemLabel = !hasSelectedValue && placeholder != null && childrenProp == null;
3220
+ const hasNullLabel = useStore(store, selectors.hasNullItemLabel, shouldCheckNullItemLabel);
3221
+ let children = null;
3222
+ if (typeof childrenProp === 'function') {
3223
+ children = childrenProp(selectedValue);
3224
+ } else if (childrenProp != null) {
3225
+ children = childrenProp;
3226
+ } else if (!hasSelectedValue && placeholder != null && !hasNullLabel) {
3227
+ children = placeholder;
3228
+ } else if (multiple && Array.isArray(selectedValue)) {
3229
+ children = resolveMultipleLabels(selectedValue, items, itemToStringLabel);
3230
+ } else {
3231
+ children = resolveSelectedLabel(selectedValue, items, itemToStringLabel);
3232
+ }
3233
+ return /*#__PURE__*/jsx(React.Fragment, {
3234
+ children: children
3235
+ });
3236
+ }
3237
+
3238
+ const ComboboxItemIndicator = /*#__PURE__*/React.forwardRef(function ComboboxItemIndicator(componentProps, forwardedRef) {
3239
+ const {
3240
+ selected
3241
+ } = useComboboxItemContext();
3242
+ const shouldRender = componentProps.keepMounted || selected;
3243
+ if (!shouldRender) {
3244
+ return null;
3245
+ }
3246
+
3247
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
3248
+ return /*#__PURE__*/jsx(Inner, {
3249
+ ...componentProps,
3250
+ ref: forwardedRef
3251
+ });
3252
+ });
3253
+
3254
+ // Split the core implementation to avoid paying the hook costs unless the element needs to mount.
3255
+ if (process.env.NODE_ENV !== "production") ComboboxItemIndicator.displayName = "ComboboxItemIndicator";
3256
+ const Inner = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef((componentProps, forwardedRef) => {
3257
+ const {
3258
+ render,
3259
+ className,
3260
+ style,
3261
+ keepMounted,
3262
+ ...elementProps
3263
+ } = componentProps;
3264
+ const {
3265
+ selected
3266
+ } = useComboboxItemContext();
3267
+ const indicatorRef = React.useRef(null);
3268
+ const {
3269
+ transitionStatus,
3270
+ setMounted
3271
+ } = useTransitionStatus(selected);
3272
+ const state = {
3273
+ selected,
3274
+ transitionStatus
3275
+ };
3276
+ const element = useRenderElement('span', componentProps, {
3277
+ ref: [forwardedRef, indicatorRef],
3278
+ state,
3279
+ props: [{
3280
+ 'aria-hidden': true,
3281
+ children: '✔️'
3282
+ }, elementProps],
3283
+ stateAttributesMapping: transitionStatusMapping
3284
+ });
3285
+ useOpenChangeComplete({
3286
+ open: selected,
3287
+ ref: indicatorRef,
3288
+ onComplete() {
3289
+ if (!selected) {
3290
+ setMounted(false);
3291
+ }
3292
+ }
3293
+ });
3294
+ return element;
3295
+ }));
3296
+ if (process.env.NODE_ENV !== "production") Inner.displayName = "Inner";
3297
+
3298
+ const ComboboxChips = /*#__PURE__*/React.forwardRef(function ComboboxChips(componentProps, forwardedRef) {
3299
+ const {
3300
+ render,
3301
+ className,
3302
+ style,
3303
+ ...elementProps
3304
+ } = componentProps;
3305
+ const store = useComboboxRootContext();
3306
+ const open = useStore(store, selectors.open);
3307
+ const hasSelectionChips = useStore(store, selectors.hasSelectionChips);
3308
+ const [highlightedChipIndex, setHighlightedChipIndex] = React.useState(undefined);
3309
+ if (open && highlightedChipIndex !== undefined) {
3310
+ setHighlightedChipIndex(undefined);
3311
+ }
3312
+ const chipsRef = React.useRef([]);
3313
+ const element = useRenderElement('div', componentProps, {
3314
+ ref: [forwardedRef, store.state.chipsContainerRef],
3315
+ // NVDA enters browse mode instead of staying in focus mode when navigating with
3316
+ // arrow keys inside a container unless it has a toolbar role.
3317
+ props: [hasSelectionChips ? {
3318
+ role: 'toolbar'
3319
+ } : EMPTY_OBJECT, {
3320
+ onMouseDown(event) {
3321
+ handleInputPress(event, store, store.state.disabled, store.state.readOnly);
3322
+ }
3323
+ }, elementProps]
3324
+ });
3325
+ const contextValue = React.useMemo(() => ({
3326
+ highlightedChipIndex,
3327
+ setHighlightedChipIndex,
3328
+ chipsRef
3329
+ }), [highlightedChipIndex, setHighlightedChipIndex, chipsRef]);
3330
+ return /*#__PURE__*/jsx(ComboboxChipsContext.Provider, {
3331
+ value: contextValue,
3332
+ children: /*#__PURE__*/jsx(CompositeList, {
3333
+ elementsRef: chipsRef,
3334
+ children: element
3335
+ })
3336
+ });
3337
+ });
3338
+ if (process.env.NODE_ENV !== "production") ComboboxChips.displayName = "ComboboxChips";
3339
+
3340
+ const ComboboxChipContext = /*#__PURE__*/React.createContext(undefined);
3341
+ if (process.env.NODE_ENV !== "production") ComboboxChipContext.displayName = "ComboboxChipContext";
3342
+ function useComboboxChipContext() {
3343
+ const context = React.useContext(ComboboxChipContext);
3344
+ if (!context) {
3345
+ throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: ComboboxChipContext is missing. ComboboxChip parts must be placed within <Combobox.Chip>.' : formatErrorMessage(17));
3346
+ }
3347
+ return context;
3348
+ }
3349
+
3350
+ const ComboboxChip = /*#__PURE__*/React.forwardRef(function ComboboxChip(componentProps, forwardedRef) {
3351
+ const {
3352
+ render,
3353
+ className,
3354
+ style,
3355
+ ...elementProps
3356
+ } = componentProps;
3357
+ const store = useComboboxRootContext();
3358
+ const {
3359
+ setHighlightedChipIndex,
3360
+ chipsRef
3361
+ } = useComboboxChipsContext();
3362
+ const direction = useDirection();
3363
+ const disabled = useStore(store, selectors.disabled);
3364
+ const readOnly = useStore(store, selectors.readOnly);
3365
+ const selectedValue = useStore(store, selectors.selectedValue);
3366
+ const {
3367
+ ref,
3368
+ index
3369
+ } = useCompositeListItem();
3370
+ function handleKeyDown(event) {
3371
+ let nextIndex = index;
3372
+ const [previousChipKey, nextChipKey] = getChipNavigationKeys(direction);
3373
+ if (event.key === previousChipKey) {
3374
+ event.preventDefault();
3375
+ if (index > 0) {
3376
+ nextIndex = index - 1;
3377
+ } else {
3378
+ nextIndex = undefined;
3379
+ }
3380
+ } else if (event.key === nextChipKey) {
3381
+ event.preventDefault();
3382
+ if (index < chipsRef.current.length - 1) {
3383
+ nextIndex = index + 1;
3384
+ } else {
3385
+ nextIndex = undefined;
3386
+ }
3387
+ } else if (event.key === 'Backspace' || event.key === 'Delete') {
3388
+ nextIndex = getIndexAfterChipRemoval(index, selectedValue.length);
3389
+ stopEvent(event);
3390
+ store.state.setIndices({
3391
+ activeIndex: null,
3392
+ selectedIndex: null,
3393
+ type: keyboard
3394
+ });
3395
+ store.state.setSelectedValue(selectedValue.filter((_, i) => i !== index), createChangeEventDetails(none, event.nativeEvent));
3396
+ } else if (event.key === 'Enter' || event.key === ' ') {
3397
+ stopEvent(event);
3398
+ nextIndex = undefined;
3399
+ } else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
3400
+ stopEvent(event);
3401
+ store.state.setOpen(true, createChangeEventDetails(listNavigation, event.nativeEvent));
3402
+ nextIndex = undefined;
3403
+ } else if (
3404
+ // Check for printable characters (letters, numbers, symbols)
3405
+ event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
3406
+ nextIndex = undefined;
3407
+ }
3408
+ return nextIndex;
3409
+ }
3410
+ const state = {
3411
+ disabled
3412
+ };
3413
+ const element = useRenderElement('div', componentProps, {
3414
+ ref: [forwardedRef, ref],
3415
+ state,
3416
+ props: [{
3417
+ tabIndex: -1,
3418
+ 'aria-disabled': disabled || undefined,
3419
+ 'aria-readonly': readOnly || undefined,
3420
+ onKeyDown(event) {
3421
+ if (disabled || readOnly) {
3422
+ return;
3423
+ }
3424
+ const nextIndex = handleKeyDown(event);
3425
+ ReactDOM.flushSync(() => {
3426
+ setHighlightedChipIndex(nextIndex);
3427
+ });
3428
+ if (nextIndex === undefined) {
3429
+ store.state.inputRef.current?.focus();
3430
+ } else {
3431
+ chipsRef.current[nextIndex]?.focus();
3432
+ }
3433
+ }
3434
+ }, elementProps]
3435
+ });
3436
+ const contextValue = React.useMemo(() => ({
3437
+ index
3438
+ }), [index]);
3439
+ return /*#__PURE__*/jsx(ComboboxChipContext.Provider, {
3440
+ value: contextValue,
3441
+ children: element
3442
+ });
3443
+ });
3444
+ if (process.env.NODE_ENV !== "production") ComboboxChip.displayName = "ComboboxChip";
3445
+
3446
+ /**
3447
+ * A button to remove a chip.
3448
+ * Renders a `<button>` element.
3449
+ *
3450
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
3451
+ */
3452
+ const ComboboxChipRemove = /*#__PURE__*/React.forwardRef(function ComboboxChipRemove(componentProps, forwardedRef) {
3453
+ const {
3454
+ render,
3455
+ className,
3456
+ disabled: disabledProp = false,
3457
+ nativeButton = true,
3458
+ style,
3459
+ ...elementProps
3460
+ } = componentProps;
3461
+ const store = useComboboxRootContext();
3462
+ const {
3463
+ index
3464
+ } = useComboboxChipContext();
3465
+ const comboboxDisabled = useStore(store, selectors.disabled);
3466
+ const readOnly = useStore(store, selectors.readOnly);
3467
+ const selectedValue = useStore(store, selectors.selectedValue);
3468
+ const isItemEqualToValue = useStore(store, selectors.isItemEqualToValue);
3469
+ const disabled = comboboxDisabled || disabledProp;
3470
+ const {
3471
+ buttonRef,
3472
+ getButtonProps
3473
+ } = useButton({
3474
+ native: nativeButton,
3475
+ disabled: disabled || readOnly,
3476
+ focusableWhenDisabled: true
3477
+ });
3478
+ const state = {
3479
+ disabled
3480
+ };
3481
+ function clearActiveIndexForRemovedItem(removedItem) {
3482
+ const activeIndex = store.state.activeIndex;
3483
+ if (activeIndex == null) {
3484
+ return;
3485
+ }
3486
+
3487
+ // Try current visible list first; if not found, it's filtered out.
3488
+ // No need to clear highlight in that case since it can't equal activeIndex.
3489
+ const removedIndex = findItemIndex(store.state.valuesRef.current, removedItem, isItemEqualToValue);
3490
+ if (removedIndex !== -1 && activeIndex === removedIndex) {
3491
+ store.state.setIndices({
3492
+ activeIndex: null,
3493
+ type: store.state.keyboardActiveRef.current ? keyboard : pointer
3494
+ });
3495
+ }
3496
+ }
3497
+ function removeChip(event) {
3498
+ const eventDetails = createChangeEventDetails(chipRemovePress, event.nativeEvent);
3499
+ const removedItem = selectedValue[index];
3500
+ clearActiveIndexForRemovedItem(removedItem);
3501
+ store.state.setSelectedValue(selectedValue.filter((_, i) => i !== index), eventDetails);
3502
+ store.state.inputRef.current?.focus();
3503
+ return eventDetails;
3504
+ }
3505
+ const element = useRenderElement('button', componentProps, {
3506
+ ref: [forwardedRef, buttonRef],
3507
+ state,
3508
+ props: [{
3509
+ tabIndex: -1,
3510
+ onMouseDown(event) {
3511
+ event.preventDefault();
3512
+ },
3513
+ onClick(event) {
3514
+ const eventDetails = removeChip(event);
3515
+ if (!eventDetails.isPropagationAllowed) {
3516
+ event.stopPropagation();
3517
+ }
3518
+ },
3519
+ onKeyDown(event) {
3520
+ if (event.key === 'Enter' || event.key === ' ') {
3521
+ const eventDetails = removeChip(event);
3522
+ if (!eventDetails.isPropagationAllowed) {
3523
+ stopEvent(event);
3524
+ }
3525
+ }
3526
+ }
3527
+ }, elementProps, getButtonProps]
3528
+ });
3529
+ return element;
3530
+ });
3531
+ if (process.env.NODE_ENV !== "production") ComboboxChipRemove.displayName = "ComboboxChipRemove";
3532
+
3533
+ /**
3534
+ * A visual separator between items or groups.
3535
+ * Renders a `<div>` element.
3536
+ *
3537
+ * Documentation: [Base UI Combobox](https://base-ui.com/react/components/combobox)
3538
+ */
3539
+ const ComboboxSeparator = ListboxSeparator;
3540
+
3541
+ export { useFilteredItems as A, useCoreFilter as B, ComboboxRoot as C, AriaCombobox as D, useComboboxInputValueContext as E, ListboxSeparator as L, ComboboxLabel as a, ComboboxValue as b, ComboboxInput as c, ComboboxInputGroup as d, ComboboxTrigger as e, ComboboxList as f, ComboboxStatus as g, ComboboxPortal as h, ComboboxBackdrop as i, ComboboxPositioner as j, ComboboxPopup as k, ComboboxArrow as l, ComboboxIcon as m, ComboboxGroup as n, ComboboxGroupLabel as o, ComboboxItem as p, ComboboxItemIndicator as q, ComboboxChips as r, ComboboxChip as s, ComboboxChipRemove as t, ComboboxRow as u, ComboboxCollection as v, ComboboxEmpty as w, ComboboxClear as x, ComboboxSeparator as y, useComboboxFilter as z };