@octanejs/aria 0.0.1 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -3
- package/src/breadcrumbs/useBreadcrumbItem.ts +95 -0
- package/src/breadcrumbs/useBreadcrumbs.ts +51 -0
- package/src/button/useButton.ts +273 -0
- package/src/button/useToggleButton.ts +131 -0
- package/src/button/useToggleButtonGroup.ts +131 -0
- package/src/checkbox/useCheckbox.ts +114 -0
- package/src/checkbox/useCheckboxGroup.ts +107 -0
- package/src/checkbox/useCheckboxGroupItem.ts +132 -0
- package/src/checkbox/utils.ts +15 -0
- package/src/combobox/useComboBox.ts +602 -0
- package/src/dialog/useDialog.ts +147 -0
- package/src/disclosure/useDisclosure.ts +180 -0
- package/src/focus/FocusRing.ts +69 -0
- package/src/focus/FocusScope.ts +1205 -0
- package/src/focus/useFocusRing.ts +125 -0
- package/src/focus/useHasTabbableChild.ts +82 -0
- package/src/focus/virtualFocus.ts +38 -0
- package/src/form/useFormValidation.ts +205 -0
- package/src/grid/useGridSelectionAnnouncement.ts +177 -0
- package/src/grid/useGridSelectionCheckbox.ts +86 -0
- package/src/grid/useHighlightSelectionDescription.ts +81 -0
- package/src/gridlist/useGridList.ts +236 -0
- package/src/gridlist/useGridListItem.ts +512 -0
- package/src/gridlist/useGridListSection.ts +78 -0
- package/src/gridlist/useGridListSelectionCheckbox.ts +47 -0
- package/src/gridlist/utils.ts +36 -0
- package/src/i18n/I18nProvider.ts +97 -0
- package/src/i18n/server.ts +115 -0
- package/src/i18n/useCollator.ts +42 -0
- package/src/i18n/useDateFormatter.ts +64 -0
- package/src/i18n/useDefaultLocale.ts +93 -0
- package/src/i18n/useFilter.ts +107 -0
- package/src/i18n/useListFormatter.ts +33 -0
- package/src/i18n/useLocalizedStringFormatter.ts +90 -0
- package/src/i18n/useNumberFormatter.ts +33 -0
- package/src/i18n/utils.ts +67 -0
- package/src/index.ts +268 -0
- package/src/intl/breadcrumbs/ar-AE.json +3 -0
- package/src/intl/breadcrumbs/bg-BG.json +3 -0
- package/src/intl/breadcrumbs/cs-CZ.json +3 -0
- package/src/intl/breadcrumbs/da-DK.json +3 -0
- package/src/intl/breadcrumbs/de-DE.json +3 -0
- package/src/intl/breadcrumbs/el-GR.json +3 -0
- package/src/intl/breadcrumbs/en-US.json +3 -0
- package/src/intl/breadcrumbs/es-ES.json +3 -0
- package/src/intl/breadcrumbs/et-EE.json +3 -0
- package/src/intl/breadcrumbs/fi-FI.json +3 -0
- package/src/intl/breadcrumbs/fr-FR.json +3 -0
- package/src/intl/breadcrumbs/he-IL.json +3 -0
- package/src/intl/breadcrumbs/hr-HR.json +3 -0
- package/src/intl/breadcrumbs/hu-HU.json +3 -0
- package/src/intl/breadcrumbs/index.ts +75 -0
- package/src/intl/breadcrumbs/it-IT.json +3 -0
- package/src/intl/breadcrumbs/ja-JP.json +3 -0
- package/src/intl/breadcrumbs/ko-KR.json +3 -0
- package/src/intl/breadcrumbs/lt-LT.json +3 -0
- package/src/intl/breadcrumbs/lv-LV.json +3 -0
- package/src/intl/breadcrumbs/nb-NO.json +3 -0
- package/src/intl/breadcrumbs/nl-NL.json +3 -0
- package/src/intl/breadcrumbs/pl-PL.json +3 -0
- package/src/intl/breadcrumbs/pt-BR.json +3 -0
- package/src/intl/breadcrumbs/pt-PT.json +3 -0
- package/src/intl/breadcrumbs/ro-RO.json +3 -0
- package/src/intl/breadcrumbs/ru-RU.json +3 -0
- package/src/intl/breadcrumbs/sk-SK.json +3 -0
- package/src/intl/breadcrumbs/sl-SI.json +3 -0
- package/src/intl/breadcrumbs/sr-SP.json +3 -0
- package/src/intl/breadcrumbs/sv-SE.json +3 -0
- package/src/intl/breadcrumbs/tr-TR.json +3 -0
- package/src/intl/breadcrumbs/uk-UA.json +3 -0
- package/src/intl/breadcrumbs/zh-CN.json +3 -0
- package/src/intl/breadcrumbs/zh-TW.json +3 -0
- package/src/intl/combobox/ar-AE.json +7 -0
- package/src/intl/combobox/bg-BG.json +7 -0
- package/src/intl/combobox/cs-CZ.json +7 -0
- package/src/intl/combobox/da-DK.json +7 -0
- package/src/intl/combobox/de-DE.json +7 -0
- package/src/intl/combobox/el-GR.json +7 -0
- package/src/intl/combobox/en-US.json +7 -0
- package/src/intl/combobox/es-ES.json +7 -0
- package/src/intl/combobox/et-EE.json +7 -0
- package/src/intl/combobox/fi-FI.json +7 -0
- package/src/intl/combobox/fr-FR.json +7 -0
- package/src/intl/combobox/he-IL.json +7 -0
- package/src/intl/combobox/hr-HR.json +7 -0
- package/src/intl/combobox/hu-HU.json +7 -0
- package/src/intl/combobox/index.ts +75 -0
- package/src/intl/combobox/it-IT.json +7 -0
- package/src/intl/combobox/ja-JP.json +7 -0
- package/src/intl/combobox/ko-KR.json +7 -0
- package/src/intl/combobox/lt-LT.json +7 -0
- package/src/intl/combobox/lv-LV.json +7 -0
- package/src/intl/combobox/nb-NO.json +7 -0
- package/src/intl/combobox/nl-NL.json +7 -0
- package/src/intl/combobox/pl-PL.json +7 -0
- package/src/intl/combobox/pt-BR.json +7 -0
- package/src/intl/combobox/pt-PT.json +7 -0
- package/src/intl/combobox/ro-RO.json +7 -0
- package/src/intl/combobox/ru-RU.json +7 -0
- package/src/intl/combobox/sk-SK.json +7 -0
- package/src/intl/combobox/sl-SI.json +7 -0
- package/src/intl/combobox/sr-SP.json +7 -0
- package/src/intl/combobox/sv-SE.json +7 -0
- package/src/intl/combobox/tr-TR.json +7 -0
- package/src/intl/combobox/uk-UA.json +7 -0
- package/src/intl/combobox/zh-CN.json +7 -0
- package/src/intl/combobox/zh-TW.json +7 -0
- package/src/intl/grid/ar-AE.json +8 -0
- package/src/intl/grid/bg-BG.json +8 -0
- package/src/intl/grid/cs-CZ.json +8 -0
- package/src/intl/grid/da-DK.json +8 -0
- package/src/intl/grid/de-DE.json +8 -0
- package/src/intl/grid/el-GR.json +8 -0
- package/src/intl/grid/en-US.json +8 -0
- package/src/intl/grid/es-ES.json +8 -0
- package/src/intl/grid/et-EE.json +8 -0
- package/src/intl/grid/fi-FI.json +8 -0
- package/src/intl/grid/fr-FR.json +8 -0
- package/src/intl/grid/he-IL.json +8 -0
- package/src/intl/grid/hr-HR.json +8 -0
- package/src/intl/grid/hu-HU.json +8 -0
- package/src/intl/grid/index.ts +75 -0
- package/src/intl/grid/it-IT.json +8 -0
- package/src/intl/grid/ja-JP.json +8 -0
- package/src/intl/grid/ko-KR.json +8 -0
- package/src/intl/grid/lt-LT.json +8 -0
- package/src/intl/grid/lv-LV.json +8 -0
- package/src/intl/grid/nb-NO.json +8 -0
- package/src/intl/grid/nl-NL.json +8 -0
- package/src/intl/grid/pl-PL.json +8 -0
- package/src/intl/grid/pt-BR.json +8 -0
- package/src/intl/grid/pt-PT.json +8 -0
- package/src/intl/grid/ro-RO.json +8 -0
- package/src/intl/grid/ru-RU.json +8 -0
- package/src/intl/grid/sk-SK.json +8 -0
- package/src/intl/grid/sl-SI.json +8 -0
- package/src/intl/grid/sr-SP.json +8 -0
- package/src/intl/grid/sv-SE.json +8 -0
- package/src/intl/grid/tr-TR.json +8 -0
- package/src/intl/grid/uk-UA.json +8 -0
- package/src/intl/grid/zh-CN.json +8 -0
- package/src/intl/grid/zh-TW.json +8 -0
- package/src/intl/gridlist/ar-AE.json +4 -0
- package/src/intl/gridlist/bg-BG.json +4 -0
- package/src/intl/gridlist/cs-CZ.json +4 -0
- package/src/intl/gridlist/da-DK.json +4 -0
- package/src/intl/gridlist/de-DE.json +4 -0
- package/src/intl/gridlist/el-GR.json +4 -0
- package/src/intl/gridlist/en-US.json +4 -0
- package/src/intl/gridlist/es-ES.json +4 -0
- package/src/intl/gridlist/et-EE.json +4 -0
- package/src/intl/gridlist/fi-FI.json +4 -0
- package/src/intl/gridlist/fr-FR.json +4 -0
- package/src/intl/gridlist/he-IL.json +4 -0
- package/src/intl/gridlist/hr-HR.json +4 -0
- package/src/intl/gridlist/hu-HU.json +4 -0
- package/src/intl/gridlist/index.ts +75 -0
- package/src/intl/gridlist/it-IT.json +4 -0
- package/src/intl/gridlist/ja-JP.json +4 -0
- package/src/intl/gridlist/ko-KR.json +4 -0
- package/src/intl/gridlist/lt-LT.json +4 -0
- package/src/intl/gridlist/lv-LV.json +4 -0
- package/src/intl/gridlist/nb-NO.json +4 -0
- package/src/intl/gridlist/nl-NL.json +4 -0
- package/src/intl/gridlist/pl-PL.json +4 -0
- package/src/intl/gridlist/pt-BR.json +4 -0
- package/src/intl/gridlist/pt-PT.json +4 -0
- package/src/intl/gridlist/ro-RO.json +4 -0
- package/src/intl/gridlist/ru-RU.json +4 -0
- package/src/intl/gridlist/sk-SK.json +4 -0
- package/src/intl/gridlist/sl-SI.json +4 -0
- package/src/intl/gridlist/sr-SP.json +4 -0
- package/src/intl/gridlist/sv-SE.json +4 -0
- package/src/intl/gridlist/tr-TR.json +4 -0
- package/src/intl/gridlist/uk-UA.json +4 -0
- package/src/intl/gridlist/zh-CN.json +4 -0
- package/src/intl/gridlist/zh-TW.json +4 -0
- package/src/intl/menu/ar-AE.json +3 -0
- package/src/intl/menu/bg-BG.json +3 -0
- package/src/intl/menu/cs-CZ.json +3 -0
- package/src/intl/menu/da-DK.json +3 -0
- package/src/intl/menu/de-DE.json +3 -0
- package/src/intl/menu/el-GR.json +3 -0
- package/src/intl/menu/en-US.json +3 -0
- package/src/intl/menu/es-ES.json +3 -0
- package/src/intl/menu/et-EE.json +3 -0
- package/src/intl/menu/fi-FI.json +3 -0
- package/src/intl/menu/fr-FR.json +3 -0
- package/src/intl/menu/he-IL.json +3 -0
- package/src/intl/menu/hr-HR.json +3 -0
- package/src/intl/menu/hu-HU.json +3 -0
- package/src/intl/menu/index.ts +75 -0
- package/src/intl/menu/it-IT.json +3 -0
- package/src/intl/menu/ja-JP.json +3 -0
- package/src/intl/menu/ko-KR.json +3 -0
- package/src/intl/menu/lt-LT.json +3 -0
- package/src/intl/menu/lv-LV.json +3 -0
- package/src/intl/menu/nb-NO.json +3 -0
- package/src/intl/menu/nl-NL.json +3 -0
- package/src/intl/menu/pl-PL.json +3 -0
- package/src/intl/menu/pt-BR.json +3 -0
- package/src/intl/menu/pt-PT.json +3 -0
- package/src/intl/menu/ro-RO.json +3 -0
- package/src/intl/menu/ru-RU.json +3 -0
- package/src/intl/menu/sk-SK.json +3 -0
- package/src/intl/menu/sl-SI.json +3 -0
- package/src/intl/menu/sr-SP.json +3 -0
- package/src/intl/menu/sv-SE.json +3 -0
- package/src/intl/menu/tr-TR.json +3 -0
- package/src/intl/menu/uk-UA.json +3 -0
- package/src/intl/menu/zh-CN.json +3 -0
- package/src/intl/menu/zh-TW.json +3 -0
- package/src/intl/numberfield/ar-AE.json +5 -0
- package/src/intl/numberfield/bg-BG.json +5 -0
- package/src/intl/numberfield/cs-CZ.json +5 -0
- package/src/intl/numberfield/da-DK.json +5 -0
- package/src/intl/numberfield/de-DE.json +5 -0
- package/src/intl/numberfield/el-GR.json +5 -0
- package/src/intl/numberfield/en-US.json +5 -0
- package/src/intl/numberfield/es-ES.json +5 -0
- package/src/intl/numberfield/et-EE.json +5 -0
- package/src/intl/numberfield/fi-FI.json +5 -0
- package/src/intl/numberfield/fr-FR.json +5 -0
- package/src/intl/numberfield/he-IL.json +5 -0
- package/src/intl/numberfield/hr-HR.json +5 -0
- package/src/intl/numberfield/hu-HU.json +5 -0
- package/src/intl/numberfield/index.ts +75 -0
- package/src/intl/numberfield/it-IT.json +5 -0
- package/src/intl/numberfield/ja-JP.json +5 -0
- package/src/intl/numberfield/ko-KR.json +5 -0
- package/src/intl/numberfield/lt-LT.json +5 -0
- package/src/intl/numberfield/lv-LV.json +5 -0
- package/src/intl/numberfield/nb-NO.json +5 -0
- package/src/intl/numberfield/nl-NL.json +5 -0
- package/src/intl/numberfield/pl-PL.json +5 -0
- package/src/intl/numberfield/pt-BR.json +5 -0
- package/src/intl/numberfield/pt-PT.json +5 -0
- package/src/intl/numberfield/ro-RO.json +5 -0
- package/src/intl/numberfield/ru-RU.json +5 -0
- package/src/intl/numberfield/sk-SK.json +5 -0
- package/src/intl/numberfield/sl-SI.json +5 -0
- package/src/intl/numberfield/sr-SP.json +5 -0
- package/src/intl/numberfield/sv-SE.json +5 -0
- package/src/intl/numberfield/tr-TR.json +5 -0
- package/src/intl/numberfield/uk-UA.json +5 -0
- package/src/intl/numberfield/zh-CN.json +5 -0
- package/src/intl/numberfield/zh-TW.json +5 -0
- package/src/intl/overlays/ar-AE.json +3 -0
- package/src/intl/overlays/bg-BG.json +3 -0
- package/src/intl/overlays/cs-CZ.json +3 -0
- package/src/intl/overlays/da-DK.json +3 -0
- package/src/intl/overlays/de-DE.json +3 -0
- package/src/intl/overlays/el-GR.json +3 -0
- package/src/intl/overlays/en-US.json +3 -0
- package/src/intl/overlays/es-ES.json +3 -0
- package/src/intl/overlays/et-EE.json +3 -0
- package/src/intl/overlays/fi-FI.json +3 -0
- package/src/intl/overlays/fr-FR.json +3 -0
- package/src/intl/overlays/he-IL.json +3 -0
- package/src/intl/overlays/hr-HR.json +3 -0
- package/src/intl/overlays/hu-HU.json +3 -0
- package/src/intl/overlays/index.ts +75 -0
- package/src/intl/overlays/it-IT.json +3 -0
- package/src/intl/overlays/ja-JP.json +3 -0
- package/src/intl/overlays/ko-KR.json +3 -0
- package/src/intl/overlays/lt-LT.json +3 -0
- package/src/intl/overlays/lv-LV.json +3 -0
- package/src/intl/overlays/nb-NO.json +3 -0
- package/src/intl/overlays/nl-NL.json +3 -0
- package/src/intl/overlays/pl-PL.json +3 -0
- package/src/intl/overlays/pt-BR.json +3 -0
- package/src/intl/overlays/pt-PT.json +3 -0
- package/src/intl/overlays/ro-RO.json +3 -0
- package/src/intl/overlays/ru-RU.json +3 -0
- package/src/intl/overlays/sk-SK.json +3 -0
- package/src/intl/overlays/sl-SI.json +3 -0
- package/src/intl/overlays/sr-SP.json +3 -0
- package/src/intl/overlays/sv-SE.json +3 -0
- package/src/intl/overlays/tr-TR.json +3 -0
- package/src/intl/overlays/uk-UA.json +3 -0
- package/src/intl/overlays/zh-CN.json +3 -0
- package/src/intl/overlays/zh-TW.json +3 -0
- package/src/intl/searchfield/ar-AE.json +3 -0
- package/src/intl/searchfield/bg-BG.json +3 -0
- package/src/intl/searchfield/cs-CZ.json +3 -0
- package/src/intl/searchfield/da-DK.json +3 -0
- package/src/intl/searchfield/de-DE.json +3 -0
- package/src/intl/searchfield/el-GR.json +3 -0
- package/src/intl/searchfield/en-US.json +3 -0
- package/src/intl/searchfield/es-ES.json +3 -0
- package/src/intl/searchfield/et-EE.json +3 -0
- package/src/intl/searchfield/fi-FI.json +3 -0
- package/src/intl/searchfield/fr-FR.json +3 -0
- package/src/intl/searchfield/he-IL.json +3 -0
- package/src/intl/searchfield/hr-HR.json +3 -0
- package/src/intl/searchfield/hu-HU.json +3 -0
- package/src/intl/searchfield/index.ts +75 -0
- package/src/intl/searchfield/it-IT.json +3 -0
- package/src/intl/searchfield/ja-JP.json +3 -0
- package/src/intl/searchfield/ko-KR.json +3 -0
- package/src/intl/searchfield/lt-LT.json +3 -0
- package/src/intl/searchfield/lv-LV.json +3 -0
- package/src/intl/searchfield/nb-NO.json +3 -0
- package/src/intl/searchfield/nl-NL.json +3 -0
- package/src/intl/searchfield/pl-PL.json +3 -0
- package/src/intl/searchfield/pt-BR.json +3 -0
- package/src/intl/searchfield/pt-PT.json +3 -0
- package/src/intl/searchfield/ro-RO.json +3 -0
- package/src/intl/searchfield/ru-RU.json +3 -0
- package/src/intl/searchfield/sk-SK.json +3 -0
- package/src/intl/searchfield/sl-SI.json +3 -0
- package/src/intl/searchfield/sr-SP.json +3 -0
- package/src/intl/searchfield/sv-SE.json +3 -0
- package/src/intl/searchfield/tr-TR.json +3 -0
- package/src/intl/searchfield/uk-UA.json +3 -0
- package/src/intl/searchfield/zh-CN.json +3 -0
- package/src/intl/searchfield/zh-TW.json +3 -0
- package/src/intl/spinbutton/ar-AE.json +3 -0
- package/src/intl/spinbutton/bg-BG.json +3 -0
- package/src/intl/spinbutton/cs-CZ.json +3 -0
- package/src/intl/spinbutton/da-DK.json +3 -0
- package/src/intl/spinbutton/de-DE.json +3 -0
- package/src/intl/spinbutton/el-GR.json +3 -0
- package/src/intl/spinbutton/en-US.json +3 -0
- package/src/intl/spinbutton/es-ES.json +3 -0
- package/src/intl/spinbutton/et-EE.json +3 -0
- package/src/intl/spinbutton/fi-FI.json +3 -0
- package/src/intl/spinbutton/fr-FR.json +3 -0
- package/src/intl/spinbutton/he-IL.json +3 -0
- package/src/intl/spinbutton/hr-HR.json +3 -0
- package/src/intl/spinbutton/hu-HU.json +3 -0
- package/src/intl/spinbutton/index.ts +75 -0
- package/src/intl/spinbutton/it-IT.json +3 -0
- package/src/intl/spinbutton/ja-JP.json +3 -0
- package/src/intl/spinbutton/ko-KR.json +3 -0
- package/src/intl/spinbutton/lt-LT.json +3 -0
- package/src/intl/spinbutton/lv-LV.json +3 -0
- package/src/intl/spinbutton/nb-NO.json +3 -0
- package/src/intl/spinbutton/nl-NL.json +3 -0
- package/src/intl/spinbutton/pl-PL.json +3 -0
- package/src/intl/spinbutton/pt-BR.json +3 -0
- package/src/intl/spinbutton/pt-PT.json +3 -0
- package/src/intl/spinbutton/ro-RO.json +3 -0
- package/src/intl/spinbutton/ru-RU.json +3 -0
- package/src/intl/spinbutton/sk-SK.json +3 -0
- package/src/intl/spinbutton/sl-SI.json +3 -0
- package/src/intl/spinbutton/sr-SP.json +3 -0
- package/src/intl/spinbutton/sv-SE.json +3 -0
- package/src/intl/spinbutton/tr-TR.json +3 -0
- package/src/intl/spinbutton/uk-UA.json +3 -0
- package/src/intl/spinbutton/zh-CN.json +3 -0
- package/src/intl/spinbutton/zh-TW.json +3 -0
- package/src/intl/tag/ar-AE.json +4 -0
- package/src/intl/tag/bg-BG.json +4 -0
- package/src/intl/tag/cs-CZ.json +4 -0
- package/src/intl/tag/da-DK.json +4 -0
- package/src/intl/tag/de-DE.json +4 -0
- package/src/intl/tag/el-GR.json +4 -0
- package/src/intl/tag/en-US.json +4 -0
- package/src/intl/tag/es-ES.json +4 -0
- package/src/intl/tag/et-EE.json +4 -0
- package/src/intl/tag/fi-FI.json +4 -0
- package/src/intl/tag/fr-FR.json +4 -0
- package/src/intl/tag/he-IL.json +4 -0
- package/src/intl/tag/hr-HR.json +4 -0
- package/src/intl/tag/hu-HU.json +4 -0
- package/src/intl/tag/index.ts +75 -0
- package/src/intl/tag/it-IT.json +4 -0
- package/src/intl/tag/ja-JP.json +4 -0
- package/src/intl/tag/ko-KR.json +4 -0
- package/src/intl/tag/lt-LT.json +4 -0
- package/src/intl/tag/lv-LV.json +4 -0
- package/src/intl/tag/nb-NO.json +4 -0
- package/src/intl/tag/nl-NL.json +4 -0
- package/src/intl/tag/pl-PL.json +4 -0
- package/src/intl/tag/pt-BR.json +4 -0
- package/src/intl/tag/pt-PT.json +4 -0
- package/src/intl/tag/ro-RO.json +4 -0
- package/src/intl/tag/ru-RU.json +4 -0
- package/src/intl/tag/sk-SK.json +4 -0
- package/src/intl/tag/sl-SI.json +4 -0
- package/src/intl/tag/sr-SP.json +4 -0
- package/src/intl/tag/sv-SE.json +4 -0
- package/src/intl/tag/tr-TR.json +4 -0
- package/src/intl/tag/uk-UA.json +4 -0
- package/src/intl/tag/zh-CN.json +4 -0
- package/src/intl/tag/zh-TW.json +4 -0
- package/src/label/useField.ts +67 -0
- package/src/label/useLabel.ts +78 -0
- package/src/link/useLink.ts +108 -0
- package/src/listbox/useListBox.ts +224 -0
- package/src/listbox/useListBoxSection.ts +74 -0
- package/src/listbox/useOption.ts +212 -0
- package/src/listbox/utils.ts +38 -0
- package/src/live-announcer/LiveAnnouncer.ts +172 -0
- package/src/menu/useMenu.ts +139 -0
- package/src/menu/useMenuItem.ts +453 -0
- package/src/menu/useMenuSection.ts +70 -0
- package/src/menu/useMenuTrigger.ts +189 -0
- package/src/menu/useSafelyMouseToSubmenu.ts +236 -0
- package/src/menu/useSubmenuTrigger.ts +357 -0
- package/src/menu/utils.ts +16 -0
- package/src/meter/useMeter.ts +43 -0
- package/src/numberfield/useNumberField.ts +572 -0
- package/src/overlays/DismissButton.ts +50 -0
- package/src/overlays/Overlay.ts +106 -0
- package/src/overlays/PortalProvider.ts +37 -0
- package/src/overlays/ariaHideOutside.ts +299 -0
- package/src/overlays/calculatePosition.ts +856 -0
- package/src/overlays/useCloseOnScroll.ts +75 -0
- package/src/overlays/useModal.ts +224 -0
- package/src/overlays/useModalOverlay.ts +103 -0
- package/src/overlays/useOverlay.ts +199 -0
- package/src/overlays/useOverlayPosition.ts +462 -0
- package/src/overlays/useOverlayTrigger.ts +94 -0
- package/src/overlays/usePopover.ts +170 -0
- package/src/overlays/usePreventScroll.ts +316 -0
- package/src/progress/useProgressBar.ts +115 -0
- package/src/radio/useRadio.ts +219 -0
- package/src/radio/useRadioGroup.ts +184 -0
- package/src/radio/utils.ts +15 -0
- package/src/searchfield/useSearchField.ts +156 -0
- package/src/select/HiddenSelect.ts +261 -0
- package/src/select/useSelect.ts +332 -0
- package/src/selection/DOMLayoutDelegate.ts +51 -0
- package/src/selection/ListKeyboardDelegate.ts +392 -0
- package/src/selection/useSelectableCollection.ts +750 -0
- package/src/selection/useSelectableItem.ts +499 -0
- package/src/selection/useSelectableList.ts +132 -0
- package/src/selection/useTypeSelect.ts +192 -0
- package/src/selection/utils.ts +50 -0
- package/src/separator/useSeparator.ts +41 -0
- package/src/slider/useSlider.ts +277 -0
- package/src/slider/useSliderThumb.ts +375 -0
- package/src/slider/utils.ts +20 -0
- package/src/spinbutton/useSpinButton.ts +380 -0
- package/src/stately/checkbox/useCheckboxGroupState.ts +177 -0
- package/src/stately/collections/CollectionBuilder.ts +332 -0
- package/src/stately/collections/Item.ts +78 -0
- package/src/stately/collections/Section.ts +52 -0
- package/src/stately/collections/getChildNodes.ts +94 -0
- package/src/stately/collections/getItemCount.ts +29 -0
- package/src/stately/collections/types.ts +20 -0
- package/src/stately/collections/useCollection.ts +54 -0
- package/src/stately/combobox/useComboBoxState.ts +763 -0
- package/src/stately/disclosure/useDisclosureGroupState.ts +108 -0
- package/src/stately/disclosure/useDisclosureState.ts +84 -0
- package/src/stately/form/useFormValidationState.ts +331 -0
- package/src/stately/index.ts +111 -0
- package/src/stately/list/ListCollection.ts +104 -0
- package/src/stately/list/useListState.ts +178 -0
- package/src/stately/list/useSingleSelectListState.ts +101 -0
- package/src/stately/menu/useMenuTriggerState.ts +120 -0
- package/src/stately/menu/useSubmenuTriggerState.ts +116 -0
- package/src/stately/numberfield/useNumberFieldState.ts +430 -0
- package/src/stately/overlays/useOverlayTriggerState.ts +85 -0
- package/src/stately/radio/useRadioGroupState.ts +150 -0
- package/src/stately/searchfield/useSearchFieldState.ts +79 -0
- package/src/stately/select/useSelectState.ts +322 -0
- package/src/stately/selection/Selection.ts +23 -0
- package/src/stately/selection/SelectionManager.ts +541 -0
- package/src/stately/selection/types.ts +117 -0
- package/src/stately/selection/useMultipleSelectionState.ts +178 -0
- package/src/stately/slider/useSliderState.ts +458 -0
- package/src/stately/tabs/useTabListState.ts +149 -0
- package/src/stately/toggle/useToggleGroupState.ts +109 -0
- package/src/stately/toggle/useToggleState.ts +100 -0
- package/src/stately/tooltip/useTooltipTriggerState.ts +218 -0
- package/src/stately/tree/TreeCollection.ts +92 -0
- package/src/stately/tree/useTreeState.ts +121 -0
- package/src/stately/utils/useControlledState.ts +7 -0
- package/src/switch/useSwitch.ts +77 -0
- package/src/tabs/TabsKeyboardDelegate.ts +99 -0
- package/src/tabs/useTab.ts +117 -0
- package/src/tabs/useTabList.ts +105 -0
- package/src/tabs/useTabPanel.ts +75 -0
- package/src/tabs/utils.ts +32 -0
- package/src/tag/useTag.ts +162 -0
- package/src/tag/useTagGroup.ts +192 -0
- package/src/textfield/useFormattedTextField.ts +203 -0
- package/src/textfield/useTextField.ts +248 -0
- package/src/toggle/useToggle.ts +265 -0
- package/src/toolbar/useToolbar.ts +147 -0
- package/src/tooltip/useTooltip.ts +64 -0
- package/src/tooltip/useTooltipTrigger.ts +187 -0
- package/src/utils/filterDOMProps.ts +121 -0
- package/src/utils/getScrollParent.ts +16 -0
- package/src/utils/getScrollParents.ts +20 -0
- package/src/utils/keyboard.ts +38 -0
- package/src/utils/scrollIntoView.ts +178 -0
- package/src/utils/useDeepMemo.ts +30 -0
- package/src/utils/useFormReset.ts +54 -0
- package/src/utils/useId.ts +5 -0
- package/src/utils/useLabels.ts +53 -0
- package/src/utils/useResizeObserver.ts +70 -0
- package/src/utils/useSlot.ts +78 -0
- package/src/utils/useUpdateEffect.ts +54 -0
- package/src/utils/useUpdateLayoutEffect.ts +58 -0
- package/src/visually-hidden/VisuallyHidden.ts +100 -0
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
// Ported from react-aria (source: .react-spectrum/packages/react-aria/src/numberfield/useNumberField.ts).
|
|
2
|
+
// octane adaptations:
|
|
3
|
+
// - Handlers receive NATIVE events. The Enter-commit keydown handler flows through the
|
|
4
|
+
// ported useKeyboard wrapper (so `continuePropagation()` works) and upstream's
|
|
5
|
+
// `e.nativeEvent.isComposing` reads `e.isComposing` off the native event; onPaste takes
|
|
6
|
+
// the native ClipboardEvent. The value-level `onChange(value)` callback is unchanged —
|
|
7
|
+
// the per-keystroke DOM wiring rides the native `input` event inside the ported
|
|
8
|
+
// useTextField, and the blur commit rides the native blur/focusout path in useFocus.
|
|
9
|
+
// - `flushSync` comes from 'octane'.
|
|
10
|
+
// - The Parcel glob intl import becomes the generated src/intl/numberfield index
|
|
11
|
+
// (verbatim dictionaries).
|
|
12
|
+
// - React's InputHTMLAttributes/LabelHTMLAttributes/GroupDOMAttributes element types
|
|
13
|
+
// collapse to the local structural `DOMAttributes` prop bag; `TextInputDOMEvents` is
|
|
14
|
+
// declared structurally over native events (upstream's drags React handler types).
|
|
15
|
+
// - `useNativeValidation`'s dep-less useLayoutEffect keeps run-every-render semantics via
|
|
16
|
+
// an explicit `null` dependency argument, and threads a sub-slot like every other hook
|
|
17
|
+
// call (it is an internal helper invoked exactly once per useNumberField call).
|
|
18
|
+
// - Public-hook slot threading (splitSlot/subSlot); explicit dependency arrays are kept
|
|
19
|
+
// verbatim.
|
|
20
|
+
import { announce } from '../live-announcer/LiveAnnouncer';
|
|
21
|
+
import type { AriaButtonProps } from '../button/useButton';
|
|
22
|
+
import type { AriaLabelingProps, DOMProps, RefObject, ValidationResult } from '@react-types/shared';
|
|
23
|
+
import { chain } from '../utils/chain';
|
|
24
|
+
import { flushSync, useCallback, useMemo, useState } from 'octane';
|
|
25
|
+
import { filterDOMProps } from '../utils/filterDOMProps';
|
|
26
|
+
import { getActiveElement, getEventTarget } from '../utils/shadowdom/DOMFunctions';
|
|
27
|
+
import intlMessages from '../intl/numberfield';
|
|
28
|
+
import { isAndroid, isIOS, isIPhone } from '../utils/platform';
|
|
29
|
+
import { mergeProps } from '../utils/mergeProps';
|
|
30
|
+
import type {
|
|
31
|
+
NumberFieldProps,
|
|
32
|
+
NumberFieldState,
|
|
33
|
+
} from '../stately/numberfield/useNumberFieldState';
|
|
34
|
+
import { privateValidationStateProp } from '../stately/form/useFormValidationState';
|
|
35
|
+
import { useFocus } from '../interactions/useFocus';
|
|
36
|
+
import { useFocusWithin } from '../interactions/useFocusWithin';
|
|
37
|
+
import { useFormattedTextField } from '../textfield/useFormattedTextField';
|
|
38
|
+
import { useFormReset } from '../utils/useFormReset';
|
|
39
|
+
import { useId } from '../utils/useId';
|
|
40
|
+
import { useLayoutEffect } from '../utils/useLayoutEffect';
|
|
41
|
+
import { useLocalizedStringFormatter } from '../i18n/useLocalizedStringFormatter';
|
|
42
|
+
import { useNumberFormatter } from '../i18n/useNumberFormatter';
|
|
43
|
+
import { useScrollWheel } from '../interactions/useScrollWheel';
|
|
44
|
+
import { useSpinButton } from '../spinbutton/useSpinButton';
|
|
45
|
+
|
|
46
|
+
import { S, splitSlot, subSlot } from '../internal';
|
|
47
|
+
|
|
48
|
+
// octane adaptation: minimal structural DOMAttributes (upstream's drags React's synthetic
|
|
49
|
+
// handler types along).
|
|
50
|
+
type DOMAttributes = Record<string, any>;
|
|
51
|
+
|
|
52
|
+
// octane adaptation: structural native-event versions of upstream's TextInputDOMEvents.
|
|
53
|
+
interface TextInputDOMEvents {
|
|
54
|
+
// Clipboard events
|
|
55
|
+
onCopy?: (e: ClipboardEvent) => void;
|
|
56
|
+
onCut?: (e: ClipboardEvent) => void;
|
|
57
|
+
onPaste?: (e: ClipboardEvent) => void;
|
|
58
|
+
// Composition events
|
|
59
|
+
onCompositionEnd?: (e: CompositionEvent) => void;
|
|
60
|
+
onCompositionStart?: (e: CompositionEvent) => void;
|
|
61
|
+
onCompositionUpdate?: (e: CompositionEvent) => void;
|
|
62
|
+
// Selection events
|
|
63
|
+
onSelect?: (e: Event) => void;
|
|
64
|
+
// Input events
|
|
65
|
+
onBeforeInput?: (e: InputEvent) => void;
|
|
66
|
+
onInput?: (e: Event) => void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface AriaNumberFieldProps
|
|
70
|
+
extends NumberFieldProps, DOMProps, AriaLabelingProps, TextInputDOMEvents {
|
|
71
|
+
/**
|
|
72
|
+
* A custom aria-label for the decrement button. If not provided, the localized string "Decrement"
|
|
73
|
+
* is used.
|
|
74
|
+
*/
|
|
75
|
+
decrementAriaLabel?: string;
|
|
76
|
+
/**
|
|
77
|
+
* A custom aria-label for the increment button. If not provided, the localized string "Increment"
|
|
78
|
+
* is used.
|
|
79
|
+
*/
|
|
80
|
+
incrementAriaLabel?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Enables or disables changing the value with scroll.
|
|
83
|
+
*/
|
|
84
|
+
isWheelDisabled?: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface NumberFieldAria extends ValidationResult {
|
|
88
|
+
/** Props for the label element. */
|
|
89
|
+
labelProps: DOMAttributes;
|
|
90
|
+
/** Props for the group wrapper around the input and stepper buttons. */
|
|
91
|
+
groupProps: DOMAttributes;
|
|
92
|
+
/** Props for the input element. */
|
|
93
|
+
inputProps: DOMAttributes;
|
|
94
|
+
/** Props for the increment button, to be passed to `useButton`. */
|
|
95
|
+
incrementButtonProps: AriaButtonProps;
|
|
96
|
+
/** Props for the decrement button, to be passed to `useButton`. */
|
|
97
|
+
decrementButtonProps: AriaButtonProps;
|
|
98
|
+
/** Props for the number field's description element, if any. */
|
|
99
|
+
descriptionProps: DOMAttributes;
|
|
100
|
+
/** Props for the number field's error message element, if any. */
|
|
101
|
+
errorMessageProps: DOMAttributes;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Provides the behavior and accessibility implementation for a number field component. Number
|
|
106
|
+
* fields allow users to enter a number, and increment or decrement the value using stepper
|
|
107
|
+
* buttons.
|
|
108
|
+
*/
|
|
109
|
+
export function useNumberField(
|
|
110
|
+
props: AriaNumberFieldProps,
|
|
111
|
+
state: NumberFieldState,
|
|
112
|
+
inputRef: RefObject<HTMLInputElement | null>,
|
|
113
|
+
): NumberFieldAria;
|
|
114
|
+
// Slot-threading form: sibling ported hooks pass their derived sub-slot as the trailing arg.
|
|
115
|
+
export function useNumberField(
|
|
116
|
+
props: AriaNumberFieldProps,
|
|
117
|
+
state: NumberFieldState,
|
|
118
|
+
inputRef: RefObject<HTMLInputElement | null>,
|
|
119
|
+
slot: symbol | undefined,
|
|
120
|
+
): NumberFieldAria;
|
|
121
|
+
export function useNumberField(...args: any[]): NumberFieldAria {
|
|
122
|
+
const [user, slotArg] = splitSlot(args);
|
|
123
|
+
const slot = slotArg ?? S('useNumberField');
|
|
124
|
+
const props = user[0] as AriaNumberFieldProps;
|
|
125
|
+
const state = user[1] as NumberFieldState;
|
|
126
|
+
const inputRef = user[2] as RefObject<HTMLInputElement | null>;
|
|
127
|
+
|
|
128
|
+
let {
|
|
129
|
+
id,
|
|
130
|
+
decrementAriaLabel,
|
|
131
|
+
incrementAriaLabel,
|
|
132
|
+
isDisabled,
|
|
133
|
+
isReadOnly,
|
|
134
|
+
isRequired,
|
|
135
|
+
minValue,
|
|
136
|
+
maxValue,
|
|
137
|
+
autoFocus,
|
|
138
|
+
label,
|
|
139
|
+
formatOptions,
|
|
140
|
+
onBlur = () => {},
|
|
141
|
+
onFocus,
|
|
142
|
+
onFocusChange,
|
|
143
|
+
onKeyDown,
|
|
144
|
+
onKeyUp,
|
|
145
|
+
description,
|
|
146
|
+
errorMessage,
|
|
147
|
+
isWheelDisabled,
|
|
148
|
+
...otherProps
|
|
149
|
+
} = props;
|
|
150
|
+
|
|
151
|
+
let {
|
|
152
|
+
increment,
|
|
153
|
+
incrementToMax,
|
|
154
|
+
decrement,
|
|
155
|
+
decrementToMin,
|
|
156
|
+
numberValue,
|
|
157
|
+
inputValue,
|
|
158
|
+
commit,
|
|
159
|
+
commitValidation,
|
|
160
|
+
} = state;
|
|
161
|
+
|
|
162
|
+
const stringFormatter = useLocalizedStringFormatter(
|
|
163
|
+
intlMessages,
|
|
164
|
+
'@react-aria/numberfield',
|
|
165
|
+
subSlot(slot, 'strings'),
|
|
166
|
+
);
|
|
167
|
+
let commitAndAnnounce = useCallback(
|
|
168
|
+
() => {
|
|
169
|
+
let oldValue = inputRef.current?.value ?? '';
|
|
170
|
+
// Set input value to normalized valid value
|
|
171
|
+
flushSync(() => {
|
|
172
|
+
commit();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
if (inputRef.current?.value !== oldValue) {
|
|
176
|
+
announce(inputRef.current?.value ?? '', 'assertive');
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
[commit, inputRef],
|
|
180
|
+
subSlot(slot, 'commitAndAnnounce'),
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
let inputId = useId(id, subSlot(slot, 'inputId'));
|
|
184
|
+
let { focusProps } = useFocus(
|
|
185
|
+
{
|
|
186
|
+
onBlur() {
|
|
187
|
+
commitAndAnnounce();
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
subSlot(slot, 'focus'),
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
let numberFormatter = useNumberFormatter(formatOptions, subSlot(slot, 'formatter'));
|
|
194
|
+
let intlOptions = useMemo(
|
|
195
|
+
() => numberFormatter.resolvedOptions(),
|
|
196
|
+
[numberFormatter],
|
|
197
|
+
subSlot(slot, 'intlOptions'),
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
// Replace negative textValue formatted using currencySign: 'accounting'
|
|
201
|
+
// with a textValue that can be announced using a minus sign.
|
|
202
|
+
let textValueFormatter = useNumberFormatter(
|
|
203
|
+
{ ...formatOptions, currencySign: undefined },
|
|
204
|
+
subSlot(slot, 'textValueFormatter'),
|
|
205
|
+
);
|
|
206
|
+
let textValue = useMemo(
|
|
207
|
+
() => (isNaN(numberValue) ? '' : textValueFormatter.format(numberValue)),
|
|
208
|
+
[textValueFormatter, numberValue],
|
|
209
|
+
subSlot(slot, 'textValue'),
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
let {
|
|
213
|
+
spinButtonProps,
|
|
214
|
+
incrementButtonProps: incButtonProps,
|
|
215
|
+
decrementButtonProps: decButtonProps,
|
|
216
|
+
} = useSpinButton(
|
|
217
|
+
{
|
|
218
|
+
isDisabled,
|
|
219
|
+
isReadOnly,
|
|
220
|
+
isRequired,
|
|
221
|
+
maxValue,
|
|
222
|
+
minValue,
|
|
223
|
+
onIncrement: increment,
|
|
224
|
+
onIncrementToMax: incrementToMax,
|
|
225
|
+
onDecrement: decrement,
|
|
226
|
+
onDecrementToMin: decrementToMin,
|
|
227
|
+
value: numberValue,
|
|
228
|
+
textValue,
|
|
229
|
+
},
|
|
230
|
+
subSlot(slot, 'spinButton'),
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
let [focusWithin, setFocusWithin] = useState(false, subSlot(slot, 'focusWithin'));
|
|
234
|
+
let { focusWithinProps } = useFocusWithin(
|
|
235
|
+
{ isDisabled, onFocusWithinChange: setFocusWithin },
|
|
236
|
+
subSlot(slot, 'focusWithinHook'),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
let onWheel = useCallback(
|
|
240
|
+
(e: { deltaX: number; deltaY: number }) => {
|
|
241
|
+
// if on a trackpad, users can scroll in both X and Y at once, check the magnitude of the change
|
|
242
|
+
// if it's mostly in the X direction, then just return, the user probably doesn't mean to inc/dec
|
|
243
|
+
// this isn't perfect, events come in fast with small deltas and a part of the scroll may give a false indication
|
|
244
|
+
// especially if the user is scrolling near 45deg
|
|
245
|
+
if (Math.abs(e.deltaY) <= Math.abs(e.deltaX)) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (e.deltaY > 0) {
|
|
249
|
+
increment();
|
|
250
|
+
} else if (e.deltaY < 0) {
|
|
251
|
+
decrement();
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
[decrement, increment],
|
|
255
|
+
subSlot(slot, 'wheel'),
|
|
256
|
+
);
|
|
257
|
+
// If the input isn't supposed to receive input, disable scrolling.
|
|
258
|
+
let scrollingDisabled = isWheelDisabled || isDisabled || isReadOnly || !focusWithin;
|
|
259
|
+
useScrollWheel(
|
|
260
|
+
{ onScroll: onWheel, isDisabled: scrollingDisabled },
|
|
261
|
+
inputRef,
|
|
262
|
+
subSlot(slot, 'scrollWheel'),
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
// The inputMode attribute influences the software keyboard that is shown on touch devices.
|
|
266
|
+
// Browsers and operating systems are quite inconsistent about what keys are available, however.
|
|
267
|
+
// We choose between numeric and decimal based on whether we allow negative and fractional numbers,
|
|
268
|
+
// and based on testing on various devices to determine what keys are available in each inputMode.
|
|
269
|
+
let hasDecimals = (intlOptions.maximumFractionDigits ?? 0) > 0;
|
|
270
|
+
let hasNegative = state.minValue === undefined || isNaN(state.minValue) || state.minValue < 0;
|
|
271
|
+
let inputMode: string = 'numeric';
|
|
272
|
+
if (isIPhone()) {
|
|
273
|
+
// iPhone doesn't have a minus sign in either numeric or decimal.
|
|
274
|
+
// Note this is only for iPhone, not iPad, which always has both
|
|
275
|
+
// minus and decimal in numeric.
|
|
276
|
+
if (hasNegative) {
|
|
277
|
+
inputMode = 'text';
|
|
278
|
+
} else if (hasDecimals) {
|
|
279
|
+
inputMode = 'decimal';
|
|
280
|
+
}
|
|
281
|
+
} else if (isAndroid()) {
|
|
282
|
+
// Android numeric has both a decimal point and minus key.
|
|
283
|
+
// decimal does not have a minus key.
|
|
284
|
+
if (hasNegative) {
|
|
285
|
+
inputMode = 'numeric';
|
|
286
|
+
} else if (hasDecimals) {
|
|
287
|
+
inputMode = 'decimal';
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
let onChange = (value: string) => {
|
|
292
|
+
if (state.validate(value)) {
|
|
293
|
+
state.setInputValue(value);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
let onPaste = (e: ClipboardEvent) => {
|
|
298
|
+
props.onPaste?.(e);
|
|
299
|
+
let inputElement = getEventTarget(e) as HTMLInputElement;
|
|
300
|
+
// we can only handle the case where the paste takes over the entire input, otherwise things get very complicated
|
|
301
|
+
// trying to calculate the new string based on what the paste is replacing and where in the source string it is
|
|
302
|
+
if (
|
|
303
|
+
inputElement &&
|
|
304
|
+
(inputElement.selectionEnd ?? -1) - (inputElement.selectionStart ?? 0) ===
|
|
305
|
+
inputElement.value.length
|
|
306
|
+
) {
|
|
307
|
+
e.preventDefault();
|
|
308
|
+
// commit so that the user gets to see what it formats to immediately
|
|
309
|
+
// paste happens before inputRef's value is updated, so have to prevent the default and do it ourselves
|
|
310
|
+
// spin button will then handle announcing the new value, this should work with controlled state as well
|
|
311
|
+
// because the announcement is done as a result of the new rendered input value if there is one
|
|
312
|
+
commit(e.clipboardData?.getData?.('text/plain')?.trim() ?? '');
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
let domProps = filterDOMProps(props);
|
|
317
|
+
let onKeyDownEnter = useCallback(
|
|
318
|
+
(e: any) => {
|
|
319
|
+
// octane adaptation: `e.nativeEvent.isComposing` → the native event's own flag
|
|
320
|
+
// (the wrapped keyboard event proxies it through).
|
|
321
|
+
if (e.isComposing) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (e.key === 'Enter') {
|
|
326
|
+
flushSync(() => {
|
|
327
|
+
commit();
|
|
328
|
+
});
|
|
329
|
+
commitValidation();
|
|
330
|
+
} else {
|
|
331
|
+
e.continuePropagation();
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
[commit, commitValidation],
|
|
335
|
+
subSlot(slot, 'keyDownEnter'),
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
let { isInvalid, validationErrors, validationDetails } = state.displayValidation;
|
|
339
|
+
let {
|
|
340
|
+
labelProps,
|
|
341
|
+
inputProps: textFieldProps,
|
|
342
|
+
descriptionProps,
|
|
343
|
+
errorMessageProps,
|
|
344
|
+
} = useFormattedTextField(
|
|
345
|
+
{
|
|
346
|
+
...otherProps,
|
|
347
|
+
...domProps,
|
|
348
|
+
// These props are added to a hidden input rather than the formatted textfield.
|
|
349
|
+
name: undefined,
|
|
350
|
+
form: undefined,
|
|
351
|
+
label,
|
|
352
|
+
autoFocus,
|
|
353
|
+
isDisabled,
|
|
354
|
+
isReadOnly,
|
|
355
|
+
isRequired,
|
|
356
|
+
validate: undefined,
|
|
357
|
+
[privateValidationStateProp]: state,
|
|
358
|
+
value: inputValue,
|
|
359
|
+
defaultValue: '!', // an invalid value so that form reset is ignored in onChange above
|
|
360
|
+
autoComplete: 'off',
|
|
361
|
+
'aria-label': props['aria-label'] || undefined,
|
|
362
|
+
'aria-labelledby': props['aria-labelledby'] || undefined,
|
|
363
|
+
id: inputId,
|
|
364
|
+
type: 'text', // Can't use type="number" because then we can't have things like $ in the field.
|
|
365
|
+
inputMode,
|
|
366
|
+
onChange,
|
|
367
|
+
onBlur,
|
|
368
|
+
onFocus,
|
|
369
|
+
onFocusChange,
|
|
370
|
+
onKeyDown: useMemo(
|
|
371
|
+
() => chain(onKeyDownEnter, onKeyDown),
|
|
372
|
+
[onKeyDownEnter, onKeyDown],
|
|
373
|
+
subSlot(slot, 'keyDownChain'),
|
|
374
|
+
),
|
|
375
|
+
onKeyUp,
|
|
376
|
+
onPaste,
|
|
377
|
+
description,
|
|
378
|
+
errorMessage,
|
|
379
|
+
} as any,
|
|
380
|
+
state,
|
|
381
|
+
inputRef,
|
|
382
|
+
subSlot(slot, 'textField'),
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
useFormReset(inputRef, state.defaultNumberValue, state.setNumberValue, subSlot(slot, 'reset'));
|
|
386
|
+
useNativeValidation(
|
|
387
|
+
state,
|
|
388
|
+
props.validationBehavior,
|
|
389
|
+
props.commitBehavior,
|
|
390
|
+
inputRef,
|
|
391
|
+
state.minValue,
|
|
392
|
+
state.maxValue,
|
|
393
|
+
props.step,
|
|
394
|
+
state.numberValue,
|
|
395
|
+
subSlot(slot, 'nativeValidation'),
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
let inputProps: DOMAttributes = mergeProps(spinButtonProps, focusProps, textFieldProps, {
|
|
399
|
+
// override the spinbutton role, we can't focus a spin button with VO
|
|
400
|
+
role: null,
|
|
401
|
+
// ignore aria-roledescription on iOS so that required state will announce when it is present
|
|
402
|
+
'aria-roledescription': !isIOS() ? stringFormatter.format('numberField') : null,
|
|
403
|
+
'aria-valuemax': null,
|
|
404
|
+
'aria-valuemin': null,
|
|
405
|
+
'aria-valuenow': null,
|
|
406
|
+
'aria-valuetext': null,
|
|
407
|
+
autoCorrect: 'off',
|
|
408
|
+
spellCheck: 'false',
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
if (props.validationBehavior === 'native') {
|
|
412
|
+
inputProps['aria-required'] = undefined;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
let onButtonPressStart = (e: any) => {
|
|
416
|
+
// If focus is already on the input, keep it there so we don't hide the
|
|
417
|
+
// software keyboard when tapping the increment/decrement buttons.
|
|
418
|
+
if (getActiveElement() === inputRef.current) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Otherwise, when using a mouse, move focus to the input.
|
|
423
|
+
// On touch, or with a screen reader, focus the button so that the software
|
|
424
|
+
// keyboard does not appear and the screen reader cursor is not moved off the button.
|
|
425
|
+
if (e.pointerType === 'mouse') {
|
|
426
|
+
inputRef.current?.focus();
|
|
427
|
+
} else {
|
|
428
|
+
e.target.focus();
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
// Determine the label for the increment and decrement buttons. There are 4 cases:
|
|
433
|
+
//
|
|
434
|
+
// 1. With a visible label that is a string: aria-label: `Increase ${props.label}`
|
|
435
|
+
// 2. With a visible label that is JSX: aria-label: 'Increase', aria-labelledby: '${incrementId} ${labelId}'
|
|
436
|
+
// 3. With an aria-label: aria-label: `Increase ${props['aria-label']}`
|
|
437
|
+
// 4. With an aria-labelledby: aria-label: 'Increase', aria-labelledby: `${incrementId} ${props['aria-labelledby']}`
|
|
438
|
+
//
|
|
439
|
+
// (1) and (2) could possibly be combined and both use aria-labelledby. However, placing the label in
|
|
440
|
+
// the aria-label string rather than using aria-labelledby gives more flexibility to translators to change
|
|
441
|
+
// the order or add additional words around the label if needed.
|
|
442
|
+
let fieldLabel = props['aria-label'] || (typeof props.label === 'string' ? props.label : '');
|
|
443
|
+
let ariaLabelledby: string | undefined;
|
|
444
|
+
if (!fieldLabel) {
|
|
445
|
+
ariaLabelledby = props.label != null ? labelProps.id : props['aria-labelledby'];
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
let incrementId = useId(subSlot(slot, 'incrementId'));
|
|
449
|
+
let decrementId = useId(subSlot(slot, 'decrementId'));
|
|
450
|
+
|
|
451
|
+
let incrementButtonProps: AriaButtonProps = mergeProps(incButtonProps, {
|
|
452
|
+
'aria-label': incrementAriaLabel || stringFormatter.format('increase', { fieldLabel }).trim(),
|
|
453
|
+
id: ariaLabelledby && !incrementAriaLabel ? incrementId : null,
|
|
454
|
+
'aria-labelledby':
|
|
455
|
+
ariaLabelledby && !incrementAriaLabel ? `${incrementId} ${ariaLabelledby}` : null,
|
|
456
|
+
'aria-controls': inputId,
|
|
457
|
+
excludeFromTabOrder: true,
|
|
458
|
+
preventFocusOnPress: true,
|
|
459
|
+
allowFocusWhenDisabled: true,
|
|
460
|
+
isDisabled: !state.canIncrement,
|
|
461
|
+
onPressStart: onButtonPressStart,
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
let decrementButtonProps: AriaButtonProps = mergeProps(decButtonProps, {
|
|
465
|
+
'aria-label': decrementAriaLabel || stringFormatter.format('decrease', { fieldLabel }).trim(),
|
|
466
|
+
id: ariaLabelledby && !decrementAriaLabel ? decrementId : null,
|
|
467
|
+
'aria-labelledby':
|
|
468
|
+
ariaLabelledby && !decrementAriaLabel ? `${decrementId} ${ariaLabelledby}` : null,
|
|
469
|
+
'aria-controls': inputId,
|
|
470
|
+
excludeFromTabOrder: true,
|
|
471
|
+
preventFocusOnPress: true,
|
|
472
|
+
allowFocusWhenDisabled: true,
|
|
473
|
+
isDisabled: !state.canDecrement,
|
|
474
|
+
onPressStart: onButtonPressStart,
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
groupProps: {
|
|
479
|
+
...focusWithinProps,
|
|
480
|
+
role: 'group',
|
|
481
|
+
'aria-disabled': isDisabled,
|
|
482
|
+
'aria-invalid': isInvalid ? 'true' : undefined,
|
|
483
|
+
},
|
|
484
|
+
labelProps,
|
|
485
|
+
inputProps,
|
|
486
|
+
incrementButtonProps,
|
|
487
|
+
decrementButtonProps,
|
|
488
|
+
errorMessageProps,
|
|
489
|
+
descriptionProps,
|
|
490
|
+
isInvalid,
|
|
491
|
+
validationErrors,
|
|
492
|
+
validationDetails,
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
let numberInput: HTMLInputElement | null = null;
|
|
497
|
+
|
|
498
|
+
function useNativeValidation(
|
|
499
|
+
state: NumberFieldState,
|
|
500
|
+
validationBehavior: 'native' | 'aria' | undefined,
|
|
501
|
+
commitBehavior: 'snap' | 'validate' | undefined,
|
|
502
|
+
inputRef: RefObject<HTMLInputElement | null>,
|
|
503
|
+
min: number | undefined,
|
|
504
|
+
max: number | undefined,
|
|
505
|
+
step: number | undefined,
|
|
506
|
+
value: number | undefined,
|
|
507
|
+
slot: symbol | undefined,
|
|
508
|
+
) {
|
|
509
|
+
// octane adaptation: upstream's dep-less useLayoutEffect (run after every render) is
|
|
510
|
+
// an explicit `null` dependency argument here.
|
|
511
|
+
useLayoutEffect(
|
|
512
|
+
() => {
|
|
513
|
+
let input = inputRef.current;
|
|
514
|
+
if (
|
|
515
|
+
commitBehavior !== 'validate' ||
|
|
516
|
+
state.realtimeValidation.isInvalid ||
|
|
517
|
+
!input ||
|
|
518
|
+
input.disabled
|
|
519
|
+
) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// Create a native number input and use it to implement validation of min/max/step.
|
|
524
|
+
// This lets us get the native validation message provided by the browser instead of needing our own translations.
|
|
525
|
+
if (!numberInput && typeof document !== 'undefined') {
|
|
526
|
+
numberInput = document.createElement('input');
|
|
527
|
+
numberInput.type = 'number';
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if (!numberInput) {
|
|
531
|
+
// For TypeScript.
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
numberInput.min = min != null && !isNaN(min) ? String(min) : '';
|
|
536
|
+
numberInput.max = max != null && !isNaN(max) ? String(max) : '';
|
|
537
|
+
numberInput.step = step != null && !isNaN(step) ? String(step) : '';
|
|
538
|
+
numberInput.value = value != null && !isNaN(value) ? String(value) : '';
|
|
539
|
+
|
|
540
|
+
// Merge validity with the visible text input (for other validations like required).
|
|
541
|
+
let valid = input.validity.valid && numberInput.validity.valid;
|
|
542
|
+
let validationMessage = input.validationMessage || numberInput.validationMessage;
|
|
543
|
+
let validity = {
|
|
544
|
+
isInvalid: !valid,
|
|
545
|
+
validationErrors: validationMessage ? [validationMessage] : [],
|
|
546
|
+
validationDetails: {
|
|
547
|
+
badInput: input.validity.badInput,
|
|
548
|
+
customError: input.validity.customError,
|
|
549
|
+
patternMismatch: input.validity.patternMismatch,
|
|
550
|
+
rangeOverflow: numberInput.validity.rangeOverflow,
|
|
551
|
+
rangeUnderflow: numberInput.validity.rangeUnderflow,
|
|
552
|
+
stepMismatch: numberInput.validity.stepMismatch,
|
|
553
|
+
tooLong: input.validity.tooLong,
|
|
554
|
+
tooShort: input.validity.tooShort,
|
|
555
|
+
typeMismatch: input.validity.typeMismatch,
|
|
556
|
+
valueMissing: input.validity.valueMissing,
|
|
557
|
+
valid,
|
|
558
|
+
},
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
state.updateValidation(validity);
|
|
562
|
+
|
|
563
|
+
// Block form submission if validation behavior is native.
|
|
564
|
+
// This won't overwrite any user-defined validation message because we checked realtimeValidation above.
|
|
565
|
+
if (validationBehavior === 'native' && !numberInput.validity.valid) {
|
|
566
|
+
input.setCustomValidity(numberInput.validationMessage);
|
|
567
|
+
}
|
|
568
|
+
},
|
|
569
|
+
null,
|
|
570
|
+
subSlot(slot, 'effect'),
|
|
571
|
+
);
|
|
572
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Ported from react-aria (source: .react-spectrum/packages/react-aria/src/overlays/DismissButton.tsx).
|
|
2
|
+
// octane adaptations: `.tsx` → `.ts`, JSX → `createElement`; the overlays intl dictionary is
|
|
3
|
+
// imported from the ported `../intl/overlays` index (upstream's Parcel glob); the plain-`.ts`
|
|
4
|
+
// component uses the S()/subSlot component-slot convention; React's `JSX.Element` → `any`;
|
|
5
|
+
// `onClick` is a native DOM click handler.
|
|
6
|
+
import type { AriaLabelingProps, DOMProps } from '@react-types/shared';
|
|
7
|
+
import { createElement } from 'octane';
|
|
8
|
+
|
|
9
|
+
import intlMessages from '../intl/overlays';
|
|
10
|
+
import { S, subSlot } from '../internal';
|
|
11
|
+
import { useLabels } from '../utils/useLabels';
|
|
12
|
+
import { useLocalizedStringFormatter } from '../i18n/useLocalizedStringFormatter';
|
|
13
|
+
import { VisuallyHidden } from '../visually-hidden/VisuallyHidden';
|
|
14
|
+
|
|
15
|
+
export interface DismissButtonProps extends AriaLabelingProps, DOMProps {
|
|
16
|
+
/** Called when the dismiss button is activated. */
|
|
17
|
+
onDismiss?: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A visually hidden button that can be used to allow screen reader
|
|
22
|
+
* users to dismiss a modal or popup when there is no visual
|
|
23
|
+
* affordance to do so.
|
|
24
|
+
*/
|
|
25
|
+
export function DismissButton(props: DismissButtonProps): any {
|
|
26
|
+
const slot = S('DismissButton');
|
|
27
|
+
let { onDismiss, ...otherProps } = props;
|
|
28
|
+
let stringFormatter = useLocalizedStringFormatter(
|
|
29
|
+
intlMessages,
|
|
30
|
+
'@react-aria/overlays',
|
|
31
|
+
subSlot(slot, 'strings'),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
let labels = useLabels(otherProps, stringFormatter.format('dismiss'), subSlot(slot, 'labels'));
|
|
35
|
+
|
|
36
|
+
let onClick = () => {
|
|
37
|
+
if (onDismiss) {
|
|
38
|
+
onDismiss();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return createElement(VisuallyHidden, {
|
|
43
|
+
children: createElement('button', {
|
|
44
|
+
...labels,
|
|
45
|
+
tabIndex: -1,
|
|
46
|
+
onClick,
|
|
47
|
+
style: { width: 1, height: 1 },
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
}
|