react-aria 3.49.0 → 3.50.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 (244) hide show
  1. package/dist/private/autocomplete/useAutocomplete.cjs +16 -7
  2. package/dist/private/autocomplete/useAutocomplete.cjs.map +1 -1
  3. package/dist/private/autocomplete/useAutocomplete.js +16 -7
  4. package/dist/private/autocomplete/useAutocomplete.js.map +1 -1
  5. package/dist/private/autocomplete/useAutocomplete.mjs +16 -7
  6. package/dist/private/autocomplete/useAutocomplete.mjs.map +1 -1
  7. package/dist/private/breadcrumbs/useBreadcrumbs.cjs.map +1 -1
  8. package/dist/private/breadcrumbs/useBreadcrumbs.js.map +1 -1
  9. package/dist/private/breadcrumbs/useBreadcrumbs.mjs.map +1 -1
  10. package/dist/private/calendar/useCalendarBase.cjs.map +1 -1
  11. package/dist/private/calendar/useCalendarBase.js.map +1 -1
  12. package/dist/private/calendar/useCalendarBase.mjs.map +1 -1
  13. package/dist/private/calendar/useCalendarCell.cjs.map +1 -1
  14. package/dist/private/calendar/useCalendarCell.js.map +1 -1
  15. package/dist/private/calendar/useCalendarCell.mjs.map +1 -1
  16. package/dist/private/calendar/useCalendarYearPicker.cjs +4 -4
  17. package/dist/private/calendar/useCalendarYearPicker.cjs.map +1 -1
  18. package/dist/private/calendar/useCalendarYearPicker.js +4 -4
  19. package/dist/private/calendar/useCalendarYearPicker.js.map +1 -1
  20. package/dist/private/calendar/useCalendarYearPicker.mjs +4 -4
  21. package/dist/private/calendar/useCalendarYearPicker.mjs.map +1 -1
  22. package/dist/private/calendar/utils.cjs.map +1 -1
  23. package/dist/private/calendar/utils.js.map +1 -1
  24. package/dist/private/calendar/utils.mjs.map +1 -1
  25. package/dist/private/color/useColorArea.cjs.map +1 -1
  26. package/dist/private/color/useColorArea.js.map +1 -1
  27. package/dist/private/color/useColorArea.mjs.map +1 -1
  28. package/dist/private/color/useColorSwatch.cjs.map +1 -1
  29. package/dist/private/color/useColorSwatch.js.map +1 -1
  30. package/dist/private/color/useColorSwatch.mjs.map +1 -1
  31. package/dist/private/combobox/useComboBox.cjs +2 -0
  32. package/dist/private/combobox/useComboBox.cjs.map +1 -1
  33. package/dist/private/combobox/useComboBox.js +2 -0
  34. package/dist/private/combobox/useComboBox.js.map +1 -1
  35. package/dist/private/combobox/useComboBox.mjs +2 -0
  36. package/dist/private/combobox/useComboBox.mjs.map +1 -1
  37. package/dist/private/datepicker/useDateField.cjs.map +1 -1
  38. package/dist/private/datepicker/useDateField.js.map +1 -1
  39. package/dist/private/datepicker/useDateField.mjs.map +1 -1
  40. package/dist/private/datepicker/useDatePicker.cjs.map +1 -1
  41. package/dist/private/datepicker/useDatePicker.js.map +1 -1
  42. package/dist/private/datepicker/useDatePicker.mjs.map +1 -1
  43. package/dist/private/datepicker/useDateRangePicker.cjs.map +1 -1
  44. package/dist/private/datepicker/useDateRangePicker.js.map +1 -1
  45. package/dist/private/datepicker/useDateRangePicker.mjs.map +1 -1
  46. package/dist/private/datepicker/useDisplayNames.cjs +1 -2
  47. package/dist/private/datepicker/useDisplayNames.cjs.map +1 -1
  48. package/dist/private/datepicker/useDisplayNames.js +1 -2
  49. package/dist/private/datepicker/useDisplayNames.js.map +1 -1
  50. package/dist/private/datepicker/useDisplayNames.mjs +1 -2
  51. package/dist/private/datepicker/useDisplayNames.mjs.map +1 -1
  52. package/dist/private/dnd/DragManager.cjs +4 -1
  53. package/dist/private/dnd/DragManager.cjs.map +1 -1
  54. package/dist/private/dnd/DragManager.js +4 -1
  55. package/dist/private/dnd/DragManager.js.map +1 -1
  56. package/dist/private/dnd/DragManager.mjs +4 -1
  57. package/dist/private/dnd/DragManager.mjs.map +1 -1
  58. package/dist/private/dnd/useDrag.cjs.map +1 -1
  59. package/dist/private/dnd/useDrag.js.map +1 -1
  60. package/dist/private/dnd/useDrag.mjs.map +1 -1
  61. package/dist/private/dnd/useDraggableItem.cjs.map +1 -1
  62. package/dist/private/dnd/useDraggableItem.js.map +1 -1
  63. package/dist/private/dnd/useDraggableItem.mjs.map +1 -1
  64. package/dist/private/dnd/useDropIndicator.cjs.map +1 -1
  65. package/dist/private/dnd/useDropIndicator.js.map +1 -1
  66. package/dist/private/dnd/useDropIndicator.mjs.map +1 -1
  67. package/dist/private/dnd/useVirtualDrop.cjs.map +1 -1
  68. package/dist/private/dnd/useVirtualDrop.js.map +1 -1
  69. package/dist/private/dnd/useVirtualDrop.mjs.map +1 -1
  70. package/dist/private/dnd/utils.cjs +13 -3
  71. package/dist/private/dnd/utils.cjs.map +1 -1
  72. package/dist/private/dnd/utils.js +13 -3
  73. package/dist/private/dnd/utils.js.map +1 -1
  74. package/dist/private/dnd/utils.mjs +13 -3
  75. package/dist/private/dnd/utils.mjs.map +1 -1
  76. package/dist/private/form/useFormValidation.cjs +1 -1
  77. package/dist/private/form/useFormValidation.cjs.map +1 -1
  78. package/dist/private/form/useFormValidation.js +1 -1
  79. package/dist/private/form/useFormValidation.js.map +1 -1
  80. package/dist/private/form/useFormValidation.mjs +1 -1
  81. package/dist/private/form/useFormValidation.mjs.map +1 -1
  82. package/dist/private/grid/useGridSelectionAnnouncement.cjs.map +1 -1
  83. package/dist/private/grid/useGridSelectionAnnouncement.js.map +1 -1
  84. package/dist/private/grid/useGridSelectionAnnouncement.mjs.map +1 -1
  85. package/dist/private/grid/useGridSelectionCheckbox.cjs.map +1 -1
  86. package/dist/private/grid/useGridSelectionCheckbox.js.map +1 -1
  87. package/dist/private/grid/useGridSelectionCheckbox.mjs.map +1 -1
  88. package/dist/private/grid/useHighlightSelectionDescription.cjs.map +1 -1
  89. package/dist/private/grid/useHighlightSelectionDescription.js.map +1 -1
  90. package/dist/private/grid/useHighlightSelectionDescription.mjs.map +1 -1
  91. package/dist/private/gridlist/useGridList.cjs +2 -1
  92. package/dist/private/gridlist/useGridList.cjs.map +1 -1
  93. package/dist/private/gridlist/useGridList.js +2 -1
  94. package/dist/private/gridlist/useGridList.js.map +1 -1
  95. package/dist/private/gridlist/useGridList.mjs +2 -1
  96. package/dist/private/gridlist/useGridList.mjs.map +1 -1
  97. package/dist/private/gridlist/useGridListItem.cjs +62 -21
  98. package/dist/private/gridlist/useGridListItem.cjs.map +1 -1
  99. package/dist/private/gridlist/useGridListItem.js +63 -22
  100. package/dist/private/gridlist/useGridListItem.js.map +1 -1
  101. package/dist/private/gridlist/useGridListItem.mjs +62 -21
  102. package/dist/private/gridlist/useGridListItem.mjs.map +1 -1
  103. package/dist/private/interactions/createEventHandler.cjs +3 -0
  104. package/dist/private/interactions/createEventHandler.cjs.map +1 -1
  105. package/dist/private/interactions/createEventHandler.js +3 -0
  106. package/dist/private/interactions/createEventHandler.js.map +1 -1
  107. package/dist/private/interactions/createEventHandler.mjs +3 -0
  108. package/dist/private/interactions/createEventHandler.mjs.map +1 -1
  109. package/dist/private/interactions/useFocusVisible.cjs +16 -5
  110. package/dist/private/interactions/useFocusVisible.cjs.map +1 -1
  111. package/dist/private/interactions/useFocusVisible.js +16 -5
  112. package/dist/private/interactions/useFocusVisible.js.map +1 -1
  113. package/dist/private/interactions/useFocusVisible.mjs +16 -5
  114. package/dist/private/interactions/useFocusVisible.mjs.map +1 -1
  115. package/dist/private/menu/useMenu.cjs.map +1 -1
  116. package/dist/private/menu/useMenu.js.map +1 -1
  117. package/dist/private/menu/useMenu.mjs.map +1 -1
  118. package/dist/private/menu/useMenuItem.cjs +1 -1
  119. package/dist/private/menu/useMenuItem.cjs.map +1 -1
  120. package/dist/private/menu/useMenuItem.js +1 -1
  121. package/dist/private/menu/useMenuItem.js.map +1 -1
  122. package/dist/private/menu/useMenuItem.mjs +1 -1
  123. package/dist/private/menu/useMenuItem.mjs.map +1 -1
  124. package/dist/private/menu/useMenuTrigger.cjs.map +1 -1
  125. package/dist/private/menu/useMenuTrigger.js.map +1 -1
  126. package/dist/private/menu/useMenuTrigger.mjs.map +1 -1
  127. package/dist/private/menu/utils.cjs.map +1 -1
  128. package/dist/private/menu/utils.js.map +1 -1
  129. package/dist/private/menu/utils.mjs.map +1 -1
  130. package/dist/private/numberfield/useNumberField.cjs.map +1 -1
  131. package/dist/private/numberfield/useNumberField.js.map +1 -1
  132. package/dist/private/numberfield/useNumberField.mjs.map +1 -1
  133. package/dist/private/overlays/DismissButton.cjs.map +1 -1
  134. package/dist/private/overlays/DismissButton.js.map +1 -1
  135. package/dist/private/overlays/DismissButton.mjs.map +1 -1
  136. package/dist/private/overlays/calculatePosition.cjs +7 -7
  137. package/dist/private/overlays/calculatePosition.cjs.map +1 -1
  138. package/dist/private/overlays/calculatePosition.js +7 -7
  139. package/dist/private/overlays/calculatePosition.js.map +1 -1
  140. package/dist/private/overlays/calculatePosition.mjs +7 -7
  141. package/dist/private/overlays/calculatePosition.mjs.map +1 -1
  142. package/dist/private/overlays/useOverlayPosition.cjs +3 -2
  143. package/dist/private/overlays/useOverlayPosition.cjs.map +1 -1
  144. package/dist/private/overlays/useOverlayPosition.js +3 -2
  145. package/dist/private/overlays/useOverlayPosition.js.map +1 -1
  146. package/dist/private/overlays/useOverlayPosition.mjs +3 -2
  147. package/dist/private/overlays/useOverlayPosition.mjs.map +1 -1
  148. package/dist/private/searchfield/useSearchField.cjs.map +1 -1
  149. package/dist/private/searchfield/useSearchField.js.map +1 -1
  150. package/dist/private/searchfield/useSearchField.mjs.map +1 -1
  151. package/dist/private/select/useSelect.cjs +1 -2
  152. package/dist/private/select/useSelect.cjs.map +1 -1
  153. package/dist/private/select/useSelect.js +1 -2
  154. package/dist/private/select/useSelect.js.map +1 -1
  155. package/dist/private/select/useSelect.mjs +1 -2
  156. package/dist/private/select/useSelect.mjs.map +1 -1
  157. package/dist/private/selection/ListKeyboardDelegate.cjs +31 -3
  158. package/dist/private/selection/ListKeyboardDelegate.cjs.map +1 -1
  159. package/dist/private/selection/ListKeyboardDelegate.js +31 -3
  160. package/dist/private/selection/ListKeyboardDelegate.js.map +1 -1
  161. package/dist/private/selection/ListKeyboardDelegate.mjs +31 -3
  162. package/dist/private/selection/ListKeyboardDelegate.mjs.map +1 -1
  163. package/dist/private/selection/useSelectableCollection.cjs +20 -14
  164. package/dist/private/selection/useSelectableCollection.cjs.map +1 -1
  165. package/dist/private/selection/useSelectableCollection.js +26 -19
  166. package/dist/private/selection/useSelectableCollection.js.map +1 -1
  167. package/dist/private/selection/useSelectableCollection.mjs +20 -14
  168. package/dist/private/selection/useSelectableCollection.mjs.map +1 -1
  169. package/dist/private/selection/useTypeSelect.cjs +50 -18
  170. package/dist/private/selection/useTypeSelect.cjs.map +1 -1
  171. package/dist/private/selection/useTypeSelect.js +51 -19
  172. package/dist/private/selection/useTypeSelect.js.map +1 -1
  173. package/dist/private/selection/useTypeSelect.mjs +51 -19
  174. package/dist/private/selection/useTypeSelect.mjs.map +1 -1
  175. package/dist/private/spinbutton/useSpinButton.cjs.map +1 -1
  176. package/dist/private/spinbutton/useSpinButton.js.map +1 -1
  177. package/dist/private/spinbutton/useSpinButton.mjs.map +1 -1
  178. package/dist/private/steplist/useStepList.cjs.map +1 -1
  179. package/dist/private/steplist/useStepList.js.map +1 -1
  180. package/dist/private/steplist/useStepList.mjs.map +1 -1
  181. package/dist/private/table/useTable.cjs.map +1 -1
  182. package/dist/private/table/useTable.js.map +1 -1
  183. package/dist/private/table/useTable.mjs.map +1 -1
  184. package/dist/private/table/useTableColumnHeader.cjs.map +1 -1
  185. package/dist/private/table/useTableColumnHeader.js.map +1 -1
  186. package/dist/private/table/useTableColumnHeader.mjs.map +1 -1
  187. package/dist/private/table/useTableColumnResize.cjs.map +1 -1
  188. package/dist/private/table/useTableColumnResize.js.map +1 -1
  189. package/dist/private/table/useTableColumnResize.mjs.map +1 -1
  190. package/dist/private/table/useTableRow.cjs.map +1 -1
  191. package/dist/private/table/useTableRow.js.map +1 -1
  192. package/dist/private/table/useTableRow.mjs.map +1 -1
  193. package/dist/private/table/useTableSelectionCheckbox.cjs.map +1 -1
  194. package/dist/private/table/useTableSelectionCheckbox.js.map +1 -1
  195. package/dist/private/table/useTableSelectionCheckbox.mjs.map +1 -1
  196. package/dist/private/tabs/TabsKeyboardDelegate.cjs +2 -2
  197. package/dist/private/tabs/TabsKeyboardDelegate.cjs.map +1 -1
  198. package/dist/private/tabs/TabsKeyboardDelegate.js +2 -2
  199. package/dist/private/tabs/TabsKeyboardDelegate.js.map +1 -1
  200. package/dist/private/tabs/TabsKeyboardDelegate.mjs +2 -2
  201. package/dist/private/tabs/TabsKeyboardDelegate.mjs.map +1 -1
  202. package/dist/private/tag/useTag.cjs.map +1 -1
  203. package/dist/private/tag/useTag.js.map +1 -1
  204. package/dist/private/tag/useTag.mjs.map +1 -1
  205. package/dist/private/toast/useToast.cjs.map +1 -1
  206. package/dist/private/toast/useToast.js.map +1 -1
  207. package/dist/private/toast/useToast.mjs.map +1 -1
  208. package/dist/private/toast/useToastRegion.cjs.map +1 -1
  209. package/dist/private/toast/useToastRegion.js.map +1 -1
  210. package/dist/private/toast/useToastRegion.mjs.map +1 -1
  211. package/dist/private/toolbar/useToolbar.cjs +0 -1
  212. package/dist/private/toolbar/useToolbar.cjs.map +1 -1
  213. package/dist/private/toolbar/useToolbar.js +0 -1
  214. package/dist/private/toolbar/useToolbar.js.map +1 -1
  215. package/dist/private/toolbar/useToolbar.mjs +0 -1
  216. package/dist/private/toolbar/useToolbar.mjs.map +1 -1
  217. package/dist/private/tree/useTree.cjs.map +1 -1
  218. package/dist/private/tree/useTree.js.map +1 -1
  219. package/dist/private/tree/useTree.mjs.map +1 -1
  220. package/dist/private/tree/useTreeItem.cjs.map +1 -1
  221. package/dist/private/tree/useTreeItem.js.map +1 -1
  222. package/dist/private/tree/useTreeItem.mjs.map +1 -1
  223. package/dist/private/utils/isElementVisible.cjs +1 -1
  224. package/dist/private/utils/isElementVisible.cjs.map +1 -1
  225. package/dist/private/utils/isElementVisible.js +1 -1
  226. package/dist/private/utils/isElementVisible.js.map +1 -1
  227. package/dist/private/utils/isElementVisible.mjs +1 -1
  228. package/dist/private/utils/isElementVisible.mjs.map +1 -1
  229. package/dist/private/utils/isFocusable.cjs +3 -1
  230. package/dist/private/utils/isFocusable.cjs.map +1 -1
  231. package/dist/private/utils/isFocusable.js +3 -1
  232. package/dist/private/utils/isFocusable.js.map +1 -1
  233. package/dist/private/utils/isFocusable.mjs +3 -1
  234. package/dist/private/utils/isFocusable.mjs.map +1 -1
  235. package/dist/types/src/dnd/utils.d.ts +2 -2
  236. package/dist/types/src/gridlist/useGridList.d.ts +7 -0
  237. package/dist/types/src/menu/useMenu.d.ts +1 -1
  238. package/dist/types/src/menu/utils.d.ts +1 -1
  239. package/dist/types/src/overlays/calculatePosition.d.ts +1 -0
  240. package/dist/types/src/overlays/useOverlayPosition.d.ts +8 -0
  241. package/dist/types/src/selection/ListKeyboardDelegate.d.ts +1 -0
  242. package/dist/types/src/selection/useSelectableCollection.d.ts +7 -0
  243. package/dist/types/src/tree/useTree.d.ts +1 -1
  244. package/package.json +4 -4
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAwCM,SAAS,0CACd,KAA2B,EAC3B,KAAuB,EACvB,GAA8B;IAE9B,IAAI,QAAC,OAAO,oBAAQ,UAAU,WAAE,UAAU,SAAQ,GAAG;IAErD,IAAI,gBAAgB,CAAA,GAAA,yCAAI;IACxB,IAAI,gBAAC,YAAY,gBAAE,YAAY,EAAC,GAAG,CAAA,GAAA,yCAAgB,EAAE;cAAC;IAAI,GAAG,OAAO;IAEpE,IAAI,YAAY,CAAA;QACd,IAAI,YACF;QAGF,IAAI,YAAY,eAAe,CAAC,EAAE,MAAM,EACtC;QAGF,IAAI,OAAO,IAAI,OAAO,EACpB,OAAQ,EAAE,GAAG;YACX,KAAK;YACL,KAAK;gBACH,sHAAsH;gBACtH,qHAAqH;gBACrH,yHAAyH;gBACzH,2HAA2H;gBAC3H,IAAI,YAAY,eAAe,EAAE,kBAAkB,IACjD;YAEJ,cAAc;YACd,KAAK;gBACH,uEAAuE;gBACvE,IAAI,CAAE,CAAA,yBAAyB,CAAA,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AS,MAAM,KAAK;QACtB;IACF;AACF","sources":["packages/react-aria/src/menu/useMenuTrigger.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '../button/useButton';\n\nimport {AriaMenuOptions} from './useMenu';\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling} from '../utils/focusWithoutScrolling';\nimport intlMessages from '../../intl/menu/*.json';\n// @ts-ignore\nimport {MenuTriggerState, MenuTriggerType} from 'react-stately/useMenuTriggerState';\nimport {PressProps} from '../interactions/usePress';\nimport {useId} from '../utils/useId';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useLongPress} from '../interactions/useLongPress';\nimport {useOverlayTrigger} from '../overlays/useOverlayTrigger';\n\nexport interface AriaMenuTriggerProps {\n /** The type of menu that the menu trigger opens. */\n type?: 'menu' | 'listbox';\n /** Whether menu trigger is disabled. */\n isDisabled?: boolean;\n /** How menu is triggered. */\n trigger?: MenuTriggerType;\n}\n\nexport interface MenuTriggerAria<T> {\n /** Props for the menu trigger element. */\n menuTriggerProps: AriaButtonProps;\n\n /** Props for the menu. */\n menuProps: AriaMenuOptions<T>;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu trigger.\n *\n * @param props - Props for the menu trigger.\n * @param state - State for the menu trigger.\n * @param ref - Ref to the HTML element trigger for the menu.\n */\nexport function useMenuTrigger<T>(\n props: AriaMenuTriggerProps,\n state: MenuTriggerState,\n ref: RefObject<Element | null>\n): MenuTriggerAria<T> {\n let {type = 'menu', isDisabled, trigger = 'press'} = props;\n\n let menuTriggerId = useId();\n let {triggerProps, overlayProps} = useOverlayTrigger({type}, state, ref);\n\n let onKeyDown = e => {\n if (isDisabled) {\n return;\n }\n\n if (trigger === 'longPress' && !e.altKey) {\n return;\n }\n\n if (ref && ref.current) {\n switch (e.key) {\n case 'Enter':\n case ' ':\n // React puts listeners on the same root, so even if propagation was stopped, immediate propagation is still possible.\n // useTypeSelect will handle the spacebar first if it's running, so we don't want to open if it's handled it already.\n // We use isDefaultPrevented() instead of isPropagationStopped() because createEventHandler stops propagation by default.\n // And default prevented means that the event was handled by something else (typeahead), so we don't want to open the menu.\n if (trigger === 'longPress' || e.isDefaultPrevented()) {\n return;\n }\n // fallthrough\n case 'ArrowDown':\n // Stop propagation, unless it would already be handled by useKeyboard.\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('first');\n break;\n case 'ArrowUp':\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('last');\n break;\n default:\n // Allow other keys.\n if ('continuePropagation' in e) {\n e.continuePropagation();\n }\n }\n }\n };\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/menu');\n let {longPressProps} = useLongPress({\n isDisabled: isDisabled || trigger !== 'longPress',\n accessibilityDescription: stringFormatter.format('longPressMessage'),\n onLongPressStart() {\n state.close();\n },\n onLongPress() {\n state.open('first');\n }\n });\n\n let pressProps: PressProps = {\n preventFocusOnPress: true,\n onPressStart(e) {\n // For consistency with native, open the menu on mouse/key down, but touch up.\n if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) {\n // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.\n focusWithoutScrolling(e.target as FocusableElement);\n\n // If opened with a screen reader, auto focus the first item.\n // Otherwise, the menu itself will be focused.\n state.open(e.pointerType === 'virtual' ? 'first' : null);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch' && !isDisabled) {\n // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.\n focusWithoutScrolling(e.target as FocusableElement);\n\n state.toggle();\n }\n }\n };\n\n // omit onPress from triggerProps since we override it above.\n delete triggerProps.onPress;\n\n return {\n // @ts-ignore - TODO we pass out both DOMAttributes AND AriaButtonProps, but useButton will discard the longPress event handlers, it's only through PressResponder magic that this works for RSP and RAC. it does not work in aria examples\n menuTriggerProps: {\n ...triggerProps,\n ...(trigger === 'press' ? pressProps : longPressProps),\n id: menuTriggerId,\n onKeyDown\n },\n menuProps: {\n ...overlayProps,\n 'aria-labelledby': menuTriggerId,\n autoFocus: state.focusStrategy || true,\n onClose: state.close\n }\n };\n}\n"],"names":[],"version":3,"file":"useMenuTrigger.mjs.map"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAsCM,SAAS,0CACd,KAA2B,EAC3B,KAAuB,EACvB,GAA8B;IAE9B,IAAI,QAAC,OAAO,oBAAQ,UAAU,WAAE,UAAU,SAAQ,GAAG;IAErD,IAAI,gBAAgB,CAAA,GAAA,yCAAI;IACxB,IAAI,gBAAC,YAAY,gBAAE,YAAY,EAAC,GAAG,CAAA,GAAA,yCAAgB,EAAE;cAAC;IAAI,GAAG,OAAO;IAEpE,IAAI,YAAY,CAAA;QACd,IAAI,YACF;QAGF,IAAI,YAAY,eAAe,CAAC,EAAE,MAAM,EACtC;QAGF,IAAI,OAAO,IAAI,OAAO,EACpB,OAAQ,EAAE,GAAG;YACX,KAAK;YACL,KAAK;gBACH,sHAAsH;gBACtH,qHAAqH;gBACrH,yHAAyH;gBACzH,2HAA2H;gBAC3H,IAAI,YAAY,eAAe,EAAE,kBAAkB,IACjD;YAEJ,cAAc;YACd,KAAK;gBACH,uEAAuE;gBACvE,IAAI,CAAE,CAAA,yBAAyB,CAAA,GAC7B,EAAE,eAAe;gBAEnB,EAAE,cAAc;gBAChB,MAAM,MAAM,CAAC;gBACb;YACF,KAAK;gBACH,IAAI,CAAE,CAAA,yBAAyB,CAAA,GAC7B,EAAE,eAAe;gBAEnB,EAAE,cAAc;gBAChB,MAAM,MAAM,CAAC;gBACb;YACF;gBACE,oBAAoB;gBACpB,IAAI,yBAAyB,GAC3B,EAAE,mBAAmB;QAE3B;IAEJ;IAEA,IAAI,kBAAkB,CAAA,GAAA,yCAA0B,EAAE,CAAA,GAAA,+CAAW,GAAG;IAChE,IAAI,kBAAC,cAAc,EAAC,GAAG,CAAA,GAAA,yCAAW,EAAE;QAClC,YAAY,cAAc,YAAY;QACtC,0BAA0B,gBAAgB,MAAM,CAAC;QACjD;YACE,MAAM,KAAK;QACb;QACA;YACE,MAAM,IAAI,CAAC;QACb;IACF;IAEA,IAAI,aAAyB;QAC3B,qBAAqB;QACrB,cAAa,CAAC;YACZ,8EAA8E;YAC9E,IAAI,EAAE,WAAW,KAAK,WAAW,EAAE,WAAW,KAAK,cAAc,CAAC,YAAY;gBAC5E,iGAAiG;gBACjG,CAAA,GAAA,yCAAoB,EAAE,EAAE,MAAM;gBAE9B,6DAA6D;gBAC7D,8CAA8C;gBAC9C,MAAM,IAAI,CAAC,EAAE,WAAW,KAAK,YAAY,UAAU;YACrD;QACF;QACA,SAAQ,CAAC;YACP,IAAI,EAAE,WAAW,KAAK,WAAW,CAAC,YAAY;gBAC5C,iGAAiG;gBACjG,CAAA,GAAA,yCAAoB,EAAE,EAAE,MAAM;gBAE9B,MAAM,MAAM;YACd;QACF;IACF;IAEA,6DAA6D;IAC7D,OAAO,aAAa,OAAO;IAE3B,OAAO;QACL,2OAA2O;QAC3O,kBAAkB;YAChB,GAAG,YAAY;YACf,GAAI,YAAY,UAAU,aAAa,cAAc;YACrD,IAAI;uBACJ;QACF;QACA,WAAW;YACT,GAAG,YAAY;YACf,mBAAmB;YACnB,WAAW,MAAM,aAAa,IAAI;YAClC,SAAS,MAAM,KAAK;QACtB;IACF;AACF","sources":["packages/react-aria/src/menu/useMenuTrigger.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '../button/useButton';\nimport {AriaMenuOptions} from './useMenu';\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling} from '../utils/focusWithoutScrolling';\nimport intlMessages from '../../intl/menu/*.json';\nimport {MenuTriggerState, MenuTriggerType} from 'react-stately/useMenuTriggerState';\nimport {PressProps} from '../interactions/usePress';\nimport {useId} from '../utils/useId';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useLongPress} from '../interactions/useLongPress';\nimport {useOverlayTrigger} from '../overlays/useOverlayTrigger';\n\nexport interface AriaMenuTriggerProps {\n /** The type of menu that the menu trigger opens. */\n type?: 'menu' | 'listbox';\n /** Whether menu trigger is disabled. */\n isDisabled?: boolean;\n /** How menu is triggered. */\n trigger?: MenuTriggerType;\n}\n\nexport interface MenuTriggerAria<T> {\n /** Props for the menu trigger element. */\n menuTriggerProps: AriaButtonProps;\n\n /** Props for the menu. */\n menuProps: AriaMenuOptions<T>;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu trigger.\n *\n * @param props - Props for the menu trigger.\n * @param state - State for the menu trigger.\n * @param ref - Ref to the HTML element trigger for the menu.\n */\nexport function useMenuTrigger<T>(\n props: AriaMenuTriggerProps,\n state: MenuTriggerState,\n ref: RefObject<Element | null>\n): MenuTriggerAria<T> {\n let {type = 'menu', isDisabled, trigger = 'press'} = props;\n\n let menuTriggerId = useId();\n let {triggerProps, overlayProps} = useOverlayTrigger({type}, state, ref);\n\n let onKeyDown = e => {\n if (isDisabled) {\n return;\n }\n\n if (trigger === 'longPress' && !e.altKey) {\n return;\n }\n\n if (ref && ref.current) {\n switch (e.key) {\n case 'Enter':\n case ' ':\n // React puts listeners on the same root, so even if propagation was stopped, immediate propagation is still possible.\n // useTypeSelect will handle the spacebar first if it's running, so we don't want to open if it's handled it already.\n // We use isDefaultPrevented() instead of isPropagationStopped() because createEventHandler stops propagation by default.\n // And default prevented means that the event was handled by something else (typeahead), so we don't want to open the menu.\n if (trigger === 'longPress' || e.isDefaultPrevented()) {\n return;\n }\n // fallthrough\n case 'ArrowDown':\n // Stop propagation, unless it would already be handled by useKeyboard.\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('first');\n break;\n case 'ArrowUp':\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n e.preventDefault();\n state.toggle('last');\n break;\n default:\n // Allow other keys.\n if ('continuePropagation' in e) {\n e.continuePropagation();\n }\n }\n }\n };\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/menu');\n let {longPressProps} = useLongPress({\n isDisabled: isDisabled || trigger !== 'longPress',\n accessibilityDescription: stringFormatter.format('longPressMessage'),\n onLongPressStart() {\n state.close();\n },\n onLongPress() {\n state.open('first');\n }\n });\n\n let pressProps: PressProps = {\n preventFocusOnPress: true,\n onPressStart(e) {\n // For consistency with native, open the menu on mouse/key down, but touch up.\n if (e.pointerType !== 'touch' && e.pointerType !== 'keyboard' && !isDisabled) {\n // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.\n focusWithoutScrolling(e.target as FocusableElement);\n\n // If opened with a screen reader, auto focus the first item.\n // Otherwise, the menu itself will be focused.\n state.open(e.pointerType === 'virtual' ? 'first' : null);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch' && !isDisabled) {\n // Ensure trigger has focus before opening the menu so it can be restored by FocusScope on close.\n focusWithoutScrolling(e.target as FocusableElement);\n\n state.toggle();\n }\n }\n };\n\n // omit onPress from triggerProps since we override it above.\n delete triggerProps.onPress;\n\n return {\n // @ts-ignore - TODO we pass out both DOMAttributes AND AriaButtonProps, but useButton will discard the longPress event handlers, it's only through PressResponder magic that this works for RSP and RAC. it does not work in aria examples\n menuTriggerProps: {\n ...triggerProps,\n ...(trigger === 'press' ? pressProps : longPressProps),\n id: menuTriggerId,\n onKeyDown\n },\n menuProps: {\n ...overlayProps,\n 'aria-labelledby': menuTriggerId,\n autoFocus: state.focusStrategy || true,\n onClose: state.close\n }\n };\n}\n"],"names":[],"version":3,"file":"useMenuTrigger.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAkD,IAAI","sources":["packages/react-aria/src/menu/utils.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Key} from '@react-types/shared';\nimport {TreeState} from 'react-stately/useTreeState';\n\ninterface MenuData {\n onClose?: () => void;\n onAction?: (key: Key) => void;\n shouldUseVirtualFocus?: boolean;\n}\n\nexport const menuData: WeakMap<TreeState<unknown>, MenuData> = new WeakMap<\n TreeState<unknown>,\n MenuData\n>();\n"],"names":[],"version":3,"file":"utils.cjs.map"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAkD,IAAI","sources":["packages/react-aria/src/menu/utils.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Key} from '@react-types/shared';\nimport {TreeState} from 'react-stately/useTreeState';\n\ninterface MenuData {\n onClose?: () => void;\n onAction?: (key: Key, value: any) => void;\n shouldUseVirtualFocus?: boolean;\n}\n\nexport const menuData: WeakMap<TreeState<unknown>, MenuData> = new WeakMap<\n TreeState<unknown>,\n MenuData\n>();\n"],"names":[],"version":3,"file":"utils.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAkD,IAAI","sources":["packages/react-aria/src/menu/utils.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Key} from '@react-types/shared';\nimport {TreeState} from 'react-stately/useTreeState';\n\ninterface MenuData {\n onClose?: () => void;\n onAction?: (key: Key) => void;\n shouldUseVirtualFocus?: boolean;\n}\n\nexport const menuData: WeakMap<TreeState<unknown>, MenuData> = new WeakMap<\n TreeState<unknown>,\n MenuData\n>();\n"],"names":[],"version":3,"file":"utils.js.map"}
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAkD,IAAI","sources":["packages/react-aria/src/menu/utils.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Key} from '@react-types/shared';\nimport {TreeState} from 'react-stately/useTreeState';\n\ninterface MenuData {\n onClose?: () => void;\n onAction?: (key: Key, value: any) => void;\n shouldUseVirtualFocus?: boolean;\n}\n\nexport const menuData: WeakMap<TreeState<unknown>, MenuData> = new WeakMap<\n TreeState<unknown>,\n MenuData\n>();\n"],"names":[],"version":3,"file":"utils.js.map"}
@@ -1 +1 @@
1
- {"mappings":"AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAkD,IAAI","sources":["packages/react-aria/src/menu/utils.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Key} from '@react-types/shared';\nimport {TreeState} from 'react-stately/useTreeState';\n\ninterface MenuData {\n onClose?: () => void;\n onAction?: (key: Key) => void;\n shouldUseVirtualFocus?: boolean;\n}\n\nexport const menuData: WeakMap<TreeState<unknown>, MenuData> = new WeakMap<\n TreeState<unknown>,\n MenuData\n>();\n"],"names":[],"version":3,"file":"utils.mjs.map"}
1
+ {"mappings":"AAAA;;;;;;;;;;CAUC,GAWM,MAAM,4CAAkD,IAAI","sources":["packages/react-aria/src/menu/utils.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Key} from '@react-types/shared';\nimport {TreeState} from 'react-stately/useTreeState';\n\ninterface MenuData {\n onClose?: () => void;\n onAction?: (key: Key, value: any) => void;\n shouldUseVirtualFocus?: boolean;\n}\n\nexport const menuData: WeakMap<TreeState<unknown>, MenuData> = new WeakMap<\n TreeState<unknown>,\n MenuData\n>();\n"],"names":[],"version":3,"file":"utils.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;;;;;;;AAqFM,SAAS,0CACd,KAA2B,EAC3B,KAAuB,EACvB,QAA4C;IAE5C,IAAI,MACF,EAAE,sBACF,kBAAkB,sBAClB,kBAAkB,cAClB,UAAU,cACV,UAAU,cACV,UAAU,YACV,QAAQ,YACR,QAAQ,aACR,SAAS,SACT,KAAK,iBACL,aAAa,UACb,SAAS,KAAO,YAChB,OAAO,iBACP,aAAa,aACb,SAAS,WACT,OAAO,eACP,WAAW,gBACX,YAAY,mBACZ,eAAe,EACf,GAAG,YACJ,GAAG;IAEJ,IAAI,aACF,SAAS,kBACT,cAAc,aACd,SAAS,kBACT,cAAc,eACd,WAAW,cACX,UAAU,UACV,MAAM,oBACN,gBAAgB,EACjB,GAAG;IAEJ,MAAM,kBAAkB,CAAA,GAAA,qDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAClE,IAAI,oBAAoB,CAAA,GAAA,wBAAU,EAAE;QAClC,IAAI,WAAW,SAAS,OAAO,EAAE,SAAS;QAC1C,4CAA4C;QAC5C,CAAA,GAAA,yBAAQ,EAAE;YACR;QACF;QAEA,IAAI,SAAS,OAAO,EAAE,UAAU,UAC9B,CAAA,GAAA,k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M,iBAAiB,IAAI,kCAAY,iBAAiB;QAChF,IAAI,WAAW;YACb,WAAW,CAAC;YACZ,kBAAkB,oBAAoB;gBAAC;aAAkB,GAAG,EAAE;YAC9D,mBAAmB;gBACjB,UAAU,MAAM,QAAQ,CAAC,QAAQ;gBACjC,aAAa,MAAM,QAAQ,CAAC,WAAW;gBACvC,iBAAiB,MAAM,QAAQ,CAAC,eAAe;gBAC/C,eAAe,kCAAY,QAAQ,CAAC,aAAa;gBACjD,gBAAgB,kCAAY,QAAQ,CAAC,cAAc;gBACnD,cAAc,kCAAY,QAAQ,CAAC,YAAY;gBAC/C,SAAS,MAAM,QAAQ,CAAC,OAAO;gBAC/B,UAAU,MAAM,QAAQ,CAAC,QAAQ;gBACjC,cAAc,MAAM,QAAQ,CAAC,YAAY;gBACzC,cAAc,MAAM,QAAQ,CAAC,YAAY;uBACzC;YACF;QACF;QAEA,MAAM,gBAAgB,CAAC;QAEvB,0DAA0D;QAC1D,wGAAwG;QACxG,IAAI,uBAAuB,YAAY,CAAC,kCAAY,QAAQ,CAAC,KAAK,EAChE,MAAM,iBAAiB,CAAC,kCAAY,iBAAiB;IAEzD;AACF","sources":["packages/react-aria/src/numberfield/useNumberField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {announce} from '../live-announcer/LiveAnnouncer';\n\nimport {AriaButtonProps} from '../button/useButton';\nimport {\n AriaLabelingProps,\n DOMAttributes,\n DOMProps,\n GroupDOMAttributes,\n TextInputDOMEvents,\n TextInputDOMProps,\n ValidationResult\n} from '@react-types/shared';\nimport {chain} from '../utils/chain';\nimport {\n type ClipboardEvent,\n type ClipboardEventHandler,\n InputHTMLAttributes,\n LabelHTMLAttributes,\n RefObject,\n useCallback,\n useMemo,\n useState\n} from 'react';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {flushSync} from 'react-dom';\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport intlMessages from '../../intl/numberfield/*.json';\nimport {isAndroid, isIOS, isIPhone} from '../utils/platform';\nimport {mergeProps} from '../utils/mergeProps';\nimport {NumberFieldProps, NumberFieldState} from 'react-stately/useNumberFieldState';\nimport {privateValidationStateProp} from 'react-stately/private/form/useFormValidationState';\n// @ts-ignore\nimport {useFocus} from '../interactions/useFocus';\nimport {useFocusWithin} from '../interactions/useFocusWithin';\nimport {useFormattedTextField} from '../textfield/useFormattedTextField';\nimport {useFormReset} from '../utils/useFormReset';\nimport {useId} from '../utils/useId';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useNumberFormatter} from '../i18n/useNumberFormatter';\nimport {useScrollWheel} from '../interactions/useScrollWheel';\nimport {useSpinButton} from '../spinbutton/useSpinButton';\n\nexport interface AriaNumberFieldProps\n extends NumberFieldProps, DOMProps, AriaLabelingProps, TextInputDOMEvents {\n /**\n * A custom aria-label for the decrement button. If not provided, the localized string \"Decrement\"\n * is used.\n */\n decrementAriaLabel?: string;\n /**\n * A custom aria-label for the increment button. If not provided, the localized string \"Increment\"\n * is used.\n */\n incrementAriaLabel?: string;\n /**\n * Enables or disables changing the value with scroll.\n */\n isWheelDisabled?: boolean;\n}\n\nexport interface NumberFieldAria extends ValidationResult {\n /** Props for the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>;\n /** Props for the group wrapper around the input and stepper buttons. */\n groupProps: GroupDOMAttributes;\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>;\n /** Props for the increment button, to be passed to `useButton`. */\n incrementButtonProps: AriaButtonProps;\n /** Props for the decrement button, to be passed to `useButton`. */\n decrementButtonProps: AriaButtonProps;\n /** Props for the number field's description element, if any. */\n descriptionProps: DOMAttributes;\n /** Props for the number field's error message element, if any. */\n errorMessageProps: DOMAttributes;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a number field component. Number\n * fields allow users to enter a number, and increment or decrement the value using stepper\n * buttons.\n */\nexport function useNumberField(\n props: AriaNumberFieldProps,\n state: NumberFieldState,\n inputRef: RefObject<HTMLInputElement | null>\n): NumberFieldAria {\n let {\n id,\n decrementAriaLabel,\n incrementAriaLabel,\n isDisabled,\n isReadOnly,\n isRequired,\n minValue,\n maxValue,\n autoFocus,\n label,\n formatOptions,\n onBlur = () => {},\n onFocus,\n onFocusChange,\n onKeyDown,\n onKeyUp,\n description,\n errorMessage,\n isWheelDisabled,\n ...otherProps\n } = props;\n\n let {\n increment,\n incrementToMax,\n decrement,\n decrementToMin,\n numberValue,\n inputValue,\n commit,\n commitValidation\n } = state;\n\n const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/numberfield');\n let commitAndAnnounce = useCallback(() => {\n let oldValue = inputRef.current?.value ?? '';\n // Set input value to normalized valid value\n flushSync(() => {\n commit();\n });\n\n if (inputRef.current?.value !== oldValue) {\n announce(inputRef.current?.value ?? '', 'assertive');\n }\n }, [commit, inputRef]);\n\n let inputId = useId(id);\n let {focusProps} = useFocus({\n onBlur() {\n commitAndAnnounce();\n }\n });\n\n let numberFormatter = useNumberFormatter(formatOptions);\n let intlOptions = useMemo(() => numberFormatter.resolvedOptions(), [numberFormatter]);\n\n // Replace negative textValue formatted using currencySign: 'accounting'\n // with a textValue that can be announced using a minus sign.\n let textValueFormatter = useNumberFormatter({...formatOptions, currencySign: undefined});\n let textValue = useMemo(\n () => (isNaN(numberValue) ? '' : textValueFormatter.format(numberValue)),\n [textValueFormatter, numberValue]\n );\n\n let {\n spinButtonProps,\n incrementButtonProps: incButtonProps,\n decrementButtonProps: decButtonProps\n } = useSpinButton({\n isDisabled,\n isReadOnly,\n isRequired,\n maxValue,\n minValue,\n onIncrement: increment,\n onIncrementToMax: incrementToMax,\n onDecrement: decrement,\n onDecrementToMin: decrementToMin,\n value: numberValue,\n textValue\n });\n\n let [focusWithin, setFocusWithin] = useState(false);\n let {focusWithinProps} = useFocusWithin({isDisabled, onFocusWithinChange: setFocusWithin});\n\n let onWheel = useCallback(\n e => {\n // if on a trackpad, users can scroll in both X and Y at once, check the magnitude of the change\n // if it's mostly in the X direction, then just return, the user probably doesn't mean to inc/dec\n // this isn't perfect, events come in fast with small deltas and a part of the scroll may give a false indication\n // especially if the user is scrolling near 45deg\n if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) {\n return;\n }\n if (e.deltaY > 0) {\n increment();\n } else if (e.deltaY < 0) {\n decrement();\n }\n },\n [decrement, increment]\n );\n // If the input isn't supposed to receive input, disable scrolling.\n let scrollingDisabled = isWheelDisabled || isDisabled || isReadOnly || !focusWithin;\n useScrollWheel({onScroll: onWheel, isDisabled: scrollingDisabled}, inputRef);\n\n // The inputMode attribute influences the software keyboard that is shown on touch devices.\n // Browsers and operating systems are quite inconsistent about what keys are available, however.\n // We choose between numeric and decimal based on whether we allow negative and fractional numbers,\n // and based on testing on various devices to determine what keys are available in each inputMode.\n let hasDecimals = (intlOptions.maximumFractionDigits ?? 0) > 0;\n let hasNegative = state.minValue === undefined || isNaN(state.minValue) || state.minValue < 0;\n let inputMode: TextInputDOMProps['inputMode'] = 'numeric';\n if (isIPhone()) {\n // iPhone doesn't have a minus sign in either numeric or decimal.\n // Note this is only for iPhone, not iPad, which always has both\n // minus and decimal in numeric.\n if (hasNegative) {\n inputMode = 'text';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n } else if (isAndroid()) {\n // Android numeric has both a decimal point and minus key.\n // decimal does not have a minus key.\n if (hasNegative) {\n inputMode = 'numeric';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n }\n\n let onChange = value => {\n if (state.validate(value)) {\n state.setInputValue(value);\n }\n };\n\n let onPaste: ClipboardEventHandler<HTMLInputElement> = (e: ClipboardEvent<HTMLInputElement>) => {\n props.onPaste?.(e);\n let inputElement = getEventTarget(e) as HTMLInputElement;\n // we can only handle the case where the paste takes over the entire input, otherwise things get very complicated\n // trying to calculate the new string based on what the paste is replacing and where in the source string it is\n if (\n inputElement &&\n (inputElement.selectionEnd ?? -1) - (inputElement.selectionStart ?? 0) ===\n inputElement.value.length\n ) {\n e.preventDefault();\n // commit so that the user gets to see what it formats to immediately\n // paste happens before inputRef's value is updated, so have to prevent the default and do it ourselves\n // spin button will then handle announcing the new value, this should work with controlled state as well\n // because the announcement is done as a result of the new rendered input value if there is one\n commit(e.clipboardData?.getData?.('text/plain')?.trim() ?? '');\n }\n };\n\n let domProps = filterDOMProps(props);\n let onKeyDownEnter = useCallback(\n e => {\n if (e.nativeEvent.isComposing) {\n return;\n }\n\n if (e.key === 'Enter') {\n flushSync(() => {\n commit();\n });\n commitValidation();\n } else {\n e.continuePropagation();\n }\n },\n [commit, commitValidation]\n );\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {\n labelProps,\n inputProps: textFieldProps,\n descriptionProps,\n errorMessageProps\n } = useFormattedTextField(\n {\n ...otherProps,\n ...domProps,\n // These props are added to a hidden input rather than the formatted textfield.\n name: undefined,\n form: undefined,\n label,\n autoFocus,\n isDisabled,\n isReadOnly,\n isRequired,\n validate: undefined,\n [privateValidationStateProp]: state,\n value: inputValue,\n defaultValue: '!', // an invalid value so that form reset is ignored in onChange above\n autoComplete: 'off',\n 'aria-label': props['aria-label'] || undefined,\n 'aria-labelledby': props['aria-labelledby'] || undefined,\n id: inputId,\n type: 'text', // Can't use type=\"number\" because then we can't have things like $ in the field.\n inputMode,\n onChange,\n onBlur,\n onFocus,\n onFocusChange,\n onKeyDown: useMemo(() => chain(onKeyDownEnter, onKeyDown), [onKeyDownEnter, onKeyDown]),\n onKeyUp,\n onPaste,\n description,\n errorMessage\n },\n state,\n inputRef\n );\n\n useFormReset(inputRef, state.defaultNumberValue, state.setNumberValue);\n useNativeValidation(\n state,\n props.validationBehavior,\n props.commitBehavior,\n inputRef,\n state.minValue,\n state.maxValue,\n props.step,\n state.numberValue\n );\n\n let inputProps: InputHTMLAttributes<HTMLInputElement> = mergeProps(\n spinButtonProps,\n focusProps,\n textFieldProps,\n {\n // override the spinbutton role, we can't focus a spin button with VO\n role: null,\n // ignore aria-roledescription on iOS so that required state will announce when it is present\n 'aria-roledescription': !isIOS() ? stringFormatter.format('numberField') : null,\n 'aria-valuemax': null,\n 'aria-valuemin': null,\n 'aria-valuenow': null,\n 'aria-valuetext': null,\n autoCorrect: 'off',\n spellCheck: 'false'\n }\n );\n\n if (props.validationBehavior === 'native') {\n inputProps['aria-required'] = undefined;\n }\n\n let onButtonPressStart = e => {\n // If focus is already on the input, keep it there so we don't hide the\n // software keyboard when tapping the increment/decrement buttons.\n if (getActiveElement() === inputRef.current) {\n return;\n }\n\n // Otherwise, when using a mouse, move focus to the input.\n // On touch, or with a screen reader, focus the button so that the software\n // keyboard does not appear and the screen reader cursor is not moved off the button.\n if (e.pointerType === 'mouse') {\n inputRef.current?.focus();\n } else {\n e.target.focus();\n }\n };\n\n // Determine the label for the increment and decrement buttons. There are 4 cases:\n //\n // 1. With a visible label that is a string: aria-label: `Increase ${props.label}`\n // 2. With a visible label that is JSX: aria-label: 'Increase', aria-labelledby: '${incrementId} ${labelId}'\n // 3. With an aria-label: aria-label: `Increase ${props['aria-label']}`\n // 4. With an aria-labelledby: aria-label: 'Increase', aria-labelledby: `${incrementId} ${props['aria-labelledby']}`\n //\n // (1) and (2) could possibly be combined and both use aria-labelledby. However, placing the label in\n // the aria-label string rather than using aria-labelledby gives more flexibility to translators to change\n // the order or add additional words around the label if needed.\n let fieldLabel = props['aria-label'] || (typeof props.label === 'string' ? props.label : '');\n let ariaLabelledby: string | undefined;\n if (!fieldLabel) {\n ariaLabelledby = props.label != null ? labelProps.id : props['aria-labelledby'];\n }\n\n let incrementId = useId();\n let decrementId = useId();\n\n let incrementButtonProps: AriaButtonProps = mergeProps(incButtonProps, {\n 'aria-label': incrementAriaLabel || stringFormatter.format('increase', {fieldLabel}).trim(),\n id: ariaLabelledby && !incrementAriaLabel ? incrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !incrementAriaLabel ? `${incrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canIncrement,\n onPressStart: onButtonPressStart\n });\n\n let decrementButtonProps: AriaButtonProps = mergeProps(decButtonProps, {\n 'aria-label': decrementAriaLabel || stringFormatter.format('decrease', {fieldLabel}).trim(),\n id: ariaLabelledby && !decrementAriaLabel ? decrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !decrementAriaLabel ? `${decrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canDecrement,\n onPressStart: onButtonPressStart\n });\n\n return {\n groupProps: {\n ...focusWithinProps,\n role: 'group',\n 'aria-disabled': isDisabled,\n 'aria-invalid': isInvalid ? 'true' : undefined\n },\n labelProps,\n inputProps,\n incrementButtonProps,\n decrementButtonProps,\n errorMessageProps,\n descriptionProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n\nlet numberInput: HTMLInputElement | null = null;\n\nfunction useNativeValidation(\n state: NumberFieldState,\n validationBehavior: 'native' | 'aria' | undefined,\n commitBehavior: 'snap' | 'validate' | undefined,\n inputRef: RefObject<HTMLInputElement | null>,\n min: number | undefined,\n max: number | undefined,\n step: number | undefined,\n value: number | undefined\n) {\n useLayoutEffect(() => {\n let input = inputRef.current;\n if (\n commitBehavior !== 'validate' ||\n state.realtimeValidation.isInvalid ||\n !input ||\n input.disabled\n ) {\n return;\n }\n\n // Create a native number input and use it to implement validation of min/max/step.\n // This lets us get the native validation message provided by the browser instead of needing our own translations.\n if (!numberInput && typeof document !== 'undefined') {\n numberInput = document.createElement('input');\n numberInput.type = 'number';\n }\n\n if (!numberInput) {\n // For TypeScript.\n return;\n }\n\n numberInput.min = min != null && !isNaN(min) ? String(min) : '';\n numberInput.max = max != null && !isNaN(max) ? String(max) : '';\n numberInput.step = step != null && !isNaN(step) ? String(step) : '';\n numberInput.value = value != null && !isNaN(value) ? String(value) : '';\n\n // Merge validity with the visible text input (for other validations like required).\n let valid = input.validity.valid && numberInput.validity.valid;\n let validationMessage = input.validationMessage || numberInput.validationMessage;\n let validity = {\n isInvalid: !valid,\n validationErrors: validationMessage ? [validationMessage] : [],\n validationDetails: {\n badInput: input.validity.badInput,\n customError: input.validity.customError,\n patternMismatch: input.validity.patternMismatch,\n rangeOverflow: numberInput.validity.rangeOverflow,\n rangeUnderflow: numberInput.validity.rangeUnderflow,\n stepMismatch: numberInput.validity.stepMismatch,\n tooLong: input.validity.tooLong,\n tooShort: input.validity.tooShort,\n typeMismatch: input.validity.typeMismatch,\n valueMissing: input.validity.valueMissing,\n valid\n }\n };\n\n state.updateValidation(validity);\n\n // Block form submission if validation behavior is native.\n // This won't overwrite any user-defined validation message because we checked realtimeValidation above.\n if (validationBehavior === 'native' && !numberInput.validity.valid) {\n input.setCustomValidity(numberInput.validationMessage);\n }\n });\n}\n"],"names":[],"version":3,"file":"useNumberField.cjs.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;;;;;;;AAmFM,SAAS,0CACd,KAA2B,EAC3B,KAAuB,EACvB,QAA4C;IAE5C,IAAI,MACF,EAAE,sBACF,kBAAkB,sBAClB,kBAAkB,cAClB,UAAU,cACV,UAAU,cACV,UAAU,YACV,QAAQ,YACR,QAAQ,aACR,SAAS,SACT,KAAK,iBACL,aAAa,UACb,SAAS,KAAO,YAChB,OAAO,iBACP,aAAa,aACb,SAAS,WACT,OAAO,e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 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {announce} from '../live-announcer/LiveAnnouncer';\nimport {AriaButtonProps} from '../button/useButton';\nimport {\n AriaLabelingProps,\n DOMAttributes,\n DOMProps,\n GroupDOMAttributes,\n TextInputDOMEvents,\n TextInputDOMProps,\n ValidationResult\n} from '@react-types/shared';\nimport {chain} from '../utils/chain';\nimport {\n type ClipboardEvent,\n type ClipboardEventHandler,\n InputHTMLAttributes,\n LabelHTMLAttributes,\n RefObject,\n useCallback,\n useMemo,\n useState\n} from 'react';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {flushSync} from 'react-dom';\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport intlMessages from '../../intl/numberfield/*.json';\nimport {isAndroid, isIOS, isIPhone} from '../utils/platform';\nimport {mergeProps} from '../utils/mergeProps';\nimport {NumberFieldProps, NumberFieldState} from 'react-stately/useNumberFieldState';\nimport {privateValidationStateProp} from 'react-stately/private/form/useFormValidationState';\nimport {useFocus} from '../interactions/useFocus';\nimport {useFocusWithin} from '../interactions/useFocusWithin';\nimport {useFormattedTextField} from '../textfield/useFormattedTextField';\nimport {useFormReset} from '../utils/useFormReset';\nimport {useId} from '../utils/useId';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useNumberFormatter} from '../i18n/useNumberFormatter';\nimport {useScrollWheel} from '../interactions/useScrollWheel';\nimport {useSpinButton} from '../spinbutton/useSpinButton';\n\nexport interface AriaNumberFieldProps\n extends NumberFieldProps, DOMProps, AriaLabelingProps, TextInputDOMEvents {\n /**\n * A custom aria-label for the decrement button. If not provided, the localized string \"Decrement\"\n * is used.\n */\n decrementAriaLabel?: string;\n /**\n * A custom aria-label for the increment button. If not provided, the localized string \"Increment\"\n * is used.\n */\n incrementAriaLabel?: string;\n /**\n * Enables or disables changing the value with scroll.\n */\n isWheelDisabled?: boolean;\n}\n\nexport interface NumberFieldAria extends ValidationResult {\n /** Props for the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>;\n /** Props for the group wrapper around the input and stepper buttons. */\n groupProps: GroupDOMAttributes;\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>;\n /** Props for the increment button, to be passed to `useButton`. */\n incrementButtonProps: AriaButtonProps;\n /** Props for the decrement button, to be passed to `useButton`. */\n decrementButtonProps: AriaButtonProps;\n /** Props for the number field's description element, if any. */\n descriptionProps: DOMAttributes;\n /** Props for the number field's error message element, if any. */\n errorMessageProps: DOMAttributes;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a number field component. Number\n * fields allow users to enter a number, and increment or decrement the value using stepper\n * buttons.\n */\nexport function useNumberField(\n props: AriaNumberFieldProps,\n state: NumberFieldState,\n inputRef: RefObject<HTMLInputElement | null>\n): NumberFieldAria {\n let {\n id,\n decrementAriaLabel,\n incrementAriaLabel,\n isDisabled,\n isReadOnly,\n isRequired,\n minValue,\n maxValue,\n autoFocus,\n label,\n formatOptions,\n onBlur = () => {},\n onFocus,\n onFocusChange,\n onKeyDown,\n onKeyUp,\n description,\n errorMessage,\n isWheelDisabled,\n ...otherProps\n } = props;\n\n let {\n increment,\n incrementToMax,\n decrement,\n decrementToMin,\n numberValue,\n inputValue,\n commit,\n commitValidation\n } = state;\n\n const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/numberfield');\n let commitAndAnnounce = useCallback(() => {\n let oldValue = inputRef.current?.value ?? '';\n // Set input value to normalized valid value\n flushSync(() => {\n commit();\n });\n\n if (inputRef.current?.value !== oldValue) {\n announce(inputRef.current?.value ?? '', 'assertive');\n }\n }, [commit, inputRef]);\n\n let inputId = useId(id);\n let {focusProps} = useFocus({\n onBlur() {\n commitAndAnnounce();\n }\n });\n\n let numberFormatter = useNumberFormatter(formatOptions);\n let intlOptions = useMemo(() => numberFormatter.resolvedOptions(), [numberFormatter]);\n\n // Replace negative textValue formatted using currencySign: 'accounting'\n // with a textValue that can be announced using a minus sign.\n let textValueFormatter = useNumberFormatter({...formatOptions, currencySign: undefined});\n let textValue = useMemo(\n () => (isNaN(numberValue) ? '' : textValueFormatter.format(numberValue)),\n [textValueFormatter, numberValue]\n );\n\n let {\n spinButtonProps,\n incrementButtonProps: incButtonProps,\n decrementButtonProps: decButtonProps\n } = useSpinButton({\n isDisabled,\n isReadOnly,\n isRequired,\n maxValue,\n minValue,\n onIncrement: increment,\n onIncrementToMax: incrementToMax,\n onDecrement: decrement,\n onDecrementToMin: decrementToMin,\n value: numberValue,\n textValue\n });\n\n let [focusWithin, setFocusWithin] = useState(false);\n let {focusWithinProps} = useFocusWithin({isDisabled, onFocusWithinChange: setFocusWithin});\n\n let onWheel = useCallback(\n e => {\n // if on a trackpad, users can scroll in both X and Y at once, check the magnitude of the change\n // if it's mostly in the X direction, then just return, the user probably doesn't mean to inc/dec\n // this isn't perfect, events come in fast with small deltas and a part of the scroll may give a false indication\n // especially if the user is scrolling near 45deg\n if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) {\n return;\n }\n if (e.deltaY > 0) {\n increment();\n } else if (e.deltaY < 0) {\n decrement();\n }\n },\n [decrement, increment]\n );\n // If the input isn't supposed to receive input, disable scrolling.\n let scrollingDisabled = isWheelDisabled || isDisabled || isReadOnly || !focusWithin;\n useScrollWheel({onScroll: onWheel, isDisabled: scrollingDisabled}, inputRef);\n\n // The inputMode attribute influences the software keyboard that is shown on touch devices.\n // Browsers and operating systems are quite inconsistent about what keys are available, however.\n // We choose between numeric and decimal based on whether we allow negative and fractional numbers,\n // and based on testing on various devices to determine what keys are available in each inputMode.\n let hasDecimals = (intlOptions.maximumFractionDigits ?? 0) > 0;\n let hasNegative = state.minValue === undefined || isNaN(state.minValue) || state.minValue < 0;\n let inputMode: TextInputDOMProps['inputMode'] = 'numeric';\n if (isIPhone()) {\n // iPhone doesn't have a minus sign in either numeric or decimal.\n // Note this is only for iPhone, not iPad, which always has both\n // minus and decimal in numeric.\n if (hasNegative) {\n inputMode = 'text';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n } else if (isAndroid()) {\n // Android numeric has both a decimal point and minus key.\n // decimal does not have a minus key.\n if (hasNegative) {\n inputMode = 'numeric';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n }\n\n let onChange = value => {\n if (state.validate(value)) {\n state.setInputValue(value);\n }\n };\n\n let onPaste: ClipboardEventHandler<HTMLInputElement> = (e: ClipboardEvent<HTMLInputElement>) => {\n props.onPaste?.(e);\n let inputElement = getEventTarget(e) as HTMLInputElement;\n // we can only handle the case where the paste takes over the entire input, otherwise things get very complicated\n // trying to calculate the new string based on what the paste is replacing and where in the source string it is\n if (\n inputElement &&\n (inputElement.selectionEnd ?? -1) - (inputElement.selectionStart ?? 0) ===\n inputElement.value.length\n ) {\n e.preventDefault();\n // commit so that the user gets to see what it formats to immediately\n // paste happens before inputRef's value is updated, so have to prevent the default and do it ourselves\n // spin button will then handle announcing the new value, this should work with controlled state as well\n // because the announcement is done as a result of the new rendered input value if there is one\n commit(e.clipboardData?.getData?.('text/plain')?.trim() ?? '');\n }\n };\n\n let domProps = filterDOMProps(props);\n let onKeyDownEnter = useCallback(\n e => {\n if (e.nativeEvent.isComposing) {\n return;\n }\n\n if (e.key === 'Enter') {\n flushSync(() => {\n commit();\n });\n commitValidation();\n } else {\n e.continuePropagation();\n }\n },\n [commit, commitValidation]\n );\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {\n labelProps,\n inputProps: textFieldProps,\n descriptionProps,\n errorMessageProps\n } = useFormattedTextField(\n {\n ...otherProps,\n ...domProps,\n // These props are added to a hidden input rather than the formatted textfield.\n name: undefined,\n form: undefined,\n label,\n autoFocus,\n isDisabled,\n isReadOnly,\n isRequired,\n validate: undefined,\n [privateValidationStateProp]: state,\n value: inputValue,\n defaultValue: '!', // an invalid value so that form reset is ignored in onChange above\n autoComplete: 'off',\n 'aria-label': props['aria-label'] || undefined,\n 'aria-labelledby': props['aria-labelledby'] || undefined,\n id: inputId,\n type: 'text', // Can't use type=\"number\" because then we can't have things like $ in the field.\n inputMode,\n onChange,\n onBlur,\n onFocus,\n onFocusChange,\n onKeyDown: useMemo(() => chain(onKeyDownEnter, onKeyDown), [onKeyDownEnter, onKeyDown]),\n onKeyUp,\n onPaste,\n description,\n errorMessage\n },\n state,\n inputRef\n );\n\n useFormReset(inputRef, state.defaultNumberValue, state.setNumberValue);\n useNativeValidation(\n state,\n props.validationBehavior,\n props.commitBehavior,\n inputRef,\n state.minValue,\n state.maxValue,\n props.step,\n state.numberValue\n );\n\n let inputProps: InputHTMLAttributes<HTMLInputElement> = mergeProps(\n spinButtonProps,\n focusProps,\n textFieldProps,\n {\n // override the spinbutton role, we can't focus a spin button with VO\n role: null,\n // ignore aria-roledescription on iOS so that required state will announce when it is present\n 'aria-roledescription': !isIOS() ? stringFormatter.format('numberField') : null,\n 'aria-valuemax': null,\n 'aria-valuemin': null,\n 'aria-valuenow': null,\n 'aria-valuetext': null,\n autoCorrect: 'off',\n spellCheck: 'false'\n }\n );\n\n if (props.validationBehavior === 'native') {\n inputProps['aria-required'] = undefined;\n }\n\n let onButtonPressStart = e => {\n // If focus is already on the input, keep it there so we don't hide the\n // software keyboard when tapping the increment/decrement buttons.\n if (getActiveElement() === inputRef.current) {\n return;\n }\n\n // Otherwise, when using a mouse, move focus to the input.\n // On touch, or with a screen reader, focus the button so that the software\n // keyboard does not appear and the screen reader cursor is not moved off the button.\n if (e.pointerType === 'mouse') {\n inputRef.current?.focus();\n } else {\n e.target.focus();\n }\n };\n\n // Determine the label for the increment and decrement buttons. There are 4 cases:\n //\n // 1. With a visible label that is a string: aria-label: `Increase ${props.label}`\n // 2. With a visible label that is JSX: aria-label: 'Increase', aria-labelledby: '${incrementId} ${labelId}'\n // 3. With an aria-label: aria-label: `Increase ${props['aria-label']}`\n // 4. With an aria-labelledby: aria-label: 'Increase', aria-labelledby: `${incrementId} ${props['aria-labelledby']}`\n //\n // (1) and (2) could possibly be combined and both use aria-labelledby. However, placing the label in\n // the aria-label string rather than using aria-labelledby gives more flexibility to translators to change\n // the order or add additional words around the label if needed.\n let fieldLabel = props['aria-label'] || (typeof props.label === 'string' ? props.label : '');\n let ariaLabelledby: string | undefined;\n if (!fieldLabel) {\n ariaLabelledby = props.label != null ? labelProps.id : props['aria-labelledby'];\n }\n\n let incrementId = useId();\n let decrementId = useId();\n\n let incrementButtonProps: AriaButtonProps = mergeProps(incButtonProps, {\n 'aria-label': incrementAriaLabel || stringFormatter.format('increase', {fieldLabel}).trim(),\n id: ariaLabelledby && !incrementAriaLabel ? incrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !incrementAriaLabel ? `${incrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canIncrement,\n onPressStart: onButtonPressStart\n });\n\n let decrementButtonProps: AriaButtonProps = mergeProps(decButtonProps, {\n 'aria-label': decrementAriaLabel || stringFormatter.format('decrease', {fieldLabel}).trim(),\n id: ariaLabelledby && !decrementAriaLabel ? decrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !decrementAriaLabel ? `${decrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canDecrement,\n onPressStart: onButtonPressStart\n });\n\n return {\n groupProps: {\n ...focusWithinProps,\n role: 'group',\n 'aria-disabled': isDisabled,\n 'aria-invalid': isInvalid ? 'true' : undefined\n },\n labelProps,\n inputProps,\n incrementButtonProps,\n decrementButtonProps,\n errorMessageProps,\n descriptionProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n\nlet numberInput: HTMLInputElement | null = null;\n\nfunction useNativeValidation(\n state: NumberFieldState,\n validationBehavior: 'native' | 'aria' | undefined,\n commitBehavior: 'snap' | 'validate' | undefined,\n inputRef: RefObject<HTMLInputElement | null>,\n min: number | undefined,\n max: number | undefined,\n step: number | undefined,\n value: number | undefined\n) {\n useLayoutEffect(() => {\n let input = inputRef.current;\n if (\n commitBehavior !== 'validate' ||\n state.realtimeValidation.isInvalid ||\n !input ||\n input.disabled\n ) {\n return;\n }\n\n // Create a native number input and use it to implement validation of min/max/step.\n // This lets us get the native validation message provided by the browser instead of needing our own translations.\n if (!numberInput && typeof document !== 'undefined') {\n numberInput = document.createElement('input');\n numberInput.type = 'number';\n }\n\n if (!numberInput) {\n // For TypeScript.\n return;\n }\n\n numberInput.min = min != null && !isNaN(min) ? String(min) : '';\n numberInput.max = max != null && !isNaN(max) ? String(max) : '';\n numberInput.step = step != null && !isNaN(step) ? String(step) : '';\n numberInput.value = value != null && !isNaN(value) ? String(value) : '';\n\n // Merge validity with the visible text input (for other validations like required).\n let valid = input.validity.valid && numberInput.validity.valid;\n let validationMessage = input.validationMessage || numberInput.validationMessage;\n let validity = {\n isInvalid: !valid,\n validationErrors: validationMessage ? [validationMessage] : [],\n validationDetails: {\n badInput: input.validity.badInput,\n customError: input.validity.customError,\n patternMismatch: input.validity.patternMismatch,\n rangeOverflow: numberInput.validity.rangeOverflow,\n rangeUnderflow: numberInput.validity.rangeUnderflow,\n stepMismatch: numberInput.validity.stepMismatch,\n tooLong: input.validity.tooLong,\n tooShort: input.validity.tooShort,\n typeMismatch: input.validity.typeMismatch,\n valueMissing: input.validity.valueMissing,\n valid\n }\n };\n\n state.updateValidation(validity);\n\n // Block form submission if validation behavior is native.\n // This won't overwrite any user-defined validation message because we checked realtimeValidation above.\n if (validationBehavior === 'native' && !numberInput.validity.valid) {\n input.setCustomValidity(numberInput.validationMessage);\n }\n });\n}\n"],"names":[],"version":3,"file":"useNumberField.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;;;;;;;AAqFM,SAAS,0CACd,KAA2B,EAC3B,KAAuB,EACvB,QAA4C;IAE5C,IAAI,MACF,EAAE,sBACF,kBAAkB,sBAClB,kBAAkB,cAClB,UAAU,cACV,UAAU,cACV,UAAU,YACV,QAAQ,YACR,QAAQ,aACR,SAAS,SACT,KAAK,iBACL,aAAa,UACb,SAAS,KAAO,YAChB,OAAO,iBACP,aAAa,aACb,SAAS,WACT,OAAO,eACP,WAAW,gBACX,YAAY,mBACZ,eAAe,EACf,GAAG,YACJ,GAAG;IAEJ,IAAI,aACF,SAAS,kBACT,cAAc,aACd,SAAS,kBACT,cAAc,eACd,WAAW,cACX,UAAU,UACV,MAAM,oBACN,gBAAgB,EACjB,GAAG;IAEJ,MAAM,kBAAkB,CAAA,GAAA,yCAA0B,EAAE,CAAA,GAAA,8CAAW,GAAG;IAClE,IAAI,oBAAoB,CAAA,GAAA,kBAAU,EAAE;YACnB,mBAMX,oBACO;YAPI;QAAf,IAAI,WAAW,CAAA,2BAAA,oBAAA,SAAS,OAAO,cAAhB,wCAAA,kBAAkB,KAAK,cAAvB,qCAAA,0BAA2B;QAC1C,4CAA4C;QAC5C,CAAA,GAAA,gBAAQ,EAAE;YACR;QACF;YAGW;QADX,IAAI,EAAA,qBAAA,SAAS,OAAO,cAAhB,yCAAA,mBAAkB,KAAK,MAAK,UAC9B,CAAA,GAAA,yCAAO,EAAE,CAAA,4BAAA,qBAAA,SAAS,OAAO,cAAhB,yCAAA,mBAAkB,KAAK,cAAvB,sCAAA,2BAA2B,IAAI;IAE5C,GAAG;QAAC;QAAQ;KAAS;IAErB,IAAI,UAAU,CAAA,GAAA,yCAAI,EAAE;IACpB,IAAI,cAAC,UAAU,EAAC,G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QACjE,kCAAY,KAAK,GAAG,SAAS,QAAQ,CAAC,MAAM,SAAS,OAAO,SAAS;QAErE,oFAAoF;QACpF,IAAI,QAAQ,MAAM,QAAQ,CAAC,KAAK,IAAI,kCAAY,QAAQ,CAAC,KAAK;QAC9D,IAAI,oBAAoB,MAAM,iBAAiB,IAAI,kCAAY,iBAAiB;QAChF,IAAI,WAAW;YACb,WAAW,CAAC;YACZ,kBAAkB,oBAAoB;gBAAC;aAAkB,GAAG,EAAE;YAC9D,mBAAmB;gBACjB,UAAU,MAAM,QAAQ,CAAC,QAAQ;gBACjC,aAAa,MAAM,QAAQ,CAAC,WAAW;gBACvC,iBAAiB,MAAM,QAAQ,CAAC,eAAe;gBAC/C,eAAe,kCAAY,QAAQ,CAAC,aAAa;gBACjD,gBAAgB,kCAAY,QAAQ,CAAC,cAAc;gBACnD,cAAc,kCAAY,QAAQ,CAAC,YAAY;gBAC/C,SAAS,MAAM,QAAQ,CAAC,OAAO;gBAC/B,UAAU,MAAM,QAAQ,CAAC,QAAQ;gBACjC,cAAc,MAAM,QAAQ,CAAC,YAAY;gBACzC,cAAc,MAAM,QAAQ,CAAC,YAAY;uBACzC;YACF;QACF;QAEA,MAAM,gBAAgB,CAAC;QAEvB,0DAA0D;QAC1D,wGAAwG;QACxG,IAAI,uBAAuB,YAAY,CAAC,kCAAY,QAAQ,CAAC,KAAK,EAChE,MAAM,iBAAiB,CAAC,kCAAY,iBAAiB;IAEzD;AACF","sources":["packages/react-aria/src/numberfield/useNumberField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {announce} from '../live-announcer/LiveAnnouncer';\n\nimport {AriaButtonProps} from '../button/useButton';\nimport {\n AriaLabelingProps,\n DOMAttributes,\n DOMProps,\n GroupDOMAttributes,\n TextInputDOMEvents,\n TextInputDOMProps,\n ValidationResult\n} from '@react-types/shared';\nimport {chain} from '../utils/chain';\nimport {\n type ClipboardEvent,\n type ClipboardEventHandler,\n InputHTMLAttributes,\n LabelHTMLAttributes,\n RefObject,\n useCallback,\n useMemo,\n useState\n} from 'react';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {flushSync} from 'react-dom';\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport intlMessages from '../../intl/numberfield/*.json';\nimport {isAndroid, isIOS, isIPhone} from '../utils/platform';\nimport {mergeProps} from '../utils/mergeProps';\nimport {NumberFieldProps, NumberFieldState} from 'react-stately/useNumberFieldState';\nimport {privateValidationStateProp} from 'react-stately/private/form/useFormValidationState';\n// @ts-ignore\nimport {useFocus} from '../interactions/useFocus';\nimport {useFocusWithin} from '../interactions/useFocusWithin';\nimport {useFormattedTextField} from '../textfield/useFormattedTextField';\nimport {useFormReset} from '../utils/useFormReset';\nimport {useId} from '../utils/useId';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useNumberFormatter} from '../i18n/useNumberFormatter';\nimport {useScrollWheel} from '../interactions/useScrollWheel';\nimport {useSpinButton} from '../spinbutton/useSpinButton';\n\nexport interface AriaNumberFieldProps\n extends NumberFieldProps, DOMProps, AriaLabelingProps, TextInputDOMEvents {\n /**\n * A custom aria-label for the decrement button. If not provided, the localized string \"Decrement\"\n * is used.\n */\n decrementAriaLabel?: string;\n /**\n * A custom aria-label for the increment button. If not provided, the localized string \"Increment\"\n * is used.\n */\n incrementAriaLabel?: string;\n /**\n * Enables or disables changing the value with scroll.\n */\n isWheelDisabled?: boolean;\n}\n\nexport interface NumberFieldAria extends ValidationResult {\n /** Props for the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>;\n /** Props for the group wrapper around the input and stepper buttons. */\n groupProps: GroupDOMAttributes;\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>;\n /** Props for the increment button, to be passed to `useButton`. */\n incrementButtonProps: AriaButtonProps;\n /** Props for the decrement button, to be passed to `useButton`. */\n decrementButtonProps: AriaButtonProps;\n /** Props for the number field's description element, if any. */\n descriptionProps: DOMAttributes;\n /** Props for the number field's error message element, if any. */\n errorMessageProps: DOMAttributes;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a number field component. Number\n * fields allow users to enter a number, and increment or decrement the value using stepper\n * buttons.\n */\nexport function useNumberField(\n props: AriaNumberFieldProps,\n state: NumberFieldState,\n inputRef: RefObject<HTMLInputElement | null>\n): NumberFieldAria {\n let {\n id,\n decrementAriaLabel,\n incrementAriaLabel,\n isDisabled,\n isReadOnly,\n isRequired,\n minValue,\n maxValue,\n autoFocus,\n label,\n formatOptions,\n onBlur = () => {},\n onFocus,\n onFocusChange,\n onKeyDown,\n onKeyUp,\n description,\n errorMessage,\n isWheelDisabled,\n ...otherProps\n } = props;\n\n let {\n increment,\n incrementToMax,\n decrement,\n decrementToMin,\n numberValue,\n inputValue,\n commit,\n commitValidation\n } = state;\n\n const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/numberfield');\n let commitAndAnnounce = useCallback(() => {\n let oldValue = inputRef.current?.value ?? '';\n // Set input value to normalized valid value\n flushSync(() => {\n commit();\n });\n\n if (inputRef.current?.value !== oldValue) {\n announce(inputRef.current?.value ?? '', 'assertive');\n }\n }, [commit, inputRef]);\n\n let inputId = useId(id);\n let {focusProps} = useFocus({\n onBlur() {\n commitAndAnnounce();\n }\n });\n\n let numberFormatter = useNumberFormatter(formatOptions);\n let intlOptions = useMemo(() => numberFormatter.resolvedOptions(), [numberFormatter]);\n\n // Replace negative textValue formatted using currencySign: 'accounting'\n // with a textValue that can be announced using a minus sign.\n let textValueFormatter = useNumberFormatter({...formatOptions, currencySign: undefined});\n let textValue = useMemo(\n () => (isNaN(numberValue) ? '' : textValueFormatter.format(numberValue)),\n [textValueFormatter, numberValue]\n );\n\n let {\n spinButtonProps,\n incrementButtonProps: incButtonProps,\n decrementButtonProps: decButtonProps\n } = useSpinButton({\n isDisabled,\n isReadOnly,\n isRequired,\n maxValue,\n minValue,\n onIncrement: increment,\n onIncrementToMax: incrementToMax,\n onDecrement: decrement,\n onDecrementToMin: decrementToMin,\n value: numberValue,\n textValue\n });\n\n let [focusWithin, setFocusWithin] = useState(false);\n let {focusWithinProps} = useFocusWithin({isDisabled, onFocusWithinChange: setFocusWithin});\n\n let onWheel = useCallback(\n e => {\n // if on a trackpad, users can scroll in both X and Y at once, check the magnitude of the change\n // if it's mostly in the X direction, then just return, the user probably doesn't mean to inc/dec\n // this isn't perfect, events come in fast with small deltas and a part of the scroll may give a false indication\n // especially if the user is scrolling near 45deg\n if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) {\n return;\n }\n if (e.deltaY > 0) {\n increment();\n } else if (e.deltaY < 0) {\n decrement();\n }\n },\n [decrement, increment]\n );\n // If the input isn't supposed to receive input, disable scrolling.\n let scrollingDisabled = isWheelDisabled || isDisabled || isReadOnly || !focusWithin;\n useScrollWheel({onScroll: onWheel, isDisabled: scrollingDisabled}, inputRef);\n\n // The inputMode attribute influences the software keyboard that is shown on touch devices.\n // Browsers and operating systems are quite inconsistent about what keys are available, however.\n // We choose between numeric and decimal based on whether we allow negative and fractional numbers,\n // and based on testing on various devices to determine what keys are available in each inputMode.\n let hasDecimals = (intlOptions.maximumFractionDigits ?? 0) > 0;\n let hasNegative = state.minValue === undefined || isNaN(state.minValue) || state.minValue < 0;\n let inputMode: TextInputDOMProps['inputMode'] = 'numeric';\n if (isIPhone()) {\n // iPhone doesn't have a minus sign in either numeric or decimal.\n // Note this is only for iPhone, not iPad, which always has both\n // minus and decimal in numeric.\n if (hasNegative) {\n inputMode = 'text';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n } else if (isAndroid()) {\n // Android numeric has both a decimal point and minus key.\n // decimal does not have a minus key.\n if (hasNegative) {\n inputMode = 'numeric';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n }\n\n let onChange = value => {\n if (state.validate(value)) {\n state.setInputValue(value);\n }\n };\n\n let onPaste: ClipboardEventHandler<HTMLInputElement> = (e: ClipboardEvent<HTMLInputElement>) => {\n props.onPaste?.(e);\n let inputElement = getEventTarget(e) as HTMLInputElement;\n // we can only handle the case where the paste takes over the entire input, otherwise things get very complicated\n // trying to calculate the new string based on what the paste is replacing and where in the source string it is\n if (\n inputElement &&\n (inputElement.selectionEnd ?? -1) - (inputElement.selectionStart ?? 0) ===\n inputElement.value.length\n ) {\n e.preventDefault();\n // commit so that the user gets to see what it formats to immediately\n // paste happens before inputRef's value is updated, so have to prevent the default and do it ourselves\n // spin button will then handle announcing the new value, this should work with controlled state as well\n // because the announcement is done as a result of the new rendered input value if there is one\n commit(e.clipboardData?.getData?.('text/plain')?.trim() ?? '');\n }\n };\n\n let domProps = filterDOMProps(props);\n let onKeyDownEnter = useCallback(\n e => {\n if (e.nativeEvent.isComposing) {\n return;\n }\n\n if (e.key === 'Enter') {\n flushSync(() => {\n commit();\n });\n commitValidation();\n } else {\n e.continuePropagation();\n }\n },\n [commit, commitValidation]\n );\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {\n labelProps,\n inputProps: textFieldProps,\n descriptionProps,\n errorMessageProps\n } = useFormattedTextField(\n {\n ...otherProps,\n ...domProps,\n // These props are added to a hidden input rather than the formatted textfield.\n name: undefined,\n form: undefined,\n label,\n autoFocus,\n isDisabled,\n isReadOnly,\n isRequired,\n validate: undefined,\n [privateValidationStateProp]: state,\n value: inputValue,\n defaultValue: '!', // an invalid value so that form reset is ignored in onChange above\n autoComplete: 'off',\n 'aria-label': props['aria-label'] || undefined,\n 'aria-labelledby': props['aria-labelledby'] || undefined,\n id: inputId,\n type: 'text', // Can't use type=\"number\" because then we can't have things like $ in the field.\n inputMode,\n onChange,\n onBlur,\n onFocus,\n onFocusChange,\n onKeyDown: useMemo(() => chain(onKeyDownEnter, onKeyDown), [onKeyDownEnter, onKeyDown]),\n onKeyUp,\n onPaste,\n description,\n errorMessage\n },\n state,\n inputRef\n );\n\n useFormReset(inputRef, state.defaultNumberValue, state.setNumberValue);\n useNativeValidation(\n state,\n props.validationBehavior,\n props.commitBehavior,\n inputRef,\n state.minValue,\n state.maxValue,\n props.step,\n state.numberValue\n );\n\n let inputProps: InputHTMLAttributes<HTMLInputElement> = mergeProps(\n spinButtonProps,\n focusProps,\n textFieldProps,\n {\n // override the spinbutton role, we can't focus a spin button with VO\n role: null,\n // ignore aria-roledescription on iOS so that required state will announce when it is present\n 'aria-roledescription': !isIOS() ? stringFormatter.format('numberField') : null,\n 'aria-valuemax': null,\n 'aria-valuemin': null,\n 'aria-valuenow': null,\n 'aria-valuetext': null,\n autoCorrect: 'off',\n spellCheck: 'false'\n }\n );\n\n if (props.validationBehavior === 'native') {\n inputProps['aria-required'] = undefined;\n }\n\n let onButtonPressStart = e => {\n // If focus is already on the input, keep it there so we don't hide the\n // software keyboard when tapping the increment/decrement buttons.\n if (getActiveElement() === inputRef.current) {\n return;\n }\n\n // Otherwise, when using a mouse, move focus to the input.\n // On touch, or with a screen reader, focus the button so that the software\n // keyboard does not appear and the screen reader cursor is not moved off the button.\n if (e.pointerType === 'mouse') {\n inputRef.current?.focus();\n } else {\n e.target.focus();\n }\n };\n\n // Determine the label for the increment and decrement buttons. There are 4 cases:\n //\n // 1. With a visible label that is a string: aria-label: `Increase ${props.label}`\n // 2. With a visible label that is JSX: aria-label: 'Increase', aria-labelledby: '${incrementId} ${labelId}'\n // 3. With an aria-label: aria-label: `Increase ${props['aria-label']}`\n // 4. With an aria-labelledby: aria-label: 'Increase', aria-labelledby: `${incrementId} ${props['aria-labelledby']}`\n //\n // (1) and (2) could possibly be combined and both use aria-labelledby. However, placing the label in\n // the aria-label string rather than using aria-labelledby gives more flexibility to translators to change\n // the order or add additional words around the label if needed.\n let fieldLabel = props['aria-label'] || (typeof props.label === 'string' ? props.label : '');\n let ariaLabelledby: string | undefined;\n if (!fieldLabel) {\n ariaLabelledby = props.label != null ? labelProps.id : props['aria-labelledby'];\n }\n\n let incrementId = useId();\n let decrementId = useId();\n\n let incrementButtonProps: AriaButtonProps = mergeProps(incButtonProps, {\n 'aria-label': incrementAriaLabel || stringFormatter.format('increase', {fieldLabel}).trim(),\n id: ariaLabelledby && !incrementAriaLabel ? incrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !incrementAriaLabel ? `${incrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canIncrement,\n onPressStart: onButtonPressStart\n });\n\n let decrementButtonProps: AriaButtonProps = mergeProps(decButtonProps, {\n 'aria-label': decrementAriaLabel || stringFormatter.format('decrease', {fieldLabel}).trim(),\n id: ariaLabelledby && !decrementAriaLabel ? decrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !decrementAriaLabel ? `${decrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canDecrement,\n onPressStart: onButtonPressStart\n });\n\n return {\n groupProps: {\n ...focusWithinProps,\n role: 'group',\n 'aria-disabled': isDisabled,\n 'aria-invalid': isInvalid ? 'true' : undefined\n },\n labelProps,\n inputProps,\n incrementButtonProps,\n decrementButtonProps,\n errorMessageProps,\n descriptionProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n\nlet numberInput: HTMLInputElement | null = null;\n\nfunction useNativeValidation(\n state: NumberFieldState,\n validationBehavior: 'native' | 'aria' | undefined,\n commitBehavior: 'snap' | 'validate' | undefined,\n inputRef: RefObject<HTMLInputElement | null>,\n min: number | undefined,\n max: number | undefined,\n step: number | undefined,\n value: number | undefined\n) {\n useLayoutEffect(() => {\n let input = inputRef.current;\n if (\n commitBehavior !== 'validate' ||\n state.realtimeValidation.isInvalid ||\n !input ||\n input.disabled\n ) {\n return;\n }\n\n // Create a native number input and use it to implement validation of min/max/step.\n // This lets us get the native validation message provided by the browser instead of needing our own translations.\n if (!numberInput && typeof document !== 'undefined') {\n numberInput = document.createElement('input');\n numberInput.type = 'number';\n }\n\n if (!numberInput) {\n // For TypeScript.\n return;\n }\n\n numberInput.min = min != null && !isNaN(min) ? String(min) : '';\n numberInput.max = max != null && !isNaN(max) ? String(max) : '';\n numberInput.step = step != null && !isNaN(step) ? String(step) : '';\n numberInput.value = value != null && !isNaN(value) ? String(value) : '';\n\n // Merge validity with the visible text input (for other validations like required).\n let valid = input.validity.valid && numberInput.validity.valid;\n let validationMessage = input.validationMessage || numberInput.validationMessage;\n let validity = {\n isInvalid: !valid,\n validationErrors: validationMessage ? [validationMessage] : [],\n validationDetails: {\n badInput: input.validity.badInput,\n customError: input.validity.customError,\n patternMismatch: input.validity.patternMismatch,\n rangeOverflow: numberInput.validity.rangeOverflow,\n rangeUnderflow: numberInput.validity.rangeUnderflow,\n stepMismatch: numberInput.validity.stepMismatch,\n tooLong: input.validity.tooLong,\n tooShort: input.validity.tooShort,\n typeMismatch: input.validity.typeMismatch,\n valueMissing: input.validity.valueMissing,\n valid\n }\n };\n\n state.updateValidation(validity);\n\n // Block form submission if validation behavior is native.\n // This won't overwrite any user-defined validation message because we checked realtimeValidation above.\n if (validationBehavior === 'native' && !numberInput.validity.valid) {\n input.setCustomValidity(numberInput.validationMessage);\n }\n });\n}\n"],"names":[],"version":3,"file":"useNumberField.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;;;;;;;AAmFM,SAAS,0CACd,KAA2B,EAC3B,KAAuB,EACvB,QAA4C;IAE5C,IAAI,MACF,EAAE,sBACF,kBA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BAAoB;gBAAC;aAAkB,GAAG,EAAE;YAC9D,mBAAmB;gBACjB,UAAU,MAAM,QAAQ,CAAC,QAAQ;gBACjC,aAAa,MAAM,QAAQ,CAAC,WAAW;gBACvC,iBAAiB,MAAM,QAAQ,CAAC,eAAe;gBAC/C,eAAe,kCAAY,QAAQ,CAAC,aAAa;gBACjD,gBAAgB,kCAAY,QAAQ,CAAC,cAAc;gBACnD,cAAc,kCAAY,QAAQ,CAAC,YAAY;gBAC/C,SAAS,MAAM,QAAQ,CAAC,OAAO;gBAC/B,UAAU,MAAM,QAAQ,CAAC,QAAQ;gBACjC,cAAc,MAAM,QAAQ,CAAC,YAAY;gBACzC,cAAc,MAAM,QAAQ,CAAC,YAAY;uBACzC;YACF;QACF;QAEA,MAAM,gBAAgB,CAAC;QAEvB,0DAA0D;QAC1D,wGAAwG;QACxG,IAAI,uBAAuB,YAAY,CAAC,kCAAY,QAAQ,CAAC,KAAK,EAChE,MAAM,iBAAiB,CAAC,kCAAY,iBAAiB;IAEzD;AACF","sources":["packages/react-aria/src/numberfield/useNumberField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {announce} from '../live-announcer/LiveAnnouncer';\nimport {AriaButtonProps} from '../button/useButton';\nimport {\n AriaLabelingProps,\n DOMAttributes,\n DOMProps,\n GroupDOMAttributes,\n TextInputDOMEvents,\n TextInputDOMProps,\n ValidationResult\n} from '@react-types/shared';\nimport {chain} from '../utils/chain';\nimport {\n type ClipboardEvent,\n type ClipboardEventHandler,\n InputHTMLAttributes,\n LabelHTMLAttributes,\n RefObject,\n useCallback,\n useMemo,\n useState\n} from 'react';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {flushSync} from 'react-dom';\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport intlMessages from '../../intl/numberfield/*.json';\nimport {isAndroid, isIOS, isIPhone} from '../utils/platform';\nimport {mergeProps} from '../utils/mergeProps';\nimport {NumberFieldProps, NumberFieldState} from 'react-stately/useNumberFieldState';\nimport {privateValidationStateProp} from 'react-stately/private/form/useFormValidationState';\nimport {useFocus} from '../interactions/useFocus';\nimport {useFocusWithin} from '../interactions/useFocusWithin';\nimport {useFormattedTextField} from '../textfield/useFormattedTextField';\nimport {useFormReset} from '../utils/useFormReset';\nimport {useId} from '../utils/useId';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useNumberFormatter} from '../i18n/useNumberFormatter';\nimport {useScrollWheel} from '../interactions/useScrollWheel';\nimport {useSpinButton} from '../spinbutton/useSpinButton';\n\nexport interface AriaNumberFieldProps\n extends NumberFieldProps, DOMProps, AriaLabelingProps, TextInputDOMEvents {\n /**\n * A custom aria-label for the decrement button. If not provided, the localized string \"Decrement\"\n * is used.\n */\n decrementAriaLabel?: string;\n /**\n * A custom aria-label for the increment button. If not provided, the localized string \"Increment\"\n * is used.\n */\n incrementAriaLabel?: string;\n /**\n * Enables or disables changing the value with scroll.\n */\n isWheelDisabled?: boolean;\n}\n\nexport interface NumberFieldAria extends ValidationResult {\n /** Props for the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>;\n /** Props for the group wrapper around the input and stepper buttons. */\n groupProps: GroupDOMAttributes;\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>;\n /** Props for the increment button, to be passed to `useButton`. */\n incrementButtonProps: AriaButtonProps;\n /** Props for the decrement button, to be passed to `useButton`. */\n decrementButtonProps: AriaButtonProps;\n /** Props for the number field's description element, if any. */\n descriptionProps: DOMAttributes;\n /** Props for the number field's error message element, if any. */\n errorMessageProps: DOMAttributes;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a number field component. Number\n * fields allow users to enter a number, and increment or decrement the value using stepper\n * buttons.\n */\nexport function useNumberField(\n props: AriaNumberFieldProps,\n state: NumberFieldState,\n inputRef: RefObject<HTMLInputElement | null>\n): NumberFieldAria {\n let {\n id,\n decrementAriaLabel,\n incrementAriaLabel,\n isDisabled,\n isReadOnly,\n isRequired,\n minValue,\n maxValue,\n autoFocus,\n label,\n formatOptions,\n onBlur = () => {},\n onFocus,\n onFocusChange,\n onKeyDown,\n onKeyUp,\n description,\n errorMessage,\n isWheelDisabled,\n ...otherProps\n } = props;\n\n let {\n increment,\n incrementToMax,\n decrement,\n decrementToMin,\n numberValue,\n inputValue,\n commit,\n commitValidation\n } = state;\n\n const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/numberfield');\n let commitAndAnnounce = useCallback(() => {\n let oldValue = inputRef.current?.value ?? '';\n // Set input value to normalized valid value\n flushSync(() => {\n commit();\n });\n\n if (inputRef.current?.value !== oldValue) {\n announce(inputRef.current?.value ?? '', 'assertive');\n }\n }, [commit, inputRef]);\n\n let inputId = useId(id);\n let {focusProps} = useFocus({\n onBlur() {\n commitAndAnnounce();\n }\n });\n\n let numberFormatter = useNumberFormatter(formatOptions);\n let intlOptions = useMemo(() => numberFormatter.resolvedOptions(), [numberFormatter]);\n\n // Replace negative textValue formatted using currencySign: 'accounting'\n // with a textValue that can be announced using a minus sign.\n let textValueFormatter = useNumberFormatter({...formatOptions, currencySign: undefined});\n let textValue = useMemo(\n () => (isNaN(numberValue) ? '' : textValueFormatter.format(numberValue)),\n [textValueFormatter, numberValue]\n );\n\n let {\n spinButtonProps,\n incrementButtonProps: incButtonProps,\n decrementButtonProps: decButtonProps\n } = useSpinButton({\n isDisabled,\n isReadOnly,\n isRequired,\n maxValue,\n minValue,\n onIncrement: increment,\n onIncrementToMax: incrementToMax,\n onDecrement: decrement,\n onDecrementToMin: decrementToMin,\n value: numberValue,\n textValue\n });\n\n let [focusWithin, setFocusWithin] = useState(false);\n let {focusWithinProps} = useFocusWithin({isDisabled, onFocusWithinChange: setFocusWithin});\n\n let onWheel = useCallback(\n e => {\n // if on a trackpad, users can scroll in both X and Y at once, check the magnitude of the change\n // if it's mostly in the X direction, then just return, the user probably doesn't mean to inc/dec\n // this isn't perfect, events come in fast with small deltas and a part of the scroll may give a false indication\n // especially if the user is scrolling near 45deg\n if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) {\n return;\n }\n if (e.deltaY > 0) {\n increment();\n } else if (e.deltaY < 0) {\n decrement();\n }\n },\n [decrement, increment]\n );\n // If the input isn't supposed to receive input, disable scrolling.\n let scrollingDisabled = isWheelDisabled || isDisabled || isReadOnly || !focusWithin;\n useScrollWheel({onScroll: onWheel, isDisabled: scrollingDisabled}, inputRef);\n\n // The inputMode attribute influences the software keyboard that is shown on touch devices.\n // Browsers and operating systems are quite inconsistent about what keys are available, however.\n // We choose between numeric and decimal based on whether we allow negative and fractional numbers,\n // and based on testing on various devices to determine what keys are available in each inputMode.\n let hasDecimals = (intlOptions.maximumFractionDigits ?? 0) > 0;\n let hasNegative = state.minValue === undefined || isNaN(state.minValue) || state.minValue < 0;\n let inputMode: TextInputDOMProps['inputMode'] = 'numeric';\n if (isIPhone()) {\n // iPhone doesn't have a minus sign in either numeric or decimal.\n // Note this is only for iPhone, not iPad, which always has both\n // minus and decimal in numeric.\n if (hasNegative) {\n inputMode = 'text';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n } else if (isAndroid()) {\n // Android numeric has both a decimal point and minus key.\n // decimal does not have a minus key.\n if (hasNegative) {\n inputMode = 'numeric';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n }\n\n let onChange = value => {\n if (state.validate(value)) {\n state.setInputValue(value);\n }\n };\n\n let onPaste: ClipboardEventHandler<HTMLInputElement> = (e: ClipboardEvent<HTMLInputElement>) => {\n props.onPaste?.(e);\n let inputElement = getEventTarget(e) as HTMLInputElement;\n // we can only handle the case where the paste takes over the entire input, otherwise things get very complicated\n // trying to calculate the new string based on what the paste is replacing and where in the source string it is\n if (\n inputElement &&\n (inputElement.selectionEnd ?? -1) - (inputElement.selectionStart ?? 0) ===\n inputElement.value.length\n ) {\n e.preventDefault();\n // commit so that the user gets to see what it formats to immediately\n // paste happens before inputRef's value is updated, so have to prevent the default and do it ourselves\n // spin button will then handle announcing the new value, this should work with controlled state as well\n // because the announcement is done as a result of the new rendered input value if there is one\n commit(e.clipboardData?.getData?.('text/plain')?.trim() ?? '');\n }\n };\n\n let domProps = filterDOMProps(props);\n let onKeyDownEnter = useCallback(\n e => {\n if (e.nativeEvent.isComposing) {\n return;\n }\n\n if (e.key === 'Enter') {\n flushSync(() => {\n commit();\n });\n commitValidation();\n } else {\n e.continuePropagation();\n }\n },\n [commit, commitValidation]\n );\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {\n labelProps,\n inputProps: textFieldProps,\n descriptionProps,\n errorMessageProps\n } = useFormattedTextField(\n {\n ...otherProps,\n ...domProps,\n // These props are added to a hidden input rather than the formatted textfield.\n name: undefined,\n form: undefined,\n label,\n autoFocus,\n isDisabled,\n isReadOnly,\n isRequired,\n validate: undefined,\n [privateValidationStateProp]: state,\n value: inputValue,\n defaultValue: '!', // an invalid value so that form reset is ignored in onChange above\n autoComplete: 'off',\n 'aria-label': props['aria-label'] || undefined,\n 'aria-labelledby': props['aria-labelledby'] || undefined,\n id: inputId,\n type: 'text', // Can't use type=\"number\" because then we can't have things like $ in the field.\n inputMode,\n onChange,\n onBlur,\n onFocus,\n onFocusChange,\n onKeyDown: useMemo(() => chain(onKeyDownEnter, onKeyDown), [onKeyDownEnter, onKeyDown]),\n onKeyUp,\n onPaste,\n description,\n errorMessage\n },\n state,\n inputRef\n );\n\n useFormReset(inputRef, state.defaultNumberValue, state.setNumberValue);\n useNativeValidation(\n state,\n props.validationBehavior,\n props.commitBehavior,\n inputRef,\n state.minValue,\n state.maxValue,\n props.step,\n state.numberValue\n );\n\n let inputProps: InputHTMLAttributes<HTMLInputElement> = mergeProps(\n spinButtonProps,\n focusProps,\n textFieldProps,\n {\n // override the spinbutton role, we can't focus a spin button with VO\n role: null,\n // ignore aria-roledescription on iOS so that required state will announce when it is present\n 'aria-roledescription': !isIOS() ? stringFormatter.format('numberField') : null,\n 'aria-valuemax': null,\n 'aria-valuemin': null,\n 'aria-valuenow': null,\n 'aria-valuetext': null,\n autoCorrect: 'off',\n spellCheck: 'false'\n }\n );\n\n if (props.validationBehavior === 'native') {\n inputProps['aria-required'] = undefined;\n }\n\n let onButtonPressStart = e => {\n // If focus is already on the input, keep it there so we don't hide the\n // software keyboard when tapping the increment/decrement buttons.\n if (getActiveElement() === inputRef.current) {\n return;\n }\n\n // Otherwise, when using a mouse, move focus to the input.\n // On touch, or with a screen reader, focus the button so that the software\n // keyboard does not appear and the screen reader cursor is not moved off the button.\n if (e.pointerType === 'mouse') {\n inputRef.current?.focus();\n } else {\n e.target.focus();\n }\n };\n\n // Determine the label for the increment and decrement buttons. There are 4 cases:\n //\n // 1. With a visible label that is a string: aria-label: `Increase ${props.label}`\n // 2. With a visible label that is JSX: aria-label: 'Increase', aria-labelledby: '${incrementId} ${labelId}'\n // 3. With an aria-label: aria-label: `Increase ${props['aria-label']}`\n // 4. With an aria-labelledby: aria-label: 'Increase', aria-labelledby: `${incrementId} ${props['aria-labelledby']}`\n //\n // (1) and (2) could possibly be combined and both use aria-labelledby. However, placing the label in\n // the aria-label string rather than using aria-labelledby gives more flexibility to translators to change\n // the order or add additional words around the label if needed.\n let fieldLabel = props['aria-label'] || (typeof props.label === 'string' ? props.label : '');\n let ariaLabelledby: string | undefined;\n if (!fieldLabel) {\n ariaLabelledby = props.label != null ? labelProps.id : props['aria-labelledby'];\n }\n\n let incrementId = useId();\n let decrementId = useId();\n\n let incrementButtonProps: AriaButtonProps = mergeProps(incButtonProps, {\n 'aria-label': incrementAriaLabel || stringFormatter.format('increase', {fieldLabel}).trim(),\n id: ariaLabelledby && !incrementAriaLabel ? incrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !incrementAriaLabel ? `${incrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canIncrement,\n onPressStart: onButtonPressStart\n });\n\n let decrementButtonProps: AriaButtonProps = mergeProps(decButtonProps, {\n 'aria-label': decrementAriaLabel || stringFormatter.format('decrease', {fieldLabel}).trim(),\n id: ariaLabelledby && !decrementAriaLabel ? decrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !decrementAriaLabel ? `${decrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canDecrement,\n onPressStart: onButtonPressStart\n });\n\n return {\n groupProps: {\n ...focusWithinProps,\n role: 'group',\n 'aria-disabled': isDisabled,\n 'aria-invalid': isInvalid ? 'true' : undefined\n },\n labelProps,\n inputProps,\n incrementButtonProps,\n decrementButtonProps,\n errorMessageProps,\n descriptionProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n\nlet numberInput: HTMLInputElement | null = null;\n\nfunction useNativeValidation(\n state: NumberFieldState,\n validationBehavior: 'native' | 'aria' | undefined,\n commitBehavior: 'snap' | 'validate' | undefined,\n inputRef: RefObject<HTMLInputElement | null>,\n min: number | undefined,\n max: number | undefined,\n step: number | undefined,\n value: number | undefined\n) {\n useLayoutEffect(() => {\n let input = inputRef.current;\n if (\n commitBehavior !== 'validate' ||\n state.realtimeValidation.isInvalid ||\n !input ||\n input.disabled\n ) {\n return;\n }\n\n // Create a native number input and use it to implement validation of min/max/step.\n // This lets us get the native validation message provided by the browser instead of needing our own translations.\n if (!numberInput && typeof document !== 'undefined') {\n numberInput = document.createElement('input');\n numberInput.type = 'number';\n }\n\n if (!numberInput) {\n // For TypeScript.\n return;\n }\n\n numberInput.min = min != null && !isNaN(min) ? String(min) : '';\n numberInput.max = max != null && !isNaN(max) ? String(max) : '';\n numberInput.step = step != null && !isNaN(step) ? String(step) : '';\n numberInput.value = value != null && !isNaN(value) ? String(value) : '';\n\n // Merge validity with the visible text input (for other validations like required).\n let valid = input.validity.valid && numberInput.validity.valid;\n let validationMessage = input.validationMessage || numberInput.validationMessage;\n let validity = {\n isInvalid: !valid,\n validationErrors: validationMessage ? [validationMessage] : [],\n validationDetails: {\n badInput: input.validity.badInput,\n customError: input.validity.customError,\n patternMismatch: input.validity.patternMismatch,\n rangeOverflow: numberInput.validity.rangeOverflow,\n rangeUnderflow: numberInput.validity.rangeUnderflow,\n stepMismatch: numberInput.validity.stepMismatch,\n tooLong: input.validity.tooLong,\n tooShort: input.validity.tooShort,\n typeMismatch: input.validity.typeMismatch,\n valueMissing: input.validity.valueMissing,\n valid\n }\n };\n\n state.updateValidation(validity);\n\n // Block form submission if validation behavior is native.\n // This won't overwrite any user-defined validation message because we checked realtimeValidation above.\n if (validationBehavior === 'native' && !numberInput.validity.valid) {\n input.setCustomValidity(numberInput.validationMessage);\n }\n });\n}\n"],"names":[],"version":3,"file":"useNumberField.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;;;;;;;;;AAqFM,SAAS,0CACd,KAA2B,EAC3B,KAAuB,EACvB,QAA4C;IAE5C,IAAI,MACF,EAAE,sBACF,kBAAkB,sBAClB,kBAAkB,cAClB,UAAU,cACV,UAAU,cACV,UAAU,YACV,QAAQ,YACR,QAAQ,aACR,SAAS,SACT,KAAK,iBACL,aAAa,UACb,SAAS,KAAO,YAChB,OAAO,iBACP,aAAa,aACb,SAAS,WACT,OAAO,eACP,WAAW,gBACX,YAAY,mBACZ,eAAe,EACf,GAAG,YACJ,GAAG;IAEJ,IAAI,aACF,SAAS,kBACT,cAAc,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,MAAM,OAAO,OAAO,OAAO;QAC7D,kCAAY,GAAG,GAAG,OAAO,QAAQ,CAAC,MAAM,OAAO,OAAO,OAAO;QAC7D,kCAAY,IAAI,GAAG,QAAQ,QAAQ,CAAC,MAAM,QAAQ,OAAO,QAAQ;QACjE,kCAAY,KAAK,GAAG,SAAS,QAAQ,CAAC,MAAM,SAAS,OAAO,SAAS;QAErE,oFAAoF;QACpF,IAAI,QAAQ,MAAM,QAAQ,CAAC,KAAK,IAAI,kCAAY,QAAQ,CAAC,KAAK;QAC9D,IAAI,oBAAoB,MAAM,iBAAiB,IAAI,kCAAY,iBAAiB;QAChF,IAAI,WAAW;YACb,WAAW,CAAC;YACZ,kBAAkB,oBAAoB;gBAAC;aAAkB,GAAG,EAAE;YAC9D,mBAAmB;gBACjB,UAAU,MAAM,QAAQ,CAAC,QAAQ;gBACjC,aAAa,MAAM,QAAQ,CAAC,WAAW;gBACvC,iBAAiB,MAAM,QAAQ,CAAC,eAAe;gBAC/C,eAAe,kCAAY,QAAQ,CAAC,aAAa;gBACjD,gBAAgB,kCAAY,QAAQ,CAAC,cAAc;gBACnD,cAAc,kCAAY,QAAQ,CAAC,YAAY;gBAC/C,SAAS,MAAM,QAAQ,CAAC,OAAO;gBAC/B,UAAU,MAAM,QAAQ,CAAC,QAAQ;gBACjC,cAAc,MAAM,QAAQ,CAAC,YAAY;gBACzC,cAAc,MAAM,QAAQ,CAAC,YAAY;uBACzC;YACF;QACF;QAEA,MAAM,gBAAgB,CAAC;QAEvB,0DAA0D;QAC1D,wGAAwG;QACxG,IAAI,uBAAuB,YAAY,CAAC,kCAAY,QAAQ,CAAC,KAAK,EAChE,MAAM,iBAAiB,CAAC,kCAAY,iBAAiB;IAEzD;AACF","sources":["packages/react-aria/src/numberfield/useNumberField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {announce} from '../live-announcer/LiveAnnouncer';\n\nimport {AriaButtonProps} from '../button/useButton';\nimport {\n AriaLabelingProps,\n DOMAttributes,\n DOMProps,\n GroupDOMAttributes,\n TextInputDOMEvents,\n TextInputDOMProps,\n ValidationResult\n} from '@react-types/shared';\nimport {chain} from '../utils/chain';\nimport {\n type ClipboardEvent,\n type ClipboardEventHandler,\n InputHTMLAttributes,\n LabelHTMLAttributes,\n RefObject,\n useCallback,\n useMemo,\n useState\n} from 'react';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {flushSync} from 'react-dom';\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport intlMessages from '../../intl/numberfield/*.json';\nimport {isAndroid, isIOS, isIPhone} from '../utils/platform';\nimport {mergeProps} from '../utils/mergeProps';\nimport {NumberFieldProps, NumberFieldState} from 'react-stately/useNumberFieldState';\nimport {privateValidationStateProp} from 'react-stately/private/form/useFormValidationState';\n// @ts-ignore\nimport {useFocus} from '../interactions/useFocus';\nimport {useFocusWithin} from '../interactions/useFocusWithin';\nimport {useFormattedTextField} from '../textfield/useFormattedTextField';\nimport {useFormReset} from '../utils/useFormReset';\nimport {useId} from '../utils/useId';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useNumberFormatter} from '../i18n/useNumberFormatter';\nimport {useScrollWheel} from '../interactions/useScrollWheel';\nimport {useSpinButton} from '../spinbutton/useSpinButton';\n\nexport interface AriaNumberFieldProps\n extends NumberFieldProps, DOMProps, AriaLabelingProps, TextInputDOMEvents {\n /**\n * A custom aria-label for the decrement button. If not provided, the localized string \"Decrement\"\n * is used.\n */\n decrementAriaLabel?: string;\n /**\n * A custom aria-label for the increment button. If not provided, the localized string \"Increment\"\n * is used.\n */\n incrementAriaLabel?: string;\n /**\n * Enables or disables changing the value with scroll.\n */\n isWheelDisabled?: boolean;\n}\n\nexport interface NumberFieldAria extends ValidationResult {\n /** Props for the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>;\n /** Props for the group wrapper around the input and stepper buttons. */\n groupProps: GroupDOMAttributes;\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>;\n /** Props for the increment button, to be passed to `useButton`. */\n incrementButtonProps: AriaButtonProps;\n /** Props for the decrement button, to be passed to `useButton`. */\n decrementButtonProps: AriaButtonProps;\n /** Props for the number field's description element, if any. */\n descriptionProps: DOMAttributes;\n /** Props for the number field's error message element, if any. */\n errorMessageProps: DOMAttributes;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a number field component. Number\n * fields allow users to enter a number, and increment or decrement the value using stepper\n * buttons.\n */\nexport function useNumberField(\n props: AriaNumberFieldProps,\n state: NumberFieldState,\n inputRef: RefObject<HTMLInputElement | null>\n): NumberFieldAria {\n let {\n id,\n decrementAriaLabel,\n incrementAriaLabel,\n isDisabled,\n isReadOnly,\n isRequired,\n minValue,\n maxValue,\n autoFocus,\n label,\n formatOptions,\n onBlur = () => {},\n onFocus,\n onFocusChange,\n onKeyDown,\n onKeyUp,\n description,\n errorMessage,\n isWheelDisabled,\n ...otherProps\n } = props;\n\n let {\n increment,\n incrementToMax,\n decrement,\n decrementToMin,\n numberValue,\n inputValue,\n commit,\n commitValidation\n } = state;\n\n const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/numberfield');\n let commitAndAnnounce = useCallback(() => {\n let oldValue = inputRef.current?.value ?? '';\n // Set input value to normalized valid value\n flushSync(() => {\n commit();\n });\n\n if (inputRef.current?.value !== oldValue) {\n announce(inputRef.current?.value ?? '', 'assertive');\n }\n }, [commit, inputRef]);\n\n let inputId = useId(id);\n let {focusProps} = useFocus({\n onBlur() {\n commitAndAnnounce();\n }\n });\n\n let numberFormatter = useNumberFormatter(formatOptions);\n let intlOptions = useMemo(() => numberFormatter.resolvedOptions(), [numberFormatter]);\n\n // Replace negative textValue formatted using currencySign: 'accounting'\n // with a textValue that can be announced using a minus sign.\n let textValueFormatter = useNumberFormatter({...formatOptions, currencySign: undefined});\n let textValue = useMemo(\n () => (isNaN(numberValue) ? '' : textValueFormatter.format(numberValue)),\n [textValueFormatter, numberValue]\n );\n\n let {\n spinButtonProps,\n incrementButtonProps: incButtonProps,\n decrementButtonProps: decButtonProps\n } = useSpinButton({\n isDisabled,\n isReadOnly,\n isRequired,\n maxValue,\n minValue,\n onIncrement: increment,\n onIncrementToMax: incrementToMax,\n onDecrement: decrement,\n onDecrementToMin: decrementToMin,\n value: numberValue,\n textValue\n });\n\n let [focusWithin, setFocusWithin] = useState(false);\n let {focusWithinProps} = useFocusWithin({isDisabled, onFocusWithinChange: setFocusWithin});\n\n let onWheel = useCallback(\n e => {\n // if on a trackpad, users can scroll in both X and Y at once, check the magnitude of the change\n // if it's mostly in the X direction, then just return, the user probably doesn't mean to inc/dec\n // this isn't perfect, events come in fast with small deltas and a part of the scroll may give a false indication\n // especially if the user is scrolling near 45deg\n if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) {\n return;\n }\n if (e.deltaY > 0) {\n increment();\n } else if (e.deltaY < 0) {\n decrement();\n }\n },\n [decrement, increment]\n );\n // If the input isn't supposed to receive input, disable scrolling.\n let scrollingDisabled = isWheelDisabled || isDisabled || isReadOnly || !focusWithin;\n useScrollWheel({onScroll: onWheel, isDisabled: scrollingDisabled}, inputRef);\n\n // The inputMode attribute influences the software keyboard that is shown on touch devices.\n // Browsers and operating systems are quite inconsistent about what keys are available, however.\n // We choose between numeric and decimal based on whether we allow negative and fractional numbers,\n // and based on testing on various devices to determine what keys are available in each inputMode.\n let hasDecimals = (intlOptions.maximumFractionDigits ?? 0) > 0;\n let hasNegative = state.minValue === undefined || isNaN(state.minValue) || state.minValue < 0;\n let inputMode: TextInputDOMProps['inputMode'] = 'numeric';\n if (isIPhone()) {\n // iPhone doesn't have a minus sign in either numeric or decimal.\n // Note this is only for iPhone, not iPad, which always has both\n // minus and decimal in numeric.\n if (hasNegative) {\n inputMode = 'text';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n } else if (isAndroid()) {\n // Android numeric has both a decimal point and minus key.\n // decimal does not have a minus key.\n if (hasNegative) {\n inputMode = 'numeric';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n }\n\n let onChange = value => {\n if (state.validate(value)) {\n state.setInputValue(value);\n }\n };\n\n let onPaste: ClipboardEventHandler<HTMLInputElement> = (e: ClipboardEvent<HTMLInputElement>) => {\n props.onPaste?.(e);\n let inputElement = getEventTarget(e) as HTMLInputElement;\n // we can only handle the case where the paste takes over the entire input, otherwise things get very complicated\n // trying to calculate the new string based on what the paste is replacing and where in the source string it is\n if (\n inputElement &&\n (inputElement.selectionEnd ?? -1) - (inputElement.selectionStart ?? 0) ===\n inputElement.value.length\n ) {\n e.preventDefault();\n // commit so that the user gets to see what it formats to immediately\n // paste happens before inputRef's value is updated, so have to prevent the default and do it ourselves\n // spin button will then handle announcing the new value, this should work with controlled state as well\n // because the announcement is done as a result of the new rendered input value if there is one\n commit(e.clipboardData?.getData?.('text/plain')?.trim() ?? '');\n }\n };\n\n let domProps = filterDOMProps(props);\n let onKeyDownEnter = useCallback(\n e => {\n if (e.nativeEvent.isComposing) {\n return;\n }\n\n if (e.key === 'Enter') {\n flushSync(() => {\n commit();\n });\n commitValidation();\n } else {\n e.continuePropagation();\n }\n },\n [commit, commitValidation]\n );\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {\n labelProps,\n inputProps: textFieldProps,\n descriptionProps,\n errorMessageProps\n } = useFormattedTextField(\n {\n ...otherProps,\n ...domProps,\n // These props are added to a hidden input rather than the formatted textfield.\n name: undefined,\n form: undefined,\n label,\n autoFocus,\n isDisabled,\n isReadOnly,\n isRequired,\n validate: undefined,\n [privateValidationStateProp]: state,\n value: inputValue,\n defaultValue: '!', // an invalid value so that form reset is ignored in onChange above\n autoComplete: 'off',\n 'aria-label': props['aria-label'] || undefined,\n 'aria-labelledby': props['aria-labelledby'] || undefined,\n id: inputId,\n type: 'text', // Can't use type=\"number\" because then we can't have things like $ in the field.\n inputMode,\n onChange,\n onBlur,\n onFocus,\n onFocusChange,\n onKeyDown: useMemo(() => chain(onKeyDownEnter, onKeyDown), [onKeyDownEnter, onKeyDown]),\n onKeyUp,\n onPaste,\n description,\n errorMessage\n },\n state,\n inputRef\n );\n\n useFormReset(inputRef, state.defaultNumberValue, state.setNumberValue);\n useNativeValidation(\n state,\n props.validationBehavior,\n props.commitBehavior,\n inputRef,\n state.minValue,\n state.maxValue,\n props.step,\n state.numberValue\n );\n\n let inputProps: InputHTMLAttributes<HTMLInputElement> = mergeProps(\n spinButtonProps,\n focusProps,\n textFieldProps,\n {\n // override the spinbutton role, we can't focus a spin button with VO\n role: null,\n // ignore aria-roledescription on iOS so that required state will announce when it is present\n 'aria-roledescription': !isIOS() ? stringFormatter.format('numberField') : null,\n 'aria-valuemax': null,\n 'aria-valuemin': null,\n 'aria-valuenow': null,\n 'aria-valuetext': null,\n autoCorrect: 'off',\n spellCheck: 'false'\n }\n );\n\n if (props.validationBehavior === 'native') {\n inputProps['aria-required'] = undefined;\n }\n\n let onButtonPressStart = e => {\n // If focus is already on the input, keep it there so we don't hide the\n // software keyboard when tapping the increment/decrement buttons.\n if (getActiveElement() === inputRef.current) {\n return;\n }\n\n // Otherwise, when using a mouse, move focus to the input.\n // On touch, or with a screen reader, focus the button so that the software\n // keyboard does not appear and the screen reader cursor is not moved off the button.\n if (e.pointerType === 'mouse') {\n inputRef.current?.focus();\n } else {\n e.target.focus();\n }\n };\n\n // Determine the label for the increment and decrement buttons. There are 4 cases:\n //\n // 1. With a visible label that is a string: aria-label: `Increase ${props.label}`\n // 2. With a visible label that is JSX: aria-label: 'Increase', aria-labelledby: '${incrementId} ${labelId}'\n // 3. With an aria-label: aria-label: `Increase ${props['aria-label']}`\n // 4. With an aria-labelledby: aria-label: 'Increase', aria-labelledby: `${incrementId} ${props['aria-labelledby']}`\n //\n // (1) and (2) could possibly be combined and both use aria-labelledby. However, placing the label in\n // the aria-label string rather than using aria-labelledby gives more flexibility to translators to change\n // the order or add additional words around the label if needed.\n let fieldLabel = props['aria-label'] || (typeof props.label === 'string' ? props.label : '');\n let ariaLabelledby: string | undefined;\n if (!fieldLabel) {\n ariaLabelledby = props.label != null ? labelProps.id : props['aria-labelledby'];\n }\n\n let incrementId = useId();\n let decrementId = useId();\n\n let incrementButtonProps: AriaButtonProps = mergeProps(incButtonProps, {\n 'aria-label': incrementAriaLabel || stringFormatter.format('increase', {fieldLabel}).trim(),\n id: ariaLabelledby && !incrementAriaLabel ? incrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !incrementAriaLabel ? `${incrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canIncrement,\n onPressStart: onButtonPressStart\n });\n\n let decrementButtonProps: AriaButtonProps = mergeProps(decButtonProps, {\n 'aria-label': decrementAriaLabel || stringFormatter.format('decrease', {fieldLabel}).trim(),\n id: ariaLabelledby && !decrementAriaLabel ? decrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !decrementAriaLabel ? `${decrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canDecrement,\n onPressStart: onButtonPressStart\n });\n\n return {\n groupProps: {\n ...focusWithinProps,\n role: 'group',\n 'aria-disabled': isDisabled,\n 'aria-invalid': isInvalid ? 'true' : undefined\n },\n labelProps,\n inputProps,\n incrementButtonProps,\n decrementButtonProps,\n errorMessageProps,\n descriptionProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n\nlet numberInput: HTMLInputElement | null = null;\n\nfunction useNativeValidation(\n state: NumberFieldState,\n validationBehavior: 'native' | 'aria' | undefined,\n commitBehavior: 'snap' | 'validate' | undefined,\n inputRef: RefObject<HTMLInputElement | null>,\n min: number | undefined,\n max: number | undefined,\n step: number | undefined,\n value: number | undefined\n) {\n useLayoutEffect(() => {\n let input = inputRef.current;\n if (\n commitBehavior !== 'validate' ||\n state.realtimeValidation.isInvalid ||\n !input ||\n input.disabled\n ) {\n return;\n }\n\n // Create a native number input and use it to implement validation of min/max/step.\n // This lets us get the native validation message provided by the browser instead of needing our own translations.\n if (!numberInput && typeof document !== 'undefined') {\n numberInput = document.createElement('input');\n numberInput.type = 'number';\n }\n\n if (!numberInput) {\n // For TypeScript.\n return;\n }\n\n numberInput.min = min != null && !isNaN(min) ? String(min) : '';\n numberInput.max = max != null && !isNaN(max) ? String(max) : '';\n numberInput.step = step != null && !isNaN(step) ? String(step) : '';\n numberInput.value = value != null && !isNaN(value) ? String(value) : '';\n\n // Merge validity with the visible text input (for other validations like required).\n let valid = input.validity.valid && numberInput.validity.valid;\n let validationMessage = input.validationMessage || numberInput.validationMessage;\n let validity = {\n isInvalid: !valid,\n validationErrors: validationMessage ? [validationMessage] : [],\n validationDetails: {\n badInput: input.validity.badInput,\n customError: input.validity.customError,\n patternMismatch: input.validity.patternMismatch,\n rangeOverflow: numberInput.validity.rangeOverflow,\n rangeUnderflow: numberInput.validity.rangeUnderflow,\n stepMismatch: numberInput.validity.stepMismatch,\n tooLong: input.validity.tooLong,\n tooShort: input.validity.tooShort,\n typeMismatch: input.validity.typeMismatch,\n valueMissing: input.validity.valueMissing,\n valid\n }\n };\n\n state.updateValidation(validity);\n\n // Block form submission if validation behavior is native.\n // This won't overwrite any user-defined validation message because we checked realtimeValidation above.\n if (validationBehavior === 'native' && !numberInput.validity.valid) {\n input.setCustomValidity(numberInput.validationMessage);\n }\n });\n}\n"],"names":[],"version":3,"file":"useNumberField.mjs.map"}
1
+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Q,CAAC,QAAQ;gBACjC,cAAc,MAAM,QAAQ,CAAC,YAAY;gBACzC,cAAc,MAAM,QAAQ,CAAC,YAAY;uBACzC;YACF;QACF;QAEA,MAAM,gBAAgB,CAAC;QAEvB,0DAA0D;QAC1D,wGAAwG;QACxG,IAAI,uBAAuB,YAAY,CAAC,kCAAY,QAAQ,CAAC,KAAK,EAChE,MAAM,iBAAiB,CAAC,kCAAY,iBAAiB;IAEzD;AACF","sources":["packages/react-aria/src/numberfield/useNumberField.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {announce} from '../live-announcer/LiveAnnouncer';\nimport {AriaButtonProps} from '../button/useButton';\nimport {\n AriaLabelingProps,\n DOMAttributes,\n DOMProps,\n GroupDOMAttributes,\n TextInputDOMEvents,\n TextInputDOMProps,\n ValidationResult\n} from '@react-types/shared';\nimport {chain} from '../utils/chain';\nimport {\n type ClipboardEvent,\n type ClipboardEventHandler,\n InputHTMLAttributes,\n LabelHTMLAttributes,\n RefObject,\n useCallback,\n useMemo,\n useState\n} from 'react';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {flushSync} from 'react-dom';\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport intlMessages from '../../intl/numberfield/*.json';\nimport {isAndroid, isIOS, isIPhone} from '../utils/platform';\nimport {mergeProps} from '../utils/mergeProps';\nimport {NumberFieldProps, NumberFieldState} from 'react-stately/useNumberFieldState';\nimport {privateValidationStateProp} from 'react-stately/private/form/useFormValidationState';\nimport {useFocus} from '../interactions/useFocus';\nimport {useFocusWithin} from '../interactions/useFocusWithin';\nimport {useFormattedTextField} from '../textfield/useFormattedTextField';\nimport {useFormReset} from '../utils/useFormReset';\nimport {useId} from '../utils/useId';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useNumberFormatter} from '../i18n/useNumberFormatter';\nimport {useScrollWheel} from '../interactions/useScrollWheel';\nimport {useSpinButton} from '../spinbutton/useSpinButton';\n\nexport interface AriaNumberFieldProps\n extends NumberFieldProps, DOMProps, AriaLabelingProps, TextInputDOMEvents {\n /**\n * A custom aria-label for the decrement button. If not provided, the localized string \"Decrement\"\n * is used.\n */\n decrementAriaLabel?: string;\n /**\n * A custom aria-label for the increment button. If not provided, the localized string \"Increment\"\n * is used.\n */\n incrementAriaLabel?: string;\n /**\n * Enables or disables changing the value with scroll.\n */\n isWheelDisabled?: boolean;\n}\n\nexport interface NumberFieldAria extends ValidationResult {\n /** Props for the label element. */\n labelProps: LabelHTMLAttributes<HTMLLabelElement>;\n /** Props for the group wrapper around the input and stepper buttons. */\n groupProps: GroupDOMAttributes;\n /** Props for the input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>;\n /** Props for the increment button, to be passed to `useButton`. */\n incrementButtonProps: AriaButtonProps;\n /** Props for the decrement button, to be passed to `useButton`. */\n decrementButtonProps: AriaButtonProps;\n /** Props for the number field's description element, if any. */\n descriptionProps: DOMAttributes;\n /** Props for the number field's error message element, if any. */\n errorMessageProps: DOMAttributes;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a number field component. Number\n * fields allow users to enter a number, and increment or decrement the value using stepper\n * buttons.\n */\nexport function useNumberField(\n props: AriaNumberFieldProps,\n state: NumberFieldState,\n inputRef: RefObject<HTMLInputElement | null>\n): NumberFieldAria {\n let {\n id,\n decrementAriaLabel,\n incrementAriaLabel,\n isDisabled,\n isReadOnly,\n isRequired,\n minValue,\n maxValue,\n autoFocus,\n label,\n formatOptions,\n onBlur = () => {},\n onFocus,\n onFocusChange,\n onKeyDown,\n onKeyUp,\n description,\n errorMessage,\n isWheelDisabled,\n ...otherProps\n } = props;\n\n let {\n increment,\n incrementToMax,\n decrement,\n decrementToMin,\n numberValue,\n inputValue,\n commit,\n commitValidation\n } = state;\n\n const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/numberfield');\n let commitAndAnnounce = useCallback(() => {\n let oldValue = inputRef.current?.value ?? '';\n // Set input value to normalized valid value\n flushSync(() => {\n commit();\n });\n\n if (inputRef.current?.value !== oldValue) {\n announce(inputRef.current?.value ?? '', 'assertive');\n }\n }, [commit, inputRef]);\n\n let inputId = useId(id);\n let {focusProps} = useFocus({\n onBlur() {\n commitAndAnnounce();\n }\n });\n\n let numberFormatter = useNumberFormatter(formatOptions);\n let intlOptions = useMemo(() => numberFormatter.resolvedOptions(), [numberFormatter]);\n\n // Replace negative textValue formatted using currencySign: 'accounting'\n // with a textValue that can be announced using a minus sign.\n let textValueFormatter = useNumberFormatter({...formatOptions, currencySign: undefined});\n let textValue = useMemo(\n () => (isNaN(numberValue) ? '' : textValueFormatter.format(numberValue)),\n [textValueFormatter, numberValue]\n );\n\n let {\n spinButtonProps,\n incrementButtonProps: incButtonProps,\n decrementButtonProps: decButtonProps\n } = useSpinButton({\n isDisabled,\n isReadOnly,\n isRequired,\n maxValue,\n minValue,\n onIncrement: increment,\n onIncrementToMax: incrementToMax,\n onDecrement: decrement,\n onDecrementToMin: decrementToMin,\n value: numberValue,\n textValue\n });\n\n let [focusWithin, setFocusWithin] = useState(false);\n let {focusWithinProps} = useFocusWithin({isDisabled, onFocusWithinChange: setFocusWithin});\n\n let onWheel = useCallback(\n e => {\n // if on a trackpad, users can scroll in both X and Y at once, check the magnitude of the change\n // if it's mostly in the X direction, then just return, the user probably doesn't mean to inc/dec\n // this isn't perfect, events come in fast with small deltas and a part of the scroll may give a false indication\n // especially if the user is scrolling near 45deg\n if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) {\n return;\n }\n if (e.deltaY > 0) {\n increment();\n } else if (e.deltaY < 0) {\n decrement();\n }\n },\n [decrement, increment]\n );\n // If the input isn't supposed to receive input, disable scrolling.\n let scrollingDisabled = isWheelDisabled || isDisabled || isReadOnly || !focusWithin;\n useScrollWheel({onScroll: onWheel, isDisabled: scrollingDisabled}, inputRef);\n\n // The inputMode attribute influences the software keyboard that is shown on touch devices.\n // Browsers and operating systems are quite inconsistent about what keys are available, however.\n // We choose between numeric and decimal based on whether we allow negative and fractional numbers,\n // and based on testing on various devices to determine what keys are available in each inputMode.\n let hasDecimals = (intlOptions.maximumFractionDigits ?? 0) > 0;\n let hasNegative = state.minValue === undefined || isNaN(state.minValue) || state.minValue < 0;\n let inputMode: TextInputDOMProps['inputMode'] = 'numeric';\n if (isIPhone()) {\n // iPhone doesn't have a minus sign in either numeric or decimal.\n // Note this is only for iPhone, not iPad, which always has both\n // minus and decimal in numeric.\n if (hasNegative) {\n inputMode = 'text';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n } else if (isAndroid()) {\n // Android numeric has both a decimal point and minus key.\n // decimal does not have a minus key.\n if (hasNegative) {\n inputMode = 'numeric';\n } else if (hasDecimals) {\n inputMode = 'decimal';\n }\n }\n\n let onChange = value => {\n if (state.validate(value)) {\n state.setInputValue(value);\n }\n };\n\n let onPaste: ClipboardEventHandler<HTMLInputElement> = (e: ClipboardEvent<HTMLInputElement>) => {\n props.onPaste?.(e);\n let inputElement = getEventTarget(e) as HTMLInputElement;\n // we can only handle the case where the paste takes over the entire input, otherwise things get very complicated\n // trying to calculate the new string based on what the paste is replacing and where in the source string it is\n if (\n inputElement &&\n (inputElement.selectionEnd ?? -1) - (inputElement.selectionStart ?? 0) ===\n inputElement.value.length\n ) {\n e.preventDefault();\n // commit so that the user gets to see what it formats to immediately\n // paste happens before inputRef's value is updated, so have to prevent the default and do it ourselves\n // spin button will then handle announcing the new value, this should work with controlled state as well\n // because the announcement is done as a result of the new rendered input value if there is one\n commit(e.clipboardData?.getData?.('text/plain')?.trim() ?? '');\n }\n };\n\n let domProps = filterDOMProps(props);\n let onKeyDownEnter = useCallback(\n e => {\n if (e.nativeEvent.isComposing) {\n return;\n }\n\n if (e.key === 'Enter') {\n flushSync(() => {\n commit();\n });\n commitValidation();\n } else {\n e.continuePropagation();\n }\n },\n [commit, commitValidation]\n );\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {\n labelProps,\n inputProps: textFieldProps,\n descriptionProps,\n errorMessageProps\n } = useFormattedTextField(\n {\n ...otherProps,\n ...domProps,\n // These props are added to a hidden input rather than the formatted textfield.\n name: undefined,\n form: undefined,\n label,\n autoFocus,\n isDisabled,\n isReadOnly,\n isRequired,\n validate: undefined,\n [privateValidationStateProp]: state,\n value: inputValue,\n defaultValue: '!', // an invalid value so that form reset is ignored in onChange above\n autoComplete: 'off',\n 'aria-label': props['aria-label'] || undefined,\n 'aria-labelledby': props['aria-labelledby'] || undefined,\n id: inputId,\n type: 'text', // Can't use type=\"number\" because then we can't have things like $ in the field.\n inputMode,\n onChange,\n onBlur,\n onFocus,\n onFocusChange,\n onKeyDown: useMemo(() => chain(onKeyDownEnter, onKeyDown), [onKeyDownEnter, onKeyDown]),\n onKeyUp,\n onPaste,\n description,\n errorMessage\n },\n state,\n inputRef\n );\n\n useFormReset(inputRef, state.defaultNumberValue, state.setNumberValue);\n useNativeValidation(\n state,\n props.validationBehavior,\n props.commitBehavior,\n inputRef,\n state.minValue,\n state.maxValue,\n props.step,\n state.numberValue\n );\n\n let inputProps: InputHTMLAttributes<HTMLInputElement> = mergeProps(\n spinButtonProps,\n focusProps,\n textFieldProps,\n {\n // override the spinbutton role, we can't focus a spin button with VO\n role: null,\n // ignore aria-roledescription on iOS so that required state will announce when it is present\n 'aria-roledescription': !isIOS() ? stringFormatter.format('numberField') : null,\n 'aria-valuemax': null,\n 'aria-valuemin': null,\n 'aria-valuenow': null,\n 'aria-valuetext': null,\n autoCorrect: 'off',\n spellCheck: 'false'\n }\n );\n\n if (props.validationBehavior === 'native') {\n inputProps['aria-required'] = undefined;\n }\n\n let onButtonPressStart = e => {\n // If focus is already on the input, keep it there so we don't hide the\n // software keyboard when tapping the increment/decrement buttons.\n if (getActiveElement() === inputRef.current) {\n return;\n }\n\n // Otherwise, when using a mouse, move focus to the input.\n // On touch, or with a screen reader, focus the button so that the software\n // keyboard does not appear and the screen reader cursor is not moved off the button.\n if (e.pointerType === 'mouse') {\n inputRef.current?.focus();\n } else {\n e.target.focus();\n }\n };\n\n // Determine the label for the increment and decrement buttons. There are 4 cases:\n //\n // 1. With a visible label that is a string: aria-label: `Increase ${props.label}`\n // 2. With a visible label that is JSX: aria-label: 'Increase', aria-labelledby: '${incrementId} ${labelId}'\n // 3. With an aria-label: aria-label: `Increase ${props['aria-label']}`\n // 4. With an aria-labelledby: aria-label: 'Increase', aria-labelledby: `${incrementId} ${props['aria-labelledby']}`\n //\n // (1) and (2) could possibly be combined and both use aria-labelledby. However, placing the label in\n // the aria-label string rather than using aria-labelledby gives more flexibility to translators to change\n // the order or add additional words around the label if needed.\n let fieldLabel = props['aria-label'] || (typeof props.label === 'string' ? props.label : '');\n let ariaLabelledby: string | undefined;\n if (!fieldLabel) {\n ariaLabelledby = props.label != null ? labelProps.id : props['aria-labelledby'];\n }\n\n let incrementId = useId();\n let decrementId = useId();\n\n let incrementButtonProps: AriaButtonProps = mergeProps(incButtonProps, {\n 'aria-label': incrementAriaLabel || stringFormatter.format('increase', {fieldLabel}).trim(),\n id: ariaLabelledby && !incrementAriaLabel ? incrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !incrementAriaLabel ? `${incrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canIncrement,\n onPressStart: onButtonPressStart\n });\n\n let decrementButtonProps: AriaButtonProps = mergeProps(decButtonProps, {\n 'aria-label': decrementAriaLabel || stringFormatter.format('decrease', {fieldLabel}).trim(),\n id: ariaLabelledby && !decrementAriaLabel ? decrementId : null,\n 'aria-labelledby':\n ariaLabelledby && !decrementAriaLabel ? `${decrementId} ${ariaLabelledby}` : null,\n 'aria-controls': inputId,\n excludeFromTabOrder: true,\n preventFocusOnPress: true,\n allowFocusWhenDisabled: true,\n isDisabled: !state.canDecrement,\n onPressStart: onButtonPressStart\n });\n\n return {\n groupProps: {\n ...focusWithinProps,\n role: 'group',\n 'aria-disabled': isDisabled,\n 'aria-invalid': isInvalid ? 'true' : undefined\n },\n labelProps,\n inputProps,\n incrementButtonProps,\n decrementButtonProps,\n errorMessageProps,\n descriptionProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n\nlet numberInput: HTMLInputElement | null = null;\n\nfunction useNativeValidation(\n state: NumberFieldState,\n validationBehavior: 'native' | 'aria' | undefined,\n commitBehavior: 'snap' | 'validate' | undefined,\n inputRef: RefObject<HTMLInputElement | null>,\n min: number | undefined,\n max: number | undefined,\n step: number | undefined,\n value: number | undefined\n) {\n useLayoutEffect(() => {\n let input = inputRef.current;\n if (\n commitBehavior !== 'validate' ||\n state.realtimeValidation.isInvalid ||\n !input ||\n input.disabled\n ) {\n return;\n }\n\n // Create a native number input and use it to implement validation of min/max/step.\n // This lets us get the native validation message provided by the browser instead of needing our own translations.\n if (!numberInput && typeof document !== 'undefined') {\n numberInput = document.createElement('input');\n numberInput.type = 'number';\n }\n\n if (!numberInput) {\n // For TypeScript.\n return;\n }\n\n numberInput.min = min != null && !isNaN(min) ? String(min) : '';\n numberInput.max = max != null && !isNaN(max) ? String(max) : '';\n numberInput.step = step != null && !isNaN(step) ? String(step) : '';\n numberInput.value = value != null && !isNaN(value) ? String(value) : '';\n\n // Merge validity with the visible text input (for other validations like required).\n let valid = input.validity.valid && numberInput.validity.valid;\n let validationMessage = input.validationMessage || numberInput.validationMessage;\n let validity = {\n isInvalid: !valid,\n validationErrors: validationMessage ? [validationMessage] : [],\n validationDetails: {\n badInput: input.validity.badInput,\n customError: input.validity.customError,\n patternMismatch: input.validity.patternMismatch,\n rangeOverflow: numberInput.validity.rangeOverflow,\n rangeUnderflow: numberInput.validity.rangeUnderflow,\n stepMismatch: numberInput.validity.stepMismatch,\n tooLong: input.validity.tooLong,\n tooShort: input.validity.tooShort,\n typeMismatch: input.validity.typeMismatch,\n valueMissing: input.validity.valueMissing,\n valid\n }\n };\n\n state.updateValidation(validity);\n\n // Block form submission if validation behavior is native.\n // This won't overwrite any user-defined validation message because we checked realtimeValidation above.\n if (validationBehavior === 'native' && !numberInput.validity.valid) {\n input.setCustomValidity(numberInput.validationMessage);\n }\n });\n}\n"],"names":[],"version":3,"file":"useNumberField.mjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAoBM,SAAS,0CAAc,KAAyB;IACrD,IAAI,aAAC,SAAS,EAAE,GAAG,YAAW,GAAG;IACjC,IAAI,kBAAkB,CAAA,GAAA,qDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAEhE,IAAI,SAAS,CAAA,GAAA,mCAAQ,EAAE,YAAY,gBAAgB,MAAM,CAAC;IAE1D,IAAI,UAAU;QACZ,IAAI,WACF;IAEJ;IAEA,qBACE,0DAAC,CAAA,GAAA,wCAAa,uBACZ,0DAAC;QAAQ,GAAG,MAAM;QAAE,UAAU;QAAI,SAAS;QAAS,OAAO;YAAC,OAAO;YAAG,QAAQ;QAAC;;AAGrF","sources":["packages/react-aria/src/overlays/DismissButton.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMProps} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../../intl/overlays/*.json';\nimport React, {JSX} from 'react';\nimport {useLabels} from '../utils/useLabels';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {VisuallyHidden} from '../visually-hidden/VisuallyHidden';\n\nexport interface DismissButtonProps extends AriaLabelingProps, DOMProps {\n /** Called when the dismiss button is activated. */\n onDismiss?: () => void;\n}\n\n/**\n * A visually hidden button that can be used to allow screen reader\n * users to dismiss a modal or popup when there is no visual\n * affordance to do so.\n */\nexport function DismissButton(props: DismissButtonProps): JSX.Element {\n let {onDismiss, ...otherProps} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/overlays');\n\n let labels = useLabels(otherProps, stringFormatter.format('dismiss'));\n\n let onClick = () => {\n if (onDismiss) {\n onDismiss();\n }\n };\n\n return (\n <VisuallyHidden>\n <button {...labels} tabIndex={-1} onClick={onClick} style={{width: 1, height: 1}} />\n </VisuallyHidden>\n );\n}\n"],"names":[],"version":3,"file":"DismissButton.cjs.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAmBM,SAAS,0CAAc,KAAyB;IACrD,IAAI,aAAC,SAAS,EAAE,GAAG,YAAW,GAAG;IACjC,IAAI,kBAAkB,CAAA,GAAA,qDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAEhE,IAAI,SAAS,CAAA,GAAA,mCAAQ,EAAE,YAAY,gBAAgB,MAAM,CAAC;IAE1D,IAAI,UAAU;QACZ,IAAI,WACF;IAEJ;IAEA,qBACE,0DAAC,CAAA,GAAA,wCAAa,uBACZ,0DAAC;QAAQ,GAAG,MAAM;QAAE,UAAU;QAAI,SAAS;QAAS,OAAO;YAAC,OAAO;YAAG,QAAQ;QAAC;;AAGrF","sources":["packages/react-aria/src/overlays/DismissButton.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMProps} from '@react-types/shared';\nimport intlMessages from '../../intl/overlays/*.json';\nimport React, {JSX} from 'react';\nimport {useLabels} from '../utils/useLabels';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {VisuallyHidden} from '../visually-hidden/VisuallyHidden';\n\nexport interface DismissButtonProps extends AriaLabelingProps, DOMProps {\n /** Called when the dismiss button is activated. */\n onDismiss?: () => void;\n}\n\n/**\n * A visually hidden button that can be used to allow screen reader\n * users to dismiss a modal or popup when there is no visual\n * affordance to do so.\n */\nexport function DismissButton(props: DismissButtonProps): JSX.Element {\n let {onDismiss, ...otherProps} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/overlays');\n\n let labels = useLabels(otherProps, stringFormatter.format('dismiss'));\n\n let onClick = () => {\n if (onDismiss) {\n onDismiss();\n }\n };\n\n return (\n <VisuallyHidden>\n <button {...labels} tabIndex={-1} onClick={onClick} style={{width: 1, height: 1}} />\n </VisuallyHidden>\n );\n}\n"],"names":[],"version":3,"file":"DismissButton.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAoBM,SAAS,0CAAc,KAAyB;IACrD,IAAI,aAAC,SAAS,EAAE,GAAG,YAAW,GAAG;IACjC,IAAI,kBAAkB,CAAA,GAAA,yCAA0B,EAAE,CAAA,GAAA,8CAAW,GAAG;IAEhE,IAAI,SAAS,CAAA,GAAA,yCAAQ,EAAE,YAAY,gBAAgB,MAAM,CAAC;IAE1D,IAAI,UAAU;QACZ,IAAI,WACF;IAEJ;IAEA,qBACE,gCAAC,CAAA,GAAA,yCAAa,uBACZ,gCAAC;QAAQ,GAAG,MAAM;QAAE,UAAU;QAAI,SAAS;QAAS,OAAO;YAAC,OAAO;YAAG,QAAQ;QAAC;;AAGrF","sources":["packages/react-aria/src/overlays/DismissButton.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMProps} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../../intl/overlays/*.json';\nimport React, {JSX} from 'react';\nimport {useLabels} from '../utils/useLabels';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {VisuallyHidden} from '../visually-hidden/VisuallyHidden';\n\nexport interface DismissButtonProps extends AriaLabelingProps, DOMProps {\n /** Called when the dismiss button is activated. */\n onDismiss?: () => void;\n}\n\n/**\n * A visually hidden button that can be used to allow screen reader\n * users to dismiss a modal or popup when there is no visual\n * affordance to do so.\n */\nexport function DismissButton(props: DismissButtonProps): JSX.Element {\n let {onDismiss, ...otherProps} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/overlays');\n\n let labels = useLabels(otherProps, stringFormatter.format('dismiss'));\n\n let onClick = () => {\n if (onDismiss) {\n onDismiss();\n }\n };\n\n return (\n <VisuallyHidden>\n <button {...labels} tabIndex={-1} onClick={onClick} style={{width: 1, height: 1}} />\n </VisuallyHidden>\n );\n}\n"],"names":[],"version":3,"file":"DismissButton.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAmBM,SAAS,0CAAc,KAAyB;IACrD,IAAI,aAAC,SAAS,EAAE,GAAG,YAAW,GAAG;IACjC,IAAI,kBAAkB,CAAA,GAAA,yCAA0B,EAAE,CAAA,GAAA,8CAAW,GAAG;IAEhE,IAAI,SAAS,CAAA,GAAA,yCAAQ,EAAE,YAAY,gBAAgB,MAAM,CAAC;IAE1D,IAAI,UAAU;QACZ,IAAI,WACF;IAEJ;IAEA,qBACE,gCAAC,CAAA,GAAA,yCAAa,uBACZ,gCAAC;QAAQ,GAAG,MAAM;QAAE,UAAU;QAAI,SAAS;QAAS,OAAO;YAAC,OAAO;YAAG,QAAQ;QAAC;;AAGrF","sources":["packages/react-aria/src/overlays/DismissButton.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMProps} from '@react-types/shared';\nimport intlMessages from '../../intl/overlays/*.json';\nimport React, {JSX} from 'react';\nimport {useLabels} from '../utils/useLabels';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {VisuallyHidden} from '../visually-hidden/VisuallyHidden';\n\nexport interface DismissButtonProps extends AriaLabelingProps, DOMProps {\n /** Called when the dismiss button is activated. */\n onDismiss?: () => void;\n}\n\n/**\n * A visually hidden button that can be used to allow screen reader\n * users to dismiss a modal or popup when there is no visual\n * affordance to do so.\n */\nexport function DismissButton(props: DismissButtonProps): JSX.Element {\n let {onDismiss, ...otherProps} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/overlays');\n\n let labels = useLabels(otherProps, stringFormatter.format('dismiss'));\n\n let onClick = () => {\n if (onDismiss) {\n onDismiss();\n }\n };\n\n return (\n <VisuallyHidden>\n <button {...labels} tabIndex={-1} onClick={onClick} style={{width: 1, height: 1}} />\n </VisuallyHidden>\n );\n}\n"],"names":[],"version":3,"file":"DismissButton.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAoBM,SAAS,0CAAc,KAAyB;IACrD,IAAI,aAAC,SAAS,EAAE,GAAG,YAAW,GAAG;IACjC,IAAI,kBAAkB,CAAA,GAAA,yCAA0B,EAAE,CAAA,GAAA,+CAAW,GAAG;IAEhE,IAAI,SAAS,CAAA,GAAA,yCAAQ,EAAE,YAAY,gBAAgB,MAAM,CAAC;IAE1D,IAAI,UAAU;QACZ,IAAI,WACF;IAEJ;IAEA,qBACE,gCAAC,CAAA,GAAA,yCAAa,uBACZ,gCAAC;QAAQ,GAAG,MAAM;QAAE,UAAU;QAAI,SAAS;QAAS,OAAO;YAAC,OAAO;YAAG,QAAQ;QAAC;;AAGrF","sources":["packages/react-aria/src/overlays/DismissButton.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMProps} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../../intl/overlays/*.json';\nimport React, {JSX} from 'react';\nimport {useLabels} from '../utils/useLabels';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {VisuallyHidden} from '../visually-hidden/VisuallyHidden';\n\nexport interface DismissButtonProps extends AriaLabelingProps, DOMProps {\n /** Called when the dismiss button is activated. */\n onDismiss?: () => void;\n}\n\n/**\n * A visually hidden button that can be used to allow screen reader\n * users to dismiss a modal or popup when there is no visual\n * affordance to do so.\n */\nexport function DismissButton(props: DismissButtonProps): JSX.Element {\n let {onDismiss, ...otherProps} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/overlays');\n\n let labels = useLabels(otherProps, stringFormatter.format('dismiss'));\n\n let onClick = () => {\n if (onDismiss) {\n onDismiss();\n }\n };\n\n return (\n <VisuallyHidden>\n <button {...labels} tabIndex={-1} onClick={onClick} style={{width: 1, height: 1}} />\n </VisuallyHidden>\n );\n}\n"],"names":[],"version":3,"file":"DismissButton.mjs.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAmBM,SAAS,0CAAc,KAAyB;IACrD,IAAI,aAAC,SAAS,EAAE,GAAG,YAAW,GAAG;IACjC,IAAI,kBAAkB,CAAA,GAAA,yCAA0B,EAAE,CAAA,GAAA,+CAAW,GAAG;IAEhE,IAAI,SAAS,CAAA,GAAA,yCAAQ,EAAE,YAAY,gBAAgB,MAAM,CAAC;IAE1D,IAAI,UAAU;QACZ,IAAI,WACF;IAEJ;IAEA,qBACE,gCAAC,CAAA,GAAA,yCAAa,uBACZ,gCAAC;QAAQ,GAAG,MAAM;QAAE,UAAU;QAAI,SAAS;QAAS,OAAO;YAAC,OAAO;YAAG,QAAQ;QAAC;;AAGrF","sources":["packages/react-aria/src/overlays/DismissButton.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps, DOMProps} from '@react-types/shared';\nimport intlMessages from '../../intl/overlays/*.json';\nimport React, {JSX} from 'react';\nimport {useLabels} from '../utils/useLabels';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {VisuallyHidden} from '../visually-hidden/VisuallyHidden';\n\nexport interface DismissButtonProps extends AriaLabelingProps, DOMProps {\n /** Called when the dismiss button is activated. */\n onDismiss?: () => void;\n}\n\n/**\n * A visually hidden button that can be used to allow screen reader\n * users to dismiss a modal or popup when there is no visual\n * affordance to do so.\n */\nexport function DismissButton(props: DismissButtonProps): JSX.Element {\n let {onDismiss, ...otherProps} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/overlays');\n\n let labels = useLabels(otherProps, stringFormatter.format('dismiss'));\n\n let onClick = () => {\n if (onDismiss) {\n onDismiss();\n }\n };\n\n return (\n <VisuallyHidden>\n <button {...labels} tabIndex={-1} onClick={onClick} style={{width: 1, height: 1}} />\n </VisuallyHidden>\n );\n}\n"],"names":[],"version":3,"file":"DismissButton.mjs.map"}
@@ -297,13 +297,13 @@ function $43b053bcc899501d$export$6839422d1f33cee9(placementInput, childOffset,
297
297
  };
298
298
  }
299
299
  function $43b053bcc899501d$export$b3ceb0cbf1056d98(opts) {
300
- let { placement: placement, targetNode: targetNode, overlayNode: overlayNode, scrollNode: scrollNode, padding: padding, shouldFlip: shouldFlip, boundaryElement: boundaryElement, offset: offset, crossOffset: crossOffset, maxHeight: maxHeight, arrowSize: arrowSize = 0, arrowBoundaryOffset: arrowBoundaryOffset = 0 } = opts;
300
+ let { placement: placement, targetNode: targetNode, overlayNode: overlayNode, scrollNode: scrollNode, padding: padding, shouldFlip: shouldFlip, boundaryElement: boundaryElement, offset: offset, crossOffset: crossOffset, maxHeight: maxHeight, arrowSize: arrowSize = 0, arrowBoundaryOffset: arrowBoundaryOffset = 0, targetRect: targetRect } = opts;
301
301
  let visualViewport = $43b053bcc899501d$var$getVisualViewport();
302
302
  let container = overlayNode instanceof HTMLElement ? $43b053bcc899501d$var$getContainingBlock(overlayNode) : document.documentElement;
303
303
  let isViewportContainer = container === document.documentElement;
304
304
  const containerPositionStyle = window.getComputedStyle(container).position;
305
305
  let isContainerPositioned = !!containerPositionStyle && containerPositionStyle !== 'static';
306
- let childOffset = isViewportContainer ? $43b053bcc899501d$var$getOffset(targetNode, false) : $43b053bcc899501d$var$getPosition(targetNode, container, false);
306
+ let childOffset = isViewportContainer ? $43b053bcc899501d$var$getOffset(targetNode, false, targetRect) : $43b053bcc899501d$var$getPosition(targetNode, container, false, targetRect);
307
307
  if (!isViewportContainer) {
308
308
  let { marginTop: marginTop, marginLeft: marginLeft } = window.getComputedStyle(targetNode);
309
309
  childOffset.top += parseInt(marginTop, 10) || 0;
@@ -366,8 +366,8 @@ function $43b053bcc899501d$export$4b834cebd9e5cebe(node, ignoreScale) {
366
366
  height: height
367
367
  };
368
368
  }
369
- function $43b053bcc899501d$var$getOffset(node, ignoreScale) {
370
- let { top: top, left: left, width: width, height: height } = $43b053bcc899501d$export$4b834cebd9e5cebe(node, ignoreScale);
369
+ function $43b053bcc899501d$var$getOffset(node, ignoreScale, overrideRect) {
370
+ let { top: top, left: left, width: width, height: height } = overrideRect || $43b053bcc899501d$export$4b834cebd9e5cebe(node, ignoreScale);
371
371
  let { scrollTop: scrollTop, scrollLeft: scrollLeft, clientTop: clientTop, clientLeft: clientLeft } = document.documentElement;
372
372
  return {
373
373
  top: top + scrollTop - clientTop,
@@ -376,12 +376,12 @@ function $43b053bcc899501d$var$getOffset(node, ignoreScale) {
376
376
  height: height
377
377
  };
378
378
  }
379
- function $43b053bcc899501d$var$getPosition(node, parent, ignoreScale) {
379
+ function $43b053bcc899501d$var$getPosition(node, parent, ignoreScale, overrideRect) {
380
380
  let style = window.getComputedStyle(node);
381
381
  let offset;
382
- if (style.position === 'fixed') offset = $43b053bcc899501d$export$4b834cebd9e5cebe(node, ignoreScale);
382
+ if (style.position === 'fixed') offset = overrideRect || $43b053bcc899501d$export$4b834cebd9e5cebe(node, ignoreScale);
383
383
  else {
384
- offset = $43b053bcc899501d$var$getOffset(node, ignoreScale);
384
+ offset = $43b053bcc899501d$var$getOffset(node, ignoreScale, overrideRect);
385
385
  let parentOffset = $43b053bcc899501d$var$getOffset(parent, ignoreScale);
386
386
  let parentStyle = window.getComputedStyle(parent);
387
387
  parentOffset.top += (parseInt(parentStyle.borderTopWidth, 10) || 0) - parent.scrollTop;