@primer/components 0.0.0-2021102918546 → 0.0.0-202110303104

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 (437) hide show
  1. package/CHANGELOG.md +4 -90
  2. package/dist/browser.esm.js +774 -718
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +772 -716
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/Divider.jsx +29 -0
  7. package/lib/ActionList/Group.jsx +23 -0
  8. package/lib/ActionList/Header.jsx +66 -0
  9. package/lib/ActionList/Item.js +52 -27
  10. package/lib/ActionList/Item.jsx +311 -0
  11. package/lib/ActionList/List.jsx +138 -0
  12. package/lib/ActionList/index.js +12 -23
  13. package/lib/ActionList2/Description.jsx +29 -0
  14. package/lib/ActionList2/Divider.jsx +22 -0
  15. package/lib/ActionList2/Group.d.ts +2 -28
  16. package/lib/ActionList2/Group.js +6 -55
  17. package/lib/ActionList2/Group.jsx +25 -0
  18. package/lib/ActionList2/Header.d.ts +26 -0
  19. package/lib/ActionList2/Header.js +55 -0
  20. package/lib/ActionList2/Header.jsx +36 -0
  21. package/lib/ActionList2/Item.js +1 -2
  22. package/lib/ActionList2/Item.jsx +174 -0
  23. package/lib/ActionList2/LinkItem.jsx +28 -0
  24. package/lib/ActionList2/List.d.ts +1 -1
  25. package/lib/ActionList2/List.js +2 -1
  26. package/lib/ActionList2/List.jsx +41 -0
  27. package/lib/ActionList2/Selection.jsx +50 -0
  28. package/lib/ActionList2/Visuals.jsx +48 -0
  29. package/lib/ActionList2/index.js +23 -41
  30. package/lib/ActionMenu.jsx +73 -0
  31. package/lib/AnchoredOverlay/AnchoredOverlay.jsx +100 -0
  32. package/lib/AnchoredOverlay/index.js +4 -12
  33. package/lib/Autocomplete/Autocomplete.d.ts +3 -4
  34. package/lib/Autocomplete/Autocomplete.jsx +100 -0
  35. package/lib/Autocomplete/AutocompleteContext.jsx +5 -0
  36. package/lib/Autocomplete/AutocompleteInput.d.ts +3 -4
  37. package/lib/Autocomplete/AutocompleteInput.jsx +113 -0
  38. package/lib/Autocomplete/AutocompleteMenu.jsx +190 -0
  39. package/lib/Autocomplete/AutocompleteOverlay.jsx +55 -0
  40. package/lib/Autocomplete/index.js +7 -14
  41. package/lib/Avatar.jsx +34 -0
  42. package/lib/AvatarPair.jsx +29 -0
  43. package/lib/AvatarStack.jsx +151 -0
  44. package/lib/BaseStyles.jsx +65 -0
  45. package/lib/BorderBox.jsx +18 -0
  46. package/lib/Box.jsx +10 -0
  47. package/lib/BranchName.jsx +20 -0
  48. package/lib/Breadcrumbs.d.ts +7 -8
  49. package/lib/Breadcrumbs.js +12 -7
  50. package/lib/Breadcrumbs.jsx +74 -0
  51. package/lib/Button/Button.d.ts +3 -3
  52. package/lib/Button/Button.js +6 -2
  53. package/lib/Button/Button.jsx +60 -0
  54. package/lib/Button/ButtonBase.d.ts +8 -5
  55. package/lib/Button/ButtonBase.js +5 -1
  56. package/lib/Button/ButtonBase.jsx +36 -0
  57. package/lib/Button/ButtonClose.d.ts +46 -4
  58. package/lib/Button/ButtonClose.js +1 -1
  59. package/lib/Button/ButtonClose.jsx +55 -0
  60. package/lib/Button/ButtonDanger.d.ts +3 -3
  61. package/lib/Button/ButtonDanger.js +6 -2
  62. package/lib/Button/ButtonDanger.jsx +63 -0
  63. package/lib/Button/ButtonGroup.jsx +55 -0
  64. package/lib/Button/ButtonInvisible.d.ts +3 -3
  65. package/lib/Button/ButtonInvisible.js +6 -2
  66. package/lib/Button/ButtonInvisible.jsx +52 -0
  67. package/lib/Button/ButtonOutline.d.ts +3 -3
  68. package/lib/Button/ButtonOutline.js +6 -2
  69. package/lib/Button/ButtonOutline.jsx +63 -0
  70. package/lib/Button/ButtonPrimary.d.ts +3 -3
  71. package/lib/Button/ButtonPrimary.js +6 -2
  72. package/lib/Button/ButtonPrimary.jsx +62 -0
  73. package/lib/Button/ButtonStyles.jsx +37 -0
  74. package/lib/Button/ButtonTableList.d.ts +2 -1
  75. package/lib/Button/ButtonTableList.js +1 -1
  76. package/lib/Button/ButtonTableList.jsx +49 -0
  77. package/lib/Button/index.js +21 -70
  78. package/lib/Caret.jsx +93 -0
  79. package/lib/CircleBadge.d.ts +5 -4
  80. package/lib/CircleBadge.js +1 -1
  81. package/lib/CircleBadge.jsx +43 -0
  82. package/lib/CircleOcticon.d.ts +1 -2
  83. package/lib/CircleOcticon.jsx +21 -0
  84. package/lib/CounterLabel.d.ts +2 -1
  85. package/lib/CounterLabel.js +1 -1
  86. package/lib/CounterLabel.jsx +44 -0
  87. package/lib/Details.jsx +21 -0
  88. package/lib/Dialog/ConfirmationDialog.jsx +146 -0
  89. package/lib/Dialog/Dialog.d.ts +9 -5
  90. package/lib/Dialog/Dialog.js +11 -17
  91. package/lib/Dialog/Dialog.jsx +273 -0
  92. package/lib/Dialog.d.ts +5 -5
  93. package/lib/Dialog.js +1 -1
  94. package/lib/Dialog.jsx +131 -0
  95. package/lib/Dropdown.d.ts +99 -14
  96. package/lib/Dropdown.js +3 -3
  97. package/lib/Dropdown.jsx +134 -0
  98. package/lib/DropdownMenu/DropdownButton.d.ts +47 -4
  99. package/lib/DropdownMenu/DropdownButton.js +1 -3
  100. package/lib/DropdownMenu/DropdownButton.jsx +14 -0
  101. package/lib/DropdownMenu/DropdownMenu.jsx +70 -0
  102. package/lib/DropdownMenu/index.js +6 -20
  103. package/lib/DropdownStyles.js +18 -26
  104. package/lib/EmojiPicker/EmojiPicker.d.ts +15 -0
  105. package/lib/EmojiPicker/EmojiPicker.js +205 -0
  106. package/lib/EmojiPicker/EmojiPicker.jsx +125 -0
  107. package/lib/EmojiPicker/EmojiPickerAnchor.d.ts +0 -0
  108. package/lib/EmojiPicker/EmojiPickerAnchor.js +1 -0
  109. package/lib/EmojiPicker/EmojiPickerAnchor.jsx +1 -0
  110. package/lib/EmojiPicker/EmojiPickerPanel.d.ts +3 -0
  111. package/lib/EmojiPicker/EmojiPickerPanel.js +18 -0
  112. package/lib/EmojiPicker/EmojiPickerPanel.jsx +10 -0
  113. package/lib/EmojiPicker/data.d.ts +9 -0
  114. package/lib/EmojiPicker/data.js +7254 -0
  115. package/lib/EmojiPicker/index.d.ts +2 -0
  116. package/lib/EmojiPicker/index.js +8 -0
  117. package/lib/FilterList.d.ts +303 -265
  118. package/lib/FilterList.js +6 -2
  119. package/lib/FilterList.jsx +63 -0
  120. package/lib/FilteredActionList/FilteredActionList.jsx +100 -0
  121. package/lib/FilteredActionList/index.js +4 -12
  122. package/lib/FilteredSearch.d.ts +2 -1
  123. package/lib/FilteredSearch.js +1 -1
  124. package/lib/FilteredSearch.jsx +29 -0
  125. package/lib/Flash.d.ts +2 -1
  126. package/lib/Flash.js +1 -1
  127. package/lib/Flash.jsx +70 -0
  128. package/lib/Flex.jsx +15 -0
  129. package/lib/FormGroup.d.ts +5 -4
  130. package/lib/FormGroup.js +2 -2
  131. package/lib/FormGroup.jsx +25 -0
  132. package/lib/Grid.jsx +15 -0
  133. package/lib/Header.d.ts +7 -6
  134. package/lib/Header.js +4 -4
  135. package/lib/Header.jsx +90 -0
  136. package/lib/Heading.jsx +21 -0
  137. package/lib/Label.d.ts +2 -1
  138. package/lib/Label.js +3 -2
  139. package/lib/Label.jsx +84 -0
  140. package/lib/LabelGroup.d.ts +2 -1
  141. package/lib/LabelGroup.js +1 -1
  142. package/lib/LabelGroup.jsx +19 -0
  143. package/lib/Link.d.ts +2 -1
  144. package/lib/Link.js +1 -1
  145. package/lib/Link.jsx +38 -0
  146. package/lib/NewButton/button-counter.jsx +14 -0
  147. package/lib/NewButton/button.js +42 -34
  148. package/lib/NewButton/button.jsx +278 -0
  149. package/lib/NewButton/index.js +5 -12
  150. package/lib/NewButton/types.js +2 -1
  151. package/lib/Overlay.d.ts +11 -14
  152. package/lib/Overlay.js +4 -3
  153. package/lib/Overlay.jsx +156 -0
  154. package/lib/Pagehead.d.ts +2 -1
  155. package/lib/Pagehead.js +1 -1
  156. package/lib/Pagehead.jsx +18 -0
  157. package/lib/Pagination/Pagination.js +1 -1
  158. package/lib/Pagination/Pagination.jsx +163 -0
  159. package/lib/Pagination/index.js +6 -12
  160. package/lib/Pagination/model.jsx +174 -0
  161. package/lib/PointerBox.jsx +25 -0
  162. package/lib/Popover.d.ts +5 -4
  163. package/lib/Popover.js +5 -4
  164. package/lib/Popover.jsx +210 -0
  165. package/lib/Portal/Portal.jsx +79 -0
  166. package/lib/Portal/index.js +5 -16
  167. package/lib/Position.d.ts +4 -4
  168. package/lib/Position.jsx +46 -0
  169. package/lib/ProgressBar.jsx +39 -0
  170. package/lib/SelectMenu/SelectMenu.d.ts +189 -27
  171. package/lib/SelectMenu/SelectMenu.js +3 -1
  172. package/lib/SelectMenu/SelectMenu.jsx +114 -0
  173. package/lib/SelectMenu/SelectMenuContext.jsx +5 -0
  174. package/lib/SelectMenu/SelectMenuDivider.d.ts +2 -1
  175. package/lib/SelectMenu/SelectMenuDivider.js +1 -1
  176. package/lib/SelectMenu/SelectMenuDivider.jsx +43 -0
  177. package/lib/SelectMenu/SelectMenuFilter.js +1 -1
  178. package/lib/SelectMenu/SelectMenuFilter.jsx +59 -0
  179. package/lib/SelectMenu/SelectMenuFooter.d.ts +2 -1
  180. package/lib/SelectMenu/SelectMenuFooter.js +1 -1
  181. package/lib/SelectMenu/SelectMenuFooter.jsx +46 -0
  182. package/lib/SelectMenu/SelectMenuHeader.d.ts +2 -1
  183. package/lib/SelectMenu/SelectMenuHeader.js +1 -1
  184. package/lib/SelectMenu/SelectMenuHeader.jsx +44 -0
  185. package/lib/SelectMenu/SelectMenuItem.d.ts +3 -2
  186. package/lib/SelectMenu/SelectMenuItem.js +1 -1
  187. package/lib/SelectMenu/SelectMenuItem.jsx +143 -0
  188. package/lib/SelectMenu/SelectMenuList.d.ts +2 -1
  189. package/lib/SelectMenu/SelectMenuList.js +1 -1
  190. package/lib/SelectMenu/SelectMenuList.jsx +60 -0
  191. package/lib/SelectMenu/SelectMenuLoadingAnimation.d.ts +2 -2
  192. package/lib/SelectMenu/SelectMenuLoadingAnimation.js +1 -3
  193. package/lib/SelectMenu/SelectMenuLoadingAnimation.jsx +21 -0
  194. package/lib/SelectMenu/SelectMenuModal.d.ts +3 -2
  195. package/lib/SelectMenu/SelectMenuModal.js +1 -1
  196. package/lib/SelectMenu/SelectMenuModal.jsx +119 -0
  197. package/lib/SelectMenu/SelectMenuTab.d.ts +2 -1
  198. package/lib/SelectMenu/SelectMenuTab.js +1 -1
  199. package/lib/SelectMenu/SelectMenuTab.jsx +93 -0
  200. package/lib/SelectMenu/SelectMenuTabPanel.d.ts +2 -1
  201. package/lib/SelectMenu/SelectMenuTabPanel.js +1 -1
  202. package/lib/SelectMenu/SelectMenuTabPanel.jsx +43 -0
  203. package/lib/SelectMenu/SelectMenuTabs.d.ts +2 -1
  204. package/lib/SelectMenu/SelectMenuTabs.js +1 -1
  205. package/lib/SelectMenu/SelectMenuTabs.jsx +58 -0
  206. package/lib/SelectMenu/hooks/useKeyboardNav.js +80 -96
  207. package/lib/SelectMenu/index.js +7 -14
  208. package/lib/SelectPanel/SelectPanel.jsx +105 -0
  209. package/lib/SelectPanel/index.js +4 -12
  210. package/lib/SideNav.d.ts +8 -11
  211. package/lib/SideNav.js +15 -8
  212. package/lib/SideNav.jsx +177 -0
  213. package/lib/Spinner.jsx +35 -0
  214. package/lib/StateLabel.d.ts +2 -1
  215. package/lib/StateLabel.js +5 -6
  216. package/lib/StateLabel.jsx +94 -0
  217. package/lib/StyledOcticon.d.ts +2 -1
  218. package/lib/StyledOcticon.js +3 -1
  219. package/lib/StyledOcticon.jsx +20 -0
  220. package/lib/SubNav.d.ts +11 -5
  221. package/lib/SubNav.js +12 -7
  222. package/lib/SubNav.jsx +104 -0
  223. package/lib/TabNav.d.ts +4 -3
  224. package/lib/TabNav.js +2 -2
  225. package/lib/TabNav.jsx +60 -0
  226. package/lib/Text.jsx +14 -0
  227. package/lib/TextInput.jsx +23 -0
  228. package/lib/TextInputWithTokens.d.ts +3 -4
  229. package/lib/TextInputWithTokens.jsx +218 -0
  230. package/lib/ThemeProvider.jsx +130 -0
  231. package/lib/Timeline.d.ts +393 -19
  232. package/lib/Timeline.js +13 -16
  233. package/lib/Timeline.jsx +124 -0
  234. package/lib/Token/AvatarToken.d.ts +1 -1
  235. package/lib/Token/AvatarToken.jsx +54 -0
  236. package/lib/Token/IssueLabelToken.d.ts +1 -1
  237. package/lib/Token/IssueLabelToken.jsx +125 -0
  238. package/lib/Token/Token.d.ts +1 -1
  239. package/lib/Token/Token.jsx +103 -0
  240. package/lib/Token/TokenBase.jsx +88 -0
  241. package/lib/Token/_RemoveTokenButton.jsx +108 -0
  242. package/lib/Token/_TokenTextContainer.jsx +49 -0
  243. package/lib/Token/index.js +11 -30
  244. package/lib/Tooltip.d.ts +2 -1
  245. package/lib/Tooltip.js +1 -1
  246. package/lib/Tooltip.jsx +246 -0
  247. package/lib/Truncate.d.ts +2 -1
  248. package/lib/Truncate.js +3 -1
  249. package/lib/Truncate.jsx +27 -0
  250. package/lib/UnderlineNav.d.ts +3 -2
  251. package/lib/UnderlineNav.js +2 -2
  252. package/lib/UnderlineNav.jsx +90 -0
  253. package/lib/_TextInputWrapper.jsx +120 -0
  254. package/lib/_UnstyledTextInput.jsx +22 -0
  255. package/lib/behaviors/anchoredPosition.js +205 -234
  256. package/lib/behaviors/focusTrap.js +121 -157
  257. package/lib/behaviors/focusZone.js +434 -509
  258. package/lib/behaviors/scrollIntoViewingArea.js +18 -35
  259. package/lib/constants.js +39 -43
  260. package/lib/drafts.js +20 -30
  261. package/lib/hooks/index.js +16 -60
  262. package/lib/hooks/useAnchoredPosition.js +32 -40
  263. package/lib/hooks/useCombinedRefs.js +32 -36
  264. package/lib/hooks/useDetails.jsx +39 -0
  265. package/lib/hooks/useDialog.js +72 -96
  266. package/lib/hooks/useFocusTrap.js +43 -60
  267. package/lib/hooks/useFocusZone.js +54 -50
  268. package/lib/hooks/useOnEscapePress.js +25 -36
  269. package/lib/hooks/useOnOutsideClick.jsx +61 -0
  270. package/lib/hooks/useOpenAndCloseFocus.js +22 -34
  271. package/lib/hooks/useOverlay.jsx +15 -0
  272. package/lib/hooks/useProvidedRefOrCreate.js +10 -14
  273. package/lib/hooks/useProvidedStateOrCreate.js +13 -16
  274. package/lib/hooks/useRenderForcingRef.js +13 -17
  275. package/lib/hooks/useResizeObserver.js +15 -18
  276. package/lib/hooks/useSafeTimeout.js +22 -30
  277. package/lib/hooks/useScrollFlash.js +16 -23
  278. package/lib/index.d.ts +2 -2
  279. package/lib/index.js +165 -652
  280. package/lib/polyfills/eventListenerSignal.js +37 -45
  281. package/lib/sx.js +10 -22
  282. package/lib/theme-preval.js +64 -3169
  283. package/lib/theme.js +3 -12
  284. package/lib/utils/create-slots.jsx +65 -0
  285. package/lib/utils/deprecate.jsx +59 -0
  286. package/lib/utils/isNumeric.jsx +7 -0
  287. package/lib/utils/iterateFocusableElements.js +63 -85
  288. package/lib/utils/ssr.jsx +6 -0
  289. package/lib/utils/test-deprecations.jsx +20 -0
  290. package/lib/utils/test-helpers.jsx +8 -0
  291. package/lib/utils/test-matchers.jsx +100 -0
  292. package/lib/utils/testing.d.ts +61 -8
  293. package/lib/utils/testing.js +0 -29
  294. package/lib/utils/testing.jsx +206 -0
  295. package/lib/utils/theme.js +33 -47
  296. package/lib/utils/types/AriaRole.js +2 -1
  297. package/lib/utils/types/ComponentProps.js +2 -1
  298. package/lib/utils/types/Flatten.js +2 -1
  299. package/lib/utils/types/KeyPaths.js +2 -1
  300. package/lib/utils/types/MandateProps.js +16 -1
  301. package/lib/utils/types/Merge.js +2 -1
  302. package/lib/utils/types/index.js +16 -69
  303. package/lib/utils/uniqueId.js +5 -8
  304. package/lib/utils/use-force-update.js +8 -14
  305. package/lib/utils/useIsomorphicLayoutEffect.js +8 -11
  306. package/lib/utils/userAgent.js +8 -12
  307. package/lib-esm/ActionList/Item.js +53 -28
  308. package/lib-esm/ActionList2/Group.d.ts +2 -28
  309. package/lib-esm/ActionList2/Group.js +5 -52
  310. package/lib-esm/ActionList2/Header.d.ts +26 -0
  311. package/lib-esm/ActionList2/Header.js +44 -0
  312. package/lib-esm/ActionList2/Item.js +1 -2
  313. package/lib-esm/ActionList2/List.d.ts +1 -1
  314. package/lib-esm/ActionList2/List.js +2 -1
  315. package/lib-esm/Autocomplete/Autocomplete.d.ts +3 -4
  316. package/lib-esm/Autocomplete/AutocompleteInput.d.ts +3 -4
  317. package/lib-esm/Breadcrumbs.d.ts +7 -8
  318. package/lib-esm/Breadcrumbs.js +13 -8
  319. package/lib-esm/Button/Button.d.ts +3 -3
  320. package/lib-esm/Button/Button.js +2 -2
  321. package/lib-esm/Button/ButtonBase.d.ts +8 -5
  322. package/lib-esm/Button/ButtonBase.js +3 -1
  323. package/lib-esm/Button/ButtonClose.d.ts +46 -4
  324. package/lib-esm/Button/ButtonClose.js +2 -2
  325. package/lib-esm/Button/ButtonDanger.d.ts +3 -3
  326. package/lib-esm/Button/ButtonDanger.js +2 -2
  327. package/lib-esm/Button/ButtonInvisible.d.ts +3 -3
  328. package/lib-esm/Button/ButtonInvisible.js +2 -2
  329. package/lib-esm/Button/ButtonOutline.d.ts +3 -3
  330. package/lib-esm/Button/ButtonOutline.js +2 -2
  331. package/lib-esm/Button/ButtonPrimary.d.ts +3 -3
  332. package/lib-esm/Button/ButtonPrimary.js +2 -2
  333. package/lib-esm/Button/ButtonTableList.d.ts +2 -1
  334. package/lib-esm/Button/ButtonTableList.js +2 -2
  335. package/lib-esm/CircleBadge.d.ts +5 -4
  336. package/lib-esm/CircleBadge.js +2 -2
  337. package/lib-esm/CircleOcticon.d.ts +1 -2
  338. package/lib-esm/CounterLabel.d.ts +2 -1
  339. package/lib-esm/CounterLabel.js +2 -2
  340. package/lib-esm/Dialog/Dialog.d.ts +9 -5
  341. package/lib-esm/Dialog/Dialog.js +12 -12
  342. package/lib-esm/Dialog.d.ts +5 -5
  343. package/lib-esm/Dialog.js +2 -2
  344. package/lib-esm/Dropdown.d.ts +99 -14
  345. package/lib-esm/Dropdown.js +4 -4
  346. package/lib-esm/DropdownMenu/DropdownButton.d.ts +47 -4
  347. package/lib-esm/DropdownMenu/DropdownButton.js +1 -3
  348. package/lib-esm/EmojiPicker/EmojiPicker.d.ts +15 -0
  349. package/lib-esm/EmojiPicker/EmojiPicker.js +184 -0
  350. package/lib-esm/EmojiPicker/EmojiPickerAnchor.d.ts +0 -0
  351. package/lib-esm/EmojiPicker/EmojiPickerAnchor.js +0 -0
  352. package/lib-esm/EmojiPicker/EmojiPickerPanel.d.ts +3 -0
  353. package/lib-esm/EmojiPicker/EmojiPickerPanel.js +8 -0
  354. package/lib-esm/EmojiPicker/data.d.ts +9 -0
  355. package/lib-esm/EmojiPicker/data.js +5434 -0
  356. package/lib-esm/EmojiPicker/index.d.ts +2 -0
  357. package/lib-esm/EmojiPicker/index.js +1 -0
  358. package/lib-esm/FilterList.d.ts +303 -265
  359. package/lib-esm/FilterList.js +7 -3
  360. package/lib-esm/FilteredSearch.d.ts +2 -1
  361. package/lib-esm/FilteredSearch.js +2 -2
  362. package/lib-esm/Flash.d.ts +2 -1
  363. package/lib-esm/Flash.js +2 -2
  364. package/lib-esm/FormGroup.d.ts +5 -4
  365. package/lib-esm/FormGroup.js +3 -3
  366. package/lib-esm/Header.d.ts +7 -6
  367. package/lib-esm/Header.js +5 -5
  368. package/lib-esm/Label.d.ts +2 -1
  369. package/lib-esm/Label.js +4 -3
  370. package/lib-esm/LabelGroup.d.ts +2 -1
  371. package/lib-esm/LabelGroup.js +2 -2
  372. package/lib-esm/Link.d.ts +2 -1
  373. package/lib-esm/Link.js +2 -2
  374. package/lib-esm/NewButton/button.js +42 -31
  375. package/lib-esm/Overlay.d.ts +11 -14
  376. package/lib-esm/Overlay.js +3 -2
  377. package/lib-esm/Pagehead.d.ts +2 -1
  378. package/lib-esm/Pagehead.js +2 -2
  379. package/lib-esm/Pagination/Pagination.js +2 -2
  380. package/lib-esm/Popover.d.ts +5 -4
  381. package/lib-esm/Popover.js +5 -4
  382. package/lib-esm/Position.d.ts +4 -4
  383. package/lib-esm/SelectMenu/SelectMenu.d.ts +189 -27
  384. package/lib-esm/SelectMenu/SelectMenu.js +2 -1
  385. package/lib-esm/SelectMenu/SelectMenuDivider.d.ts +2 -1
  386. package/lib-esm/SelectMenu/SelectMenuDivider.js +2 -2
  387. package/lib-esm/SelectMenu/SelectMenuFilter.js +2 -2
  388. package/lib-esm/SelectMenu/SelectMenuFooter.d.ts +2 -1
  389. package/lib-esm/SelectMenu/SelectMenuFooter.js +2 -2
  390. package/lib-esm/SelectMenu/SelectMenuHeader.d.ts +2 -1
  391. package/lib-esm/SelectMenu/SelectMenuHeader.js +2 -2
  392. package/lib-esm/SelectMenu/SelectMenuItem.d.ts +3 -2
  393. package/lib-esm/SelectMenu/SelectMenuItem.js +2 -2
  394. package/lib-esm/SelectMenu/SelectMenuList.d.ts +2 -1
  395. package/lib-esm/SelectMenu/SelectMenuList.js +2 -2
  396. package/lib-esm/SelectMenu/SelectMenuLoadingAnimation.d.ts +2 -2
  397. package/lib-esm/SelectMenu/SelectMenuLoadingAnimation.js +2 -3
  398. package/lib-esm/SelectMenu/SelectMenuModal.d.ts +3 -2
  399. package/lib-esm/SelectMenu/SelectMenuModal.js +2 -2
  400. package/lib-esm/SelectMenu/SelectMenuTab.d.ts +2 -1
  401. package/lib-esm/SelectMenu/SelectMenuTab.js +2 -2
  402. package/lib-esm/SelectMenu/SelectMenuTabPanel.d.ts +2 -1
  403. package/lib-esm/SelectMenu/SelectMenuTabPanel.js +2 -2
  404. package/lib-esm/SelectMenu/SelectMenuTabs.d.ts +2 -1
  405. package/lib-esm/SelectMenu/SelectMenuTabs.js +2 -2
  406. package/lib-esm/SideNav.d.ts +8 -11
  407. package/lib-esm/SideNav.js +16 -8
  408. package/lib-esm/StateLabel.d.ts +2 -1
  409. package/lib-esm/StateLabel.js +6 -7
  410. package/lib-esm/StyledOcticon.d.ts +2 -1
  411. package/lib-esm/StyledOcticon.js +2 -1
  412. package/lib-esm/SubNav.d.ts +11 -5
  413. package/lib-esm/SubNav.js +13 -8
  414. package/lib-esm/TabNav.d.ts +4 -3
  415. package/lib-esm/TabNav.js +3 -3
  416. package/lib-esm/TextInputWithTokens.d.ts +3 -4
  417. package/lib-esm/Timeline.d.ts +393 -19
  418. package/lib-esm/Timeline.js +13 -12
  419. package/lib-esm/Token/AvatarToken.d.ts +1 -1
  420. package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
  421. package/lib-esm/Token/Token.d.ts +1 -1
  422. package/lib-esm/Tooltip.d.ts +2 -1
  423. package/lib-esm/Tooltip.js +2 -2
  424. package/lib-esm/Truncate.d.ts +2 -1
  425. package/lib-esm/Truncate.js +2 -1
  426. package/lib-esm/UnderlineNav.d.ts +3 -2
  427. package/lib-esm/UnderlineNav.js +3 -3
  428. package/lib-esm/index.d.ts +2 -2
  429. package/lib-esm/index.js +1 -1
  430. package/lib-esm/theme-preval.js +366 -512
  431. package/lib-esm/utils/testing.d.ts +61 -8
  432. package/lib-esm/utils/testing.js +0 -24
  433. package/package.json +5 -4
  434. package/lib/Checkbox.d.ts +0 -29
  435. package/lib/Checkbox.js +0 -64
  436. package/lib-esm/Checkbox.d.ts +0 -29
  437. package/lib-esm/Checkbox.js +0 -44
@@ -1,100 +1,90 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.focusZone = focusZone;
7
- exports.hasActiveDescendantAttribute = exports.activeDescendantActivatedIndirectly = exports.activeDescendantActivatedDirectly = exports.isActiveDescendantAttribute = exports.FocusKeys = void 0;
8
-
9
- var _iterateFocusableElements = require("../utils/iterateFocusableElements");
10
-
11
- var _eventListenerSignal = require("../polyfills/eventListenerSignal");
12
-
13
- var _userAgent = require("../utils/userAgent");
14
-
15
- var _uniqueId = require("../utils/uniqueId");
16
-
17
- (0, _eventListenerSignal.polyfill)();
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.focusZone = exports.hasActiveDescendantAttribute = exports.activeDescendantActivatedIndirectly = exports.activeDescendantActivatedDirectly = exports.isActiveDescendantAttribute = exports.FocusKeys = void 0;
4
+ const iterateFocusableElements_1 = require("../utils/iterateFocusableElements");
5
+ const eventListenerSignal_1 = require("../polyfills/eventListenerSignal");
6
+ const userAgent_1 = require("../utils/userAgent");
7
+ const uniqueId_1 = require("../utils/uniqueId");
8
+ eventListenerSignal_1.polyfill();
18
9
  // eslint-disable-next-line no-shadow
19
- let FocusKeys;
20
- exports.FocusKeys = FocusKeys;
21
-
10
+ var FocusKeys;
22
11
  (function (FocusKeys) {
23
- FocusKeys[FocusKeys["ArrowHorizontal"] = 1] = "ArrowHorizontal";
24
- FocusKeys[FocusKeys["ArrowVertical"] = 2] = "ArrowVertical";
25
- FocusKeys[FocusKeys["JK"] = 4] = "JK";
26
- FocusKeys[FocusKeys["HL"] = 8] = "HL";
27
- FocusKeys[FocusKeys["HomeAndEnd"] = 16] = "HomeAndEnd";
28
- FocusKeys[FocusKeys["PageUpDown"] = 256] = "PageUpDown";
29
- FocusKeys[FocusKeys["WS"] = 32] = "WS";
30
- FocusKeys[FocusKeys["AD"] = 64] = "AD";
31
- FocusKeys[FocusKeys["Tab"] = 128] = "Tab";
32
- FocusKeys[FocusKeys["ArrowAll"] = FocusKeys.ArrowHorizontal | FocusKeys.ArrowVertical] = "ArrowAll";
33
- FocusKeys[FocusKeys["HJKL"] = FocusKeys.HL | FocusKeys.JK] = "HJKL";
34
- FocusKeys[FocusKeys["WASD"] = FocusKeys.WS | FocusKeys.AD] = "WASD";
35
- FocusKeys[FocusKeys["All"] = FocusKeys.ArrowAll | FocusKeys.HJKL | FocusKeys.HomeAndEnd | FocusKeys.PageUpDown | FocusKeys.WASD | FocusKeys.Tab] = "All";
36
- })(FocusKeys || (exports.FocusKeys = FocusKeys = {}));
37
-
12
+ // Left and right arrow keys (previous and next, respectively)
13
+ FocusKeys[FocusKeys["ArrowHorizontal"] = 1] = "ArrowHorizontal";
14
+ // Up and down arrow keys (previous and next, respectively)
15
+ FocusKeys[FocusKeys["ArrowVertical"] = 2] = "ArrowVertical";
16
+ // The "J" and "K" keys (next and previous, respectively)
17
+ FocusKeys[FocusKeys["JK"] = 4] = "JK";
18
+ // The "H" and "L" keys (previous and next, respectively)
19
+ FocusKeys[FocusKeys["HL"] = 8] = "HL";
20
+ // The Home and End keys (previous and next, respectively, to end)
21
+ FocusKeys[FocusKeys["HomeAndEnd"] = 16] = "HomeAndEnd";
22
+ // The PgUp and PgDn keys (previous and next, respectively, to end)
23
+ FocusKeys[FocusKeys["PageUpDown"] = 256] = "PageUpDown";
24
+ // The "W" and "S" keys (previous and next, respectively)
25
+ FocusKeys[FocusKeys["WS"] = 32] = "WS";
26
+ // The "A" and "D" keys (previous and next, respectively)
27
+ FocusKeys[FocusKeys["AD"] = 64] = "AD";
28
+ // The Tab key (next)
29
+ FocusKeys[FocusKeys["Tab"] = 128] = "Tab";
30
+ FocusKeys[FocusKeys["ArrowAll"] = 3] = "ArrowAll";
31
+ FocusKeys[FocusKeys["HJKL"] = 12] = "HJKL";
32
+ FocusKeys[FocusKeys["WASD"] = 96] = "WASD";
33
+ FocusKeys[FocusKeys["All"] = 511] = "All";
34
+ })(FocusKeys = exports.FocusKeys || (exports.FocusKeys = {}));
38
35
  const KEY_TO_BIT = {
39
- ArrowLeft: FocusKeys.ArrowHorizontal,
40
- ArrowDown: FocusKeys.ArrowVertical,
41
- ArrowUp: FocusKeys.ArrowVertical,
42
- ArrowRight: FocusKeys.ArrowHorizontal,
43
- h: FocusKeys.HL,
44
- j: FocusKeys.JK,
45
- k: FocusKeys.JK,
46
- l: FocusKeys.HL,
47
- a: FocusKeys.AD,
48
- s: FocusKeys.WS,
49
- w: FocusKeys.WS,
50
- d: FocusKeys.AD,
51
- Tab: FocusKeys.Tab,
52
- Home: FocusKeys.HomeAndEnd,
53
- End: FocusKeys.HomeAndEnd,
54
- PageUp: FocusKeys.PageUpDown,
55
- PageDown: FocusKeys.PageUpDown
36
+ ArrowLeft: FocusKeys.ArrowHorizontal,
37
+ ArrowDown: FocusKeys.ArrowVertical,
38
+ ArrowUp: FocusKeys.ArrowVertical,
39
+ ArrowRight: FocusKeys.ArrowHorizontal,
40
+ h: FocusKeys.HL,
41
+ j: FocusKeys.JK,
42
+ k: FocusKeys.JK,
43
+ l: FocusKeys.HL,
44
+ a: FocusKeys.AD,
45
+ s: FocusKeys.WS,
46
+ w: FocusKeys.WS,
47
+ d: FocusKeys.AD,
48
+ Tab: FocusKeys.Tab,
49
+ Home: FocusKeys.HomeAndEnd,
50
+ End: FocusKeys.HomeAndEnd,
51
+ PageUp: FocusKeys.PageUpDown,
52
+ PageDown: FocusKeys.PageUpDown
56
53
  };
57
54
  const KEY_TO_DIRECTION = {
58
- ArrowLeft: 'previous',
59
- ArrowDown: 'next',
60
- ArrowUp: 'previous',
61
- ArrowRight: 'next',
62
- h: 'previous',
63
- j: 'next',
64
- k: 'previous',
65
- l: 'next',
66
- a: 'previous',
67
- s: 'next',
68
- w: 'previous',
69
- d: 'next',
70
- Tab: 'next',
71
- Home: 'start',
72
- End: 'end',
73
- PageUp: 'start',
74
- PageDown: 'end'
55
+ ArrowLeft: 'previous',
56
+ ArrowDown: 'next',
57
+ ArrowUp: 'previous',
58
+ ArrowRight: 'next',
59
+ h: 'previous',
60
+ j: 'next',
61
+ k: 'previous',
62
+ l: 'next',
63
+ a: 'previous',
64
+ s: 'next',
65
+ w: 'previous',
66
+ d: 'next',
67
+ Tab: 'next',
68
+ Home: 'start',
69
+ End: 'end',
70
+ PageUp: 'start',
71
+ PageDown: 'end'
75
72
  };
76
- /**
77
- * Options that control the behavior of the arrow focus behavior.
78
- */
79
-
80
73
  function getDirection(keyboardEvent) {
81
- const direction = KEY_TO_DIRECTION[keyboardEvent.key];
82
-
83
- if (keyboardEvent.key === 'Tab' && keyboardEvent.shiftKey) {
84
- return 'previous';
85
- }
86
-
87
- const isMac = (0, _userAgent.isMacOS)();
88
-
89
- if (isMac && keyboardEvent.metaKey || !isMac && keyboardEvent.ctrlKey) {
90
- if (keyboardEvent.key === 'ArrowLeft' || keyboardEvent.key === 'ArrowUp') {
91
- return 'start';
92
- } else if (keyboardEvent.key === 'ArrowRight' || keyboardEvent.key === 'ArrowDown') {
93
- return 'end';
74
+ const direction = KEY_TO_DIRECTION[keyboardEvent.key];
75
+ if (keyboardEvent.key === 'Tab' && keyboardEvent.shiftKey) {
76
+ return 'previous';
77
+ }
78
+ const isMac = userAgent_1.isMacOS();
79
+ if ((isMac && keyboardEvent.metaKey) || (!isMac && keyboardEvent.ctrlKey)) {
80
+ if (keyboardEvent.key === 'ArrowLeft' || keyboardEvent.key === 'ArrowUp') {
81
+ return 'start';
82
+ }
83
+ else if (keyboardEvent.key === 'ArrowRight' || keyboardEvent.key === 'ArrowDown') {
84
+ return 'end';
85
+ }
94
86
  }
95
- }
96
-
97
- return direction;
87
+ return direction;
98
88
  }
99
89
  /**
100
90
  * There are some situations where we do not want various keys to affect focus. This function
@@ -109,470 +99,405 @@ function getDirection(keyboardEvent) {
109
99
  * @param keyboardEvent
110
100
  * @param activeElement
111
101
  */
112
-
113
-
114
102
  function shouldIgnoreFocusHandling(keyboardEvent, activeElement) {
115
- const key = keyboardEvent.key; // Get the number of characters in `key`, accounting for double-wide UTF-16 chars. If keyLength
116
- // is 1, we can assume it's a "printable" character. Otherwise it's likely a control character.
117
- // One exception is the Tab key, which is technically printable, but browsers generally assign
118
- // its function to move focus rather than type a <TAB> character.
119
-
120
- const keyLength = [...key].length;
121
- const isTextInput = activeElement instanceof HTMLInputElement && activeElement.type === 'text' || activeElement instanceof HTMLTextAreaElement; // If we would normally type a character into an input, ignore
122
- // Also, Home and End keys should never affect focus when in a text input
123
-
124
- if (isTextInput && (keyLength === 1 || key === 'Home' || key === 'End')) {
125
- return true;
126
- } // Some situations we want to ignore with <select> elements
127
-
128
-
129
- if (activeElement instanceof HTMLSelectElement) {
130
- // Regular typeable characters change the selection, so ignore those
131
- if (keyLength === 1) {
132
- return true;
133
- } // On macOS, bare ArrowDown opens the select, so ignore that
134
-
135
-
136
- if (key === 'ArrowDown' && (0, _userAgent.isMacOS)() && !keyboardEvent.metaKey) {
137
- return true;
138
- } // On other platforms, Alt+ArrowDown opens the select, so ignore that
139
-
140
-
141
- if (key === 'ArrowDown' && !(0, _userAgent.isMacOS)() && keyboardEvent.altKey) {
142
- return true;
103
+ const key = keyboardEvent.key;
104
+ // Get the number of characters in `key`, accounting for double-wide UTF-16 chars. If keyLength
105
+ // is 1, we can assume it's a "printable" character. Otherwise it's likely a control character.
106
+ // One exception is the Tab key, which is technically printable, but browsers generally assign
107
+ // its function to move focus rather than type a <TAB> character.
108
+ const keyLength = [...key].length;
109
+ const isTextInput = (activeElement instanceof HTMLInputElement && activeElement.type === 'text') ||
110
+ activeElement instanceof HTMLTextAreaElement;
111
+ // If we would normally type a character into an input, ignore
112
+ // Also, Home and End keys should never affect focus when in a text input
113
+ if (isTextInput && (keyLength === 1 || key === 'Home' || key === 'End')) {
114
+ return true;
143
115
  }
144
- } // Ignore page up and page down for textareas
145
-
146
-
147
- if (activeElement instanceof HTMLTextAreaElement && (key === 'PageUp' || key === 'PageDown')) {
148
- return true;
149
- }
150
-
151
- if (isTextInput) {
152
- const textInput = activeElement;
153
- const cursorAtStart = textInput.selectionStart === 0 && textInput.selectionEnd === 0;
154
- const cursorAtEnd = textInput.selectionStart === textInput.value.length && textInput.selectionEnd === textInput.value.length; // When in a text area or text input, only move focus left/right if at beginning/end of the field
155
-
156
- if (key === 'ArrowLeft' && !cursorAtStart) {
157
- return true;
116
+ // Some situations we want to ignore with <select> elements
117
+ if (activeElement instanceof HTMLSelectElement) {
118
+ // Regular typeable characters change the selection, so ignore those
119
+ if (keyLength === 1) {
120
+ return true;
121
+ }
122
+ // On macOS, bare ArrowDown opens the select, so ignore that
123
+ if (key === 'ArrowDown' && userAgent_1.isMacOS() && !keyboardEvent.metaKey) {
124
+ return true;
125
+ }
126
+ // On other platforms, Alt+ArrowDown opens the select, so ignore that
127
+ if (key === 'ArrowDown' && !userAgent_1.isMacOS() && keyboardEvent.altKey) {
128
+ return true;
129
+ }
158
130
  }
159
-
160
- if (key === 'ArrowRight' && !cursorAtEnd) {
161
- return true;
162
- } // When in a text area, only move focus up/down if at beginning/end of the field
163
-
164
-
165
- if (textInput instanceof HTMLTextAreaElement) {
166
- if (key === 'ArrowUp' && !cursorAtStart) {
131
+ // Ignore page up and page down for textareas
132
+ if (activeElement instanceof HTMLTextAreaElement && (key === 'PageUp' || key === 'PageDown')) {
167
133
  return true;
168
- }
169
-
170
- if (key === 'ArrowDown' && !cursorAtEnd) {
171
- return true;
172
- }
173
134
  }
174
- }
175
-
176
- return false;
135
+ if (isTextInput) {
136
+ const textInput = activeElement;
137
+ const cursorAtStart = textInput.selectionStart === 0 && textInput.selectionEnd === 0;
138
+ const cursorAtEnd = textInput.selectionStart === textInput.value.length && textInput.selectionEnd === textInput.value.length;
139
+ // When in a text area or text input, only move focus left/right if at beginning/end of the field
140
+ if (key === 'ArrowLeft' && !cursorAtStart) {
141
+ return true;
142
+ }
143
+ if (key === 'ArrowRight' && !cursorAtEnd) {
144
+ return true;
145
+ }
146
+ // When in a text area, only move focus up/down if at beginning/end of the field
147
+ if (textInput instanceof HTMLTextAreaElement) {
148
+ if (key === 'ArrowUp' && !cursorAtStart) {
149
+ return true;
150
+ }
151
+ if (key === 'ArrowDown' && !cursorAtEnd) {
152
+ return true;
153
+ }
154
+ }
155
+ }
156
+ return false;
177
157
  }
178
-
179
- const isActiveDescendantAttribute = 'data-is-active-descendant';
158
+ exports.isActiveDescendantAttribute = 'data-is-active-descendant';
180
159
  /**
181
160
  * A value of activated-directly for data-is-active-descendant indicates the descendant was activated
182
161
  * by a manual user interaction with intent to move active descendant. This usually translates to the
183
162
  * user pressing one of the bound keys (up/down arrow, etc) to move through the focus zone. This is
184
163
  * intended to be roughly equivalent to the :focus-visible pseudo-class
185
164
  **/
186
-
187
- exports.isActiveDescendantAttribute = isActiveDescendantAttribute;
188
- const activeDescendantActivatedDirectly = 'activated-directly';
165
+ exports.activeDescendantActivatedDirectly = 'activated-directly';
189
166
  /**
190
167
  * A value of activated-indirectly for data-is-active-descendant indicates the descendant was activated
191
168
  * implicitly, and not by a direct key press. This includes focus zone being created from scratch, focusable
192
169
  * elements being added/removed, and mouseover events. This is intended to be roughly equivalent
193
170
  * to :focus:not(:focus-visible)
194
171
  **/
195
-
196
- exports.activeDescendantActivatedDirectly = activeDescendantActivatedDirectly;
197
- const activeDescendantActivatedIndirectly = 'activated-indirectly';
198
- exports.activeDescendantActivatedIndirectly = activeDescendantActivatedIndirectly;
199
- const hasActiveDescendantAttribute = 'data-has-active-descendant';
172
+ exports.activeDescendantActivatedIndirectly = 'activated-indirectly';
173
+ exports.hasActiveDescendantAttribute = 'data-has-active-descendant';
200
174
  /**
201
175
  * Sets up the arrow key focus behavior for all focusable elements in the given `container`.
202
176
  * @param container
203
177
  * @param settings
204
178
  * @returns
205
179
  */
206
-
207
- exports.hasActiveDescendantAttribute = hasActiveDescendantAttribute;
208
-
209
180
  function focusZone(container, settings) {
210
- var _settings$bindKeys, _settings$focusOutBeh, _settings$focusInStra, _settings$abortSignal;
211
-
212
- const focusableElements = [];
213
- const savedTabIndex = new WeakMap();
214
- const bindKeys = (_settings$bindKeys = settings === null || settings === void 0 ? void 0 : settings.bindKeys) !== null && _settings$bindKeys !== void 0 ? _settings$bindKeys : (settings !== null && settings !== void 0 && settings.getNextFocusable ? FocusKeys.ArrowAll : FocusKeys.ArrowVertical) | FocusKeys.HomeAndEnd;
215
- const focusOutBehavior = (_settings$focusOutBeh = settings === null || settings === void 0 ? void 0 : settings.focusOutBehavior) !== null && _settings$focusOutBeh !== void 0 ? _settings$focusOutBeh : 'stop';
216
- const focusInStrategy = (_settings$focusInStra = settings === null || settings === void 0 ? void 0 : settings.focusInStrategy) !== null && _settings$focusInStra !== void 0 ? _settings$focusInStra : 'previous';
217
- const activeDescendantControl = settings === null || settings === void 0 ? void 0 : settings.activeDescendantControl;
218
- const activeDescendantCallback = settings === null || settings === void 0 ? void 0 : settings.onActiveDescendantChanged;
219
- let currentFocusedElement;
220
-
221
- function getFirstFocusableElement() {
222
- return focusableElements[0];
223
- }
224
-
225
- function isActiveDescendantInputFocused() {
226
- return document.activeElement === activeDescendantControl;
227
- }
228
-
229
- function updateFocusedElement(to, directlyActivated = false) {
230
- const from = currentFocusedElement;
231
- currentFocusedElement = to;
232
-
233
- if (activeDescendantControl) {
234
- if (to && isActiveDescendantInputFocused()) {
235
- setActiveDescendant(from, to, directlyActivated);
236
- } else {
237
- clearActiveDescendant();
238
- }
239
-
240
- return;
241
- }
242
-
243
- if (from && from !== to && savedTabIndex.has(from)) {
244
- from.setAttribute('tabindex', '-1');
181
+ const focusableElements = [];
182
+ const savedTabIndex = new WeakMap();
183
+ const bindKeys = settings?.bindKeys ??
184
+ (settings?.getNextFocusable ? FocusKeys.ArrowAll : FocusKeys.ArrowVertical) | FocusKeys.HomeAndEnd;
185
+ const focusOutBehavior = settings?.focusOutBehavior ?? 'stop';
186
+ const focusInStrategy = settings?.focusInStrategy ?? 'previous';
187
+ const activeDescendantControl = settings?.activeDescendantControl;
188
+ const activeDescendantCallback = settings?.onActiveDescendantChanged;
189
+ let currentFocusedElement;
190
+ function getFirstFocusableElement() {
191
+ return focusableElements[0];
245
192
  }
246
-
247
- to === null || to === void 0 ? void 0 : to.setAttribute('tabindex', '0');
248
- }
249
-
250
- function setActiveDescendant(from, to, directlyActivated = false) {
251
- if (!to.id) {
252
- to.setAttribute('id', (0, _uniqueId.uniqueId)());
193
+ function isActiveDescendantInputFocused() {
194
+ return document.activeElement === activeDescendantControl;
253
195
  }
254
-
255
- if (from && from !== to) {
256
- from.removeAttribute(isActiveDescendantAttribute);
257
- }
258
-
259
- if (!activeDescendantControl || !directlyActivated && activeDescendantControl.getAttribute('aria-activedescendant') === to.id) {
260
- // prevent active descendant callback from being called repeatedly if the same element is activated (e.g. via mousemove)
261
- return;
262
- }
263
-
264
- activeDescendantControl.setAttribute('aria-activedescendant', to.id);
265
- container.setAttribute(hasActiveDescendantAttribute, to.id);
266
- to.setAttribute(isActiveDescendantAttribute, directlyActivated ? activeDescendantActivatedDirectly : activeDescendantActivatedIndirectly);
267
- activeDescendantCallback === null || activeDescendantCallback === void 0 ? void 0 : activeDescendantCallback(to, from, directlyActivated);
268
- }
269
-
270
- function clearActiveDescendant(previouslyActiveElement = currentFocusedElement) {
271
- if (focusInStrategy === 'first') {
272
- currentFocusedElement = undefined;
273
- }
274
-
275
- activeDescendantControl === null || activeDescendantControl === void 0 ? void 0 : activeDescendantControl.removeAttribute('aria-activedescendant');
276
- container.removeAttribute(hasActiveDescendantAttribute);
277
- previouslyActiveElement === null || previouslyActiveElement === void 0 ? void 0 : previouslyActiveElement.removeAttribute(isActiveDescendantAttribute);
278
- activeDescendantCallback === null || activeDescendantCallback === void 0 ? void 0 : activeDescendantCallback(undefined, previouslyActiveElement, false);
279
- }
280
-
281
- function beginFocusManagement(...elements) {
282
- const filteredElements = elements.filter(e => {
283
- var _settings$focusableEl, _settings$focusableEl2;
284
-
285
- return (_settings$focusableEl = settings === null || settings === void 0 ? void 0 : (_settings$focusableEl2 = settings.focusableElementFilter) === null || _settings$focusableEl2 === void 0 ? void 0 : _settings$focusableEl2.call(settings, e)) !== null && _settings$focusableEl !== void 0 ? _settings$focusableEl : true;
286
- });
287
-
288
- if (filteredElements.length === 0) {
289
- return;
290
- } // Insert all elements atomically. Assume that all passed elements are well-ordered.
291
-
292
-
293
- const insertIndex = focusableElements.findIndex(e => (e.compareDocumentPosition(filteredElements[0]) & Node.DOCUMENT_POSITION_PRECEDING) > 0);
294
- focusableElements.splice(insertIndex === -1 ? focusableElements.length : insertIndex, 0, ...filteredElements);
295
-
296
- for (const element of filteredElements) {
297
- // Set tabindex="-1" on all tabbable elements, but save the original
298
- // value in case we need to disable the behavior
299
- if (!savedTabIndex.has(element)) {
300
- savedTabIndex.set(element, element.getAttribute('tabindex'));
301
- }
302
-
303
- element.setAttribute('tabindex', '-1');
304
- }
305
-
306
- if (!currentFocusedElement) {
307
- updateFocusedElement(getFirstFocusableElement());
196
+ function updateFocusedElement(to, directlyActivated = false) {
197
+ const from = currentFocusedElement;
198
+ currentFocusedElement = to;
199
+ if (activeDescendantControl) {
200
+ if (to && isActiveDescendantInputFocused()) {
201
+ setActiveDescendant(from, to, directlyActivated);
202
+ }
203
+ else {
204
+ clearActiveDescendant();
205
+ }
206
+ return;
207
+ }
208
+ if (from && from !== to && savedTabIndex.has(from)) {
209
+ from.setAttribute('tabindex', '-1');
210
+ }
211
+ to?.setAttribute('tabindex', '0');
308
212
  }
309
- }
310
-
311
- function endFocusManagement(...elements) {
312
- for (const element of elements) {
313
- const focusableElementIndex = focusableElements.indexOf(element);
314
-
315
- if (focusableElementIndex >= 0) {
316
- focusableElements.splice(focusableElementIndex, 1);
317
- }
318
-
319
- const savedIndex = savedTabIndex.get(element);
320
-
321
- if (savedIndex !== undefined) {
322
- if (savedIndex === null) {
323
- element.removeAttribute('tabindex');
324
- } else {
325
- element.setAttribute('tabindex', savedIndex);
213
+ function setActiveDescendant(from, to, directlyActivated = false) {
214
+ if (!to.id) {
215
+ to.setAttribute('id', uniqueId_1.uniqueId());
216
+ }
217
+ if (from && from !== to) {
218
+ from.removeAttribute(exports.isActiveDescendantAttribute);
326
219
  }
327
-
328
- savedTabIndex.delete(element);
329
- } // If removing the last-focused element, move focus to the first element in the list.
330
-
331
-
332
- if (element === currentFocusedElement) {
333
- const nextElementToFocus = getFirstFocusableElement();
334
- updateFocusedElement(nextElementToFocus);
335
- }
220
+ if (!activeDescendantControl ||
221
+ (!directlyActivated && activeDescendantControl.getAttribute('aria-activedescendant') === to.id)) {
222
+ // prevent active descendant callback from being called repeatedly if the same element is activated (e.g. via mousemove)
223
+ return;
224
+ }
225
+ activeDescendantControl.setAttribute('aria-activedescendant', to.id);
226
+ container.setAttribute(exports.hasActiveDescendantAttribute, to.id);
227
+ to.setAttribute(exports.isActiveDescendantAttribute, directlyActivated ? exports.activeDescendantActivatedDirectly : exports.activeDescendantActivatedIndirectly);
228
+ activeDescendantCallback?.(to, from, directlyActivated);
336
229
  }
337
- } // Take all tabbable elements within container under management
338
-
339
-
340
- beginFocusManagement(...(0, _iterateFocusableElements.iterateFocusableElements)(container)); // Open the first tabbable element for tabbing
341
-
342
- updateFocusedElement(getFirstFocusableElement()); // If the DOM structure of the container changes, make sure we keep our state up-to-date
343
- // with respect to the focusable elements cache and its order
344
-
345
- const observer = new MutationObserver(mutations => {
346
- // Perform all removals first, in case element order has simply changed
347
- for (const mutation of mutations) {
348
- for (const removedNode of mutation.removedNodes) {
349
- if (removedNode instanceof HTMLElement) {
350
- endFocusManagement(...(0, _iterateFocusableElements.iterateFocusableElements)(removedNode));
230
+ function clearActiveDescendant(previouslyActiveElement = currentFocusedElement) {
231
+ if (focusInStrategy === 'first') {
232
+ currentFocusedElement = undefined;
351
233
  }
352
- }
234
+ activeDescendantControl?.removeAttribute('aria-activedescendant');
235
+ container.removeAttribute(exports.hasActiveDescendantAttribute);
236
+ previouslyActiveElement?.removeAttribute(exports.isActiveDescendantAttribute);
237
+ activeDescendantCallback?.(undefined, previouslyActiveElement, false);
353
238
  }
354
-
355
- for (const mutation of mutations) {
356
- for (const addedNode of mutation.addedNodes) {
357
- if (addedNode instanceof HTMLElement) {
358
- beginFocusManagement(...(0, _iterateFocusableElements.iterateFocusableElements)(addedNode));
239
+ function beginFocusManagement(...elements) {
240
+ const filteredElements = elements.filter(e => settings?.focusableElementFilter?.(e) ?? true);
241
+ if (filteredElements.length === 0) {
242
+ return;
243
+ }
244
+ // Insert all elements atomically. Assume that all passed elements are well-ordered.
245
+ const insertIndex = focusableElements.findIndex(e => (e.compareDocumentPosition(filteredElements[0]) & Node.DOCUMENT_POSITION_PRECEDING) > 0);
246
+ focusableElements.splice(insertIndex === -1 ? focusableElements.length : insertIndex, 0, ...filteredElements);
247
+ for (const element of filteredElements) {
248
+ // Set tabindex="-1" on all tabbable elements, but save the original
249
+ // value in case we need to disable the behavior
250
+ if (!savedTabIndex.has(element)) {
251
+ savedTabIndex.set(element, element.getAttribute('tabindex'));
252
+ }
253
+ element.setAttribute('tabindex', '-1');
254
+ }
255
+ if (!currentFocusedElement) {
256
+ updateFocusedElement(getFirstFocusableElement());
359
257
  }
360
- }
361
258
  }
362
- });
363
- observer.observe(container, {
364
- subtree: true,
365
- childList: true
366
- });
367
- const controller = new AbortController();
368
- const signal = (_settings$abortSignal = settings === null || settings === void 0 ? void 0 : settings.abortSignal) !== null && _settings$abortSignal !== void 0 ? _settings$abortSignal : controller.signal;
369
- signal.addEventListener('abort', () => {
370
- // Clean up any modifications
371
- endFocusManagement(...focusableElements);
372
- });
373
- let elementIndexFocusedByClick = undefined;
374
- container.addEventListener('mousedown', event => {
375
- // Since focusin is only called when focus changes, we need to make sure the clicked
376
- // element isn't already focused.
377
- if (event.target instanceof HTMLElement && event.target !== document.activeElement) {
378
- elementIndexFocusedByClick = focusableElements.indexOf(event.target);
259
+ function endFocusManagement(...elements) {
260
+ for (const element of elements) {
261
+ const focusableElementIndex = focusableElements.indexOf(element);
262
+ if (focusableElementIndex >= 0) {
263
+ focusableElements.splice(focusableElementIndex, 1);
264
+ }
265
+ const savedIndex = savedTabIndex.get(element);
266
+ if (savedIndex !== undefined) {
267
+ if (savedIndex === null) {
268
+ element.removeAttribute('tabindex');
269
+ }
270
+ else {
271
+ element.setAttribute('tabindex', savedIndex);
272
+ }
273
+ savedTabIndex.delete(element);
274
+ }
275
+ // If removing the last-focused element, move focus to the first element in the list.
276
+ if (element === currentFocusedElement) {
277
+ const nextElementToFocus = getFirstFocusableElement();
278
+ updateFocusedElement(nextElementToFocus);
279
+ }
280
+ }
379
281
  }
380
- }, {
381
- signal
382
- });
383
-
384
- if (activeDescendantControl) {
385
- container.addEventListener('focusin', event => {
386
- if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
387
- // Move focus to the activeDescendantControl if one of the descendants is focused
388
- activeDescendantControl.focus();
389
- updateFocusedElement(event.target);
390
- }
282
+ // Take all tabbable elements within container under management
283
+ beginFocusManagement(...iterateFocusableElements_1.iterateFocusableElements(container));
284
+ // Open the first tabbable element for tabbing
285
+ updateFocusedElement(getFirstFocusableElement());
286
+ // If the DOM structure of the container changes, make sure we keep our state up-to-date
287
+ // with respect to the focusable elements cache and its order
288
+ const observer = new MutationObserver(mutations => {
289
+ // Perform all removals first, in case element order has simply changed
290
+ for (const mutation of mutations) {
291
+ for (const removedNode of mutation.removedNodes) {
292
+ if (removedNode instanceof HTMLElement) {
293
+ endFocusManagement(...iterateFocusableElements_1.iterateFocusableElements(removedNode));
294
+ }
295
+ }
296
+ }
297
+ for (const mutation of mutations) {
298
+ for (const addedNode of mutation.addedNodes) {
299
+ if (addedNode instanceof HTMLElement) {
300
+ beginFocusManagement(...iterateFocusableElements_1.iterateFocusableElements(addedNode));
301
+ }
302
+ }
303
+ }
391
304
  });
392
- container.addEventListener('mousemove', ({
393
- target
394
- }) => {
395
- if (!(target instanceof Node)) {
396
- return;
397
- }
398
-
399
- const focusableElement = focusableElements.find(element => element.contains(target));
400
-
401
- if (focusableElement) {
402
- updateFocusedElement(focusableElement);
403
- }
404
- }, {
405
- signal,
406
- capture: true
407
- }); // Listeners specifically on the controlling element
408
-
409
- activeDescendantControl.addEventListener('focusin', () => {
410
- // Focus moved into the active descendant input. Activate current or first descendant.
411
- if (!currentFocusedElement) {
412
- updateFocusedElement(getFirstFocusableElement());
413
- } else {
414
- setActiveDescendant(undefined, currentFocusedElement);
415
- }
305
+ observer.observe(container, {
306
+ subtree: true,
307
+ childList: true
416
308
  });
417
- activeDescendantControl.addEventListener('focusout', () => {
418
- clearActiveDescendant();
309
+ const controller = new AbortController();
310
+ const signal = settings?.abortSignal ?? controller.signal;
311
+ signal.addEventListener('abort', () => {
312
+ // Clean up any modifications
313
+ endFocusManagement(...focusableElements);
419
314
  });
420
- } else {
421
- // This is called whenever focus enters an element in the container
422
- container.addEventListener('focusin', event => {
423
- if (event.target instanceof HTMLElement) {
424
- // If a click initiated the focus movement, we always want to set our internal state
425
- // to reflect the clicked element as the currently focused one.
426
- if (elementIndexFocusedByClick !== undefined) {
427
- if (elementIndexFocusedByClick >= 0) {
428
- if (focusableElements[elementIndexFocusedByClick] !== currentFocusedElement) {
429
- updateFocusedElement(focusableElements[elementIndexFocusedByClick]);
430
- }
431
- }
432
-
433
- elementIndexFocusedByClick = undefined;
434
- } else {
435
- // Set tab indexes and internal state based on the focus handling strategy
436
- if (focusInStrategy === 'previous') {
437
- updateFocusedElement(event.target);
438
- } else if (focusInStrategy === 'closest' || focusInStrategy === 'first') {
439
- if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
440
- // Regardless of the previously focused element, if we're coming from outside the
441
- // container, put focus onto the first encountered element (from above, it's The
442
- // first element of the container; from below, it's the last). If the
443
- // focusInStrategy is set to "first", lastKeyboardFocusDirection will always
444
- // be undefined.
445
- const targetElementIndex = lastKeyboardFocusDirection === 'previous' ? focusableElements.length - 1 : 0;
446
- const targetElement = focusableElements[targetElementIndex];
447
- targetElement === null || targetElement === void 0 ? void 0 : targetElement.focus();
448
- return;
449
- } else {
450
- updateFocusedElement(event.target);
315
+ let elementIndexFocusedByClick = undefined;
316
+ container.addEventListener('mousedown', event => {
317
+ // Since focusin is only called when focus changes, we need to make sure the clicked
318
+ // element isn't already focused.
319
+ if (event.target instanceof HTMLElement && event.target !== document.activeElement) {
320
+ elementIndexFocusedByClick = focusableElements.indexOf(event.target);
321
+ }
322
+ }, { signal });
323
+ if (activeDescendantControl) {
324
+ container.addEventListener('focusin', event => {
325
+ if (event.target instanceof HTMLElement && focusableElements.includes(event.target)) {
326
+ // Move focus to the activeDescendantControl if one of the descendants is focused
327
+ activeDescendantControl.focus();
328
+ updateFocusedElement(event.target);
451
329
  }
452
- } else if (typeof focusInStrategy === 'function') {
453
- if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
454
- const elementToFocus = focusInStrategy(event.relatedTarget);
455
- const requestedFocusElementIndex = elementToFocus ? focusableElements.indexOf(elementToFocus) : -1;
456
-
457
- if (requestedFocusElementIndex >= 0 && elementToFocus instanceof HTMLElement) {
458
- // Since we are calling focus() this handler will run again synchronously. Therefore,
459
- // we don't want to let this invocation finish since it will clobber the value of
460
- // currentFocusedElement.
461
- elementToFocus.focus();
330
+ });
331
+ container.addEventListener('mousemove', ({ target }) => {
332
+ if (!(target instanceof Node)) {
462
333
  return;
463
- } else {
464
- // eslint-disable-next-line no-console
465
- console.warn('Element requested is not a known focusable element.');
466
- }
467
- } else {
468
- updateFocusedElement(event.target);
469
334
  }
470
- }
471
- }
472
- }
473
-
474
- lastKeyboardFocusDirection = undefined;
475
- }, {
476
- signal
477
- });
478
- }
479
-
480
- const keyboardEventRecipient = activeDescendantControl !== null && activeDescendantControl !== void 0 ? activeDescendantControl : container; // If the strategy is "closest", we need to capture the direction that the user
481
- // is trying to move focus before our focusin handler is executed.
482
-
483
- let lastKeyboardFocusDirection = undefined;
484
-
485
- if (focusInStrategy === 'closest') {
486
- document.addEventListener('keydown', event => {
487
- if (event.key === 'Tab') {
488
- lastKeyboardFocusDirection = getDirection(event);
489
- }
490
- }, {
491
- signal,
492
- capture: true
493
- });
494
- }
495
-
496
- function getCurrentFocusedIndex() {
497
- if (!currentFocusedElement) {
498
- return 0;
335
+ const focusableElement = focusableElements.find(element => element.contains(target));
336
+ if (focusableElement) {
337
+ updateFocusedElement(focusableElement);
338
+ }
339
+ }, { signal, capture: true });
340
+ // Listeners specifically on the controlling element
341
+ activeDescendantControl.addEventListener('focusin', () => {
342
+ // Focus moved into the active descendant input. Activate current or first descendant.
343
+ if (!currentFocusedElement) {
344
+ updateFocusedElement(getFirstFocusableElement());
345
+ }
346
+ else {
347
+ setActiveDescendant(undefined, currentFocusedElement);
348
+ }
349
+ });
350
+ activeDescendantControl.addEventListener('focusout', () => {
351
+ clearActiveDescendant();
352
+ });
499
353
  }
500
-
501
- const focusedIndex = focusableElements.indexOf(currentFocusedElement);
502
- const fallbackIndex = currentFocusedElement === container ? -1 : 0;
503
- return focusedIndex !== -1 ? focusedIndex : fallbackIndex;
504
- } // "keydown" is the event that triggers DOM focus change, so that is what we use here
505
-
506
-
507
- keyboardEventRecipient.addEventListener('keydown', event => {
508
- if (event.key in KEY_TO_DIRECTION) {
509
- const keyBit = KEY_TO_BIT[event.key]; // Check if the pressed key (keyBit) is one that is being used for focus (bindKeys)
510
-
511
- if (!event.defaultPrevented && (keyBit & bindKeys) > 0 && !shouldIgnoreFocusHandling(event, document.activeElement)) {
512
- // Moving forward or backward?
513
- const direction = getDirection(event);
514
- let nextElementToFocus = undefined; // If there is a custom function that retrieves the next focusable element, try calling that first.
515
-
516
- if (settings !== null && settings !== void 0 && settings.getNextFocusable) {
517
- var _document$activeEleme;
518
-
519
- nextElementToFocus = settings.getNextFocusable(direction, (_document$activeEleme = document.activeElement) !== null && _document$activeEleme !== void 0 ? _document$activeEleme : undefined, event);
520
- }
521
-
522
- if (!nextElementToFocus) {
523
- const lastFocusedIndex = getCurrentFocusedIndex();
524
- let nextFocusedIndex = lastFocusedIndex;
525
-
526
- if (direction === 'previous') {
527
- nextFocusedIndex -= 1;
528
- } else if (direction === 'start') {
529
- nextFocusedIndex = 0;
530
- } else if (direction === 'next') {
531
- nextFocusedIndex += 1;
532
- } else {
533
- // end
534
- nextFocusedIndex = focusableElements.length - 1;
535
- }
536
-
537
- if (nextFocusedIndex < 0) {
538
- // Tab should never cause focus to wrap. Use focusTrap for that behavior.
539
- if (focusOutBehavior === 'wrap' && event.key !== 'Tab') {
540
- nextFocusedIndex = focusableElements.length - 1;
541
- } else {
542
- nextFocusedIndex = 0;
354
+ else {
355
+ // This is called whenever focus enters an element in the container
356
+ container.addEventListener('focusin', event => {
357
+ if (event.target instanceof HTMLElement) {
358
+ // If a click initiated the focus movement, we always want to set our internal state
359
+ // to reflect the clicked element as the currently focused one.
360
+ if (elementIndexFocusedByClick !== undefined) {
361
+ if (elementIndexFocusedByClick >= 0) {
362
+ if (focusableElements[elementIndexFocusedByClick] !== currentFocusedElement) {
363
+ updateFocusedElement(focusableElements[elementIndexFocusedByClick]);
364
+ }
365
+ }
366
+ elementIndexFocusedByClick = undefined;
367
+ }
368
+ else {
369
+ // Set tab indexes and internal state based on the focus handling strategy
370
+ if (focusInStrategy === 'previous') {
371
+ updateFocusedElement(event.target);
372
+ }
373
+ else if (focusInStrategy === 'closest' || focusInStrategy === 'first') {
374
+ if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
375
+ // Regardless of the previously focused element, if we're coming from outside the
376
+ // container, put focus onto the first encountered element (from above, it's The
377
+ // first element of the container; from below, it's the last). If the
378
+ // focusInStrategy is set to "first", lastKeyboardFocusDirection will always
379
+ // be undefined.
380
+ const targetElementIndex = lastKeyboardFocusDirection === 'previous' ? focusableElements.length - 1 : 0;
381
+ const targetElement = focusableElements[targetElementIndex];
382
+ targetElement?.focus();
383
+ return;
384
+ }
385
+ else {
386
+ updateFocusedElement(event.target);
387
+ }
388
+ }
389
+ else if (typeof focusInStrategy === 'function') {
390
+ if (event.relatedTarget instanceof Element && !container.contains(event.relatedTarget)) {
391
+ const elementToFocus = focusInStrategy(event.relatedTarget);
392
+ const requestedFocusElementIndex = elementToFocus ? focusableElements.indexOf(elementToFocus) : -1;
393
+ if (requestedFocusElementIndex >= 0 && elementToFocus instanceof HTMLElement) {
394
+ // Since we are calling focus() this handler will run again synchronously. Therefore,
395
+ // we don't want to let this invocation finish since it will clobber the value of
396
+ // currentFocusedElement.
397
+ elementToFocus.focus();
398
+ return;
399
+ }
400
+ else {
401
+ // eslint-disable-next-line no-console
402
+ console.warn('Element requested is not a known focusable element.');
403
+ }
404
+ }
405
+ else {
406
+ updateFocusedElement(event.target);
407
+ }
408
+ }
409
+ }
543
410
  }
544
- }
545
-
546
- if (nextFocusedIndex >= focusableElements.length) {
547
- if (focusOutBehavior === 'wrap' && event.key !== 'Tab') {
548
- nextFocusedIndex = 0;
549
- } else {
550
- nextFocusedIndex = focusableElements.length - 1;
411
+ lastKeyboardFocusDirection = undefined;
412
+ }, { signal });
413
+ }
414
+ const keyboardEventRecipient = activeDescendantControl ?? container;
415
+ // If the strategy is "closest", we need to capture the direction that the user
416
+ // is trying to move focus before our focusin handler is executed.
417
+ let lastKeyboardFocusDirection = undefined;
418
+ if (focusInStrategy === 'closest') {
419
+ document.addEventListener('keydown', event => {
420
+ if (event.key === 'Tab') {
421
+ lastKeyboardFocusDirection = getDirection(event);
551
422
  }
552
- }
553
-
554
- if (lastFocusedIndex !== nextFocusedIndex) {
555
- nextElementToFocus = focusableElements[nextFocusedIndex];
556
- }
557
- }
558
-
559
- if (activeDescendantControl) {
560
- updateFocusedElement(nextElementToFocus || currentFocusedElement, true);
561
- } else if (nextElementToFocus) {
562
- lastKeyboardFocusDirection = direction; // updateFocusedElement will be called implicitly when focus moves, as long as the event isn't prevented somehow
563
-
564
- nextElementToFocus.focus();
565
- } // Tab should always allow escaping from this container, so only
566
- // preventDefault if tab key press already resulted in a focus movement
567
-
568
-
569
- if (event.key !== 'Tab' || nextElementToFocus) {
570
- event.preventDefault();
423
+ }, { signal, capture: true });
424
+ }
425
+ function getCurrentFocusedIndex() {
426
+ if (!currentFocusedElement) {
427
+ return 0;
571
428
  }
572
- }
429
+ const focusedIndex = focusableElements.indexOf(currentFocusedElement);
430
+ const fallbackIndex = currentFocusedElement === container ? -1 : 0;
431
+ return focusedIndex !== -1 ? focusedIndex : fallbackIndex;
573
432
  }
574
- }, {
575
- signal
576
- });
577
- return controller;
578
- }
433
+ // "keydown" is the event that triggers DOM focus change, so that is what we use here
434
+ keyboardEventRecipient.addEventListener('keydown', event => {
435
+ if (event.key in KEY_TO_DIRECTION) {
436
+ const keyBit = KEY_TO_BIT[event.key];
437
+ // Check if the pressed key (keyBit) is one that is being used for focus (bindKeys)
438
+ if (!event.defaultPrevented &&
439
+ (keyBit & bindKeys) > 0 &&
440
+ !shouldIgnoreFocusHandling(event, document.activeElement)) {
441
+ // Moving forward or backward?
442
+ const direction = getDirection(event);
443
+ let nextElementToFocus = undefined;
444
+ // If there is a custom function that retrieves the next focusable element, try calling that first.
445
+ if (settings?.getNextFocusable) {
446
+ nextElementToFocus = settings.getNextFocusable(direction, document.activeElement ?? undefined, event);
447
+ }
448
+ if (!nextElementToFocus) {
449
+ const lastFocusedIndex = getCurrentFocusedIndex();
450
+ let nextFocusedIndex = lastFocusedIndex;
451
+ if (direction === 'previous') {
452
+ nextFocusedIndex -= 1;
453
+ }
454
+ else if (direction === 'start') {
455
+ nextFocusedIndex = 0;
456
+ }
457
+ else if (direction === 'next') {
458
+ nextFocusedIndex += 1;
459
+ }
460
+ else {
461
+ // end
462
+ nextFocusedIndex = focusableElements.length - 1;
463
+ }
464
+ if (nextFocusedIndex < 0) {
465
+ // Tab should never cause focus to wrap. Use focusTrap for that behavior.
466
+ if (focusOutBehavior === 'wrap' && event.key !== 'Tab') {
467
+ nextFocusedIndex = focusableElements.length - 1;
468
+ }
469
+ else {
470
+ nextFocusedIndex = 0;
471
+ }
472
+ }
473
+ if (nextFocusedIndex >= focusableElements.length) {
474
+ if (focusOutBehavior === 'wrap' && event.key !== 'Tab') {
475
+ nextFocusedIndex = 0;
476
+ }
477
+ else {
478
+ nextFocusedIndex = focusableElements.length - 1;
479
+ }
480
+ }
481
+ if (lastFocusedIndex !== nextFocusedIndex) {
482
+ nextElementToFocus = focusableElements[nextFocusedIndex];
483
+ }
484
+ }
485
+ if (activeDescendantControl) {
486
+ updateFocusedElement(nextElementToFocus || currentFocusedElement, true);
487
+ }
488
+ else if (nextElementToFocus) {
489
+ lastKeyboardFocusDirection = direction;
490
+ // updateFocusedElement will be called implicitly when focus moves, as long as the event isn't prevented somehow
491
+ nextElementToFocus.focus();
492
+ }
493
+ // Tab should always allow escaping from this container, so only
494
+ // preventDefault if tab key press already resulted in a focus movement
495
+ if (event.key !== 'Tab' || nextElementToFocus) {
496
+ event.preventDefault();
497
+ }
498
+ }
499
+ }
500
+ }, { signal });
501
+ return controller;
502
+ }
503
+ exports.focusZone = focusZone;