@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,162 @@
|
|
|
1
|
+
// Ported from react-aria (source: .react-spectrum/packages/react-aria/src/tag/useTag.ts).
|
|
2
|
+
// octane adaptations:
|
|
3
|
+
// - Handlers receive NATIVE events: the Delete/Backspace removal handler takes the
|
|
4
|
+
// native KeyboardEvent.
|
|
5
|
+
// - The Parcel glob intl import becomes the generated src/intl/tag index (verbatim
|
|
6
|
+
// dictionaries).
|
|
7
|
+
// - `ListState` comes from the ported stately list hook; `DOMAttributes` is a local
|
|
8
|
+
// structural prop-bag alias.
|
|
9
|
+
// - Public-hook slot threading (splitSlot/subSlot).
|
|
10
|
+
import type { AriaButtonProps } from '../button/useButton';
|
|
11
|
+
import type { FocusableElement, Node, RefObject } from '@react-types/shared';
|
|
12
|
+
import { filterDOMProps } from '../utils/filterDOMProps';
|
|
13
|
+
import { hookData } from './useTagGroup';
|
|
14
|
+
import intlMessages from '../intl/tag';
|
|
15
|
+
import type { ListState } from '../stately/list/useListState';
|
|
16
|
+
import { mergeProps } from '../utils/mergeProps';
|
|
17
|
+
import { SelectableItemStates } from '../selection/useSelectableItem';
|
|
18
|
+
import { useDescription } from '../utils/useDescription';
|
|
19
|
+
import { useFocusable } from '../interactions/useFocusable';
|
|
20
|
+
import { useGridListItem } from '../gridlist/useGridListItem';
|
|
21
|
+
import { useId } from '../utils/useId';
|
|
22
|
+
import { useInteractionModality } from '../interactions/useFocusVisible';
|
|
23
|
+
import { useLocalizedStringFormatter } from '../i18n/useLocalizedStringFormatter';
|
|
24
|
+
import { useSyntheticLinkProps } from '../utils/openLink';
|
|
25
|
+
|
|
26
|
+
import { S, splitSlot, subSlot } from '../internal';
|
|
27
|
+
|
|
28
|
+
// octane adaptation: minimal structural DOMAttributes (upstream's drags React's synthetic
|
|
29
|
+
// handler types along).
|
|
30
|
+
type DOMAttributes = Record<string, any>;
|
|
31
|
+
|
|
32
|
+
export interface TagAria extends SelectableItemStates {
|
|
33
|
+
/** Props for the tag row element. */
|
|
34
|
+
rowProps: DOMAttributes;
|
|
35
|
+
/** Props for the tag cell element. */
|
|
36
|
+
gridCellProps: DOMAttributes;
|
|
37
|
+
/** Props for the tag remove button. */
|
|
38
|
+
removeButtonProps: AriaButtonProps;
|
|
39
|
+
/** Whether the tag can be removed. */
|
|
40
|
+
allowsRemoving: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface AriaTagProps<T> {
|
|
44
|
+
/** An object representing the tag. Contains all the relevant information that makes up the tag. */
|
|
45
|
+
item: Node<T>;
|
|
46
|
+
// octane adaptation (part of upstream's surface via DOMProps/AriaLabelingProps reads
|
|
47
|
+
// below): optional aria attributes forwarded to the cell.
|
|
48
|
+
'aria-errormessage'?: string;
|
|
49
|
+
'aria-label'?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Provides the behavior and accessibility implementation for a tag component.
|
|
54
|
+
*
|
|
55
|
+
* @param props - Props to be applied to the tag.
|
|
56
|
+
* @param state - State for the tag group, as returned by `useListState`.
|
|
57
|
+
* @param ref - A ref to a DOM element for the tag.
|
|
58
|
+
*/
|
|
59
|
+
export function useTag<T>(
|
|
60
|
+
props: AriaTagProps<T>,
|
|
61
|
+
state: ListState<T>,
|
|
62
|
+
ref: RefObject<FocusableElement | null>,
|
|
63
|
+
): TagAria;
|
|
64
|
+
// Slot-threading form: sibling ported hooks pass their derived sub-slot as the trailing arg.
|
|
65
|
+
export function useTag<T>(
|
|
66
|
+
props: AriaTagProps<T>,
|
|
67
|
+
state: ListState<T>,
|
|
68
|
+
ref: RefObject<FocusableElement | null>,
|
|
69
|
+
slot: symbol | undefined,
|
|
70
|
+
): TagAria;
|
|
71
|
+
export function useTag(...args: any[]): TagAria {
|
|
72
|
+
const [user, slotArg] = splitSlot(args);
|
|
73
|
+
const slot = slotArg ?? S('useTag');
|
|
74
|
+
const props = user[0] as AriaTagProps<any>;
|
|
75
|
+
const state = user[1] as ListState<any>;
|
|
76
|
+
const ref = user[2] as RefObject<FocusableElement | null>;
|
|
77
|
+
|
|
78
|
+
let { item } = props;
|
|
79
|
+
let stringFormatter = useLocalizedStringFormatter(
|
|
80
|
+
intlMessages,
|
|
81
|
+
'@react-aria/tag',
|
|
82
|
+
subSlot(slot, 'strings'),
|
|
83
|
+
);
|
|
84
|
+
let buttonId = useId(subSlot(slot, 'buttonId'));
|
|
85
|
+
|
|
86
|
+
let { onRemove } = hookData.get(state) || {};
|
|
87
|
+
let { rowProps, gridCellProps, ...states } = useGridListItem(
|
|
88
|
+
{
|
|
89
|
+
node: item,
|
|
90
|
+
},
|
|
91
|
+
state,
|
|
92
|
+
ref,
|
|
93
|
+
subSlot(slot, 'gridListItem'),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
let { descriptionProps: _, ...stateWithoutDescription } = states;
|
|
97
|
+
|
|
98
|
+
let isDisabled = state.disabledKeys.has(item.key) || item.props.isDisabled;
|
|
99
|
+
let onKeyDown = (e: KeyboardEvent) => {
|
|
100
|
+
if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
101
|
+
if (isDisabled) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
if (state.selectionManager.isSelected(item.key)) {
|
|
107
|
+
onRemove?.(new Set(state.selectionManager.selectedKeys));
|
|
108
|
+
} else {
|
|
109
|
+
onRemove?.(new Set([item.key]));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
let modality = useInteractionModality(subSlot(slot, 'modality'));
|
|
115
|
+
if (modality === 'virtual' && typeof window !== 'undefined' && 'ontouchstart' in window) {
|
|
116
|
+
modality = 'pointer';
|
|
117
|
+
}
|
|
118
|
+
let description =
|
|
119
|
+
onRemove && (modality === 'keyboard' || modality === 'virtual')
|
|
120
|
+
? stringFormatter.format('removeDescription')
|
|
121
|
+
: '';
|
|
122
|
+
let descProps = useDescription(description, subSlot(slot, 'description'));
|
|
123
|
+
|
|
124
|
+
let isItemFocused = item.key === state.selectionManager.focusedKey;
|
|
125
|
+
let isFocused = state.selectionManager.focusedKey != null;
|
|
126
|
+
let tabIndex = -1;
|
|
127
|
+
if (!isDisabled && (isItemFocused || !isFocused)) {
|
|
128
|
+
tabIndex = 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let domProps = filterDOMProps(item.props);
|
|
132
|
+
let linkProps = useSyntheticLinkProps(item.props);
|
|
133
|
+
let { focusableProps } = useFocusable(
|
|
134
|
+
{
|
|
135
|
+
...item.props,
|
|
136
|
+
isDisabled,
|
|
137
|
+
},
|
|
138
|
+
ref,
|
|
139
|
+
subSlot(slot, 'focusable'),
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
removeButtonProps: {
|
|
144
|
+
'aria-label': stringFormatter.format('removeButtonLabel'),
|
|
145
|
+
'aria-labelledby': `${buttonId} ${rowProps.id}`,
|
|
146
|
+
isDisabled,
|
|
147
|
+
id: buttonId,
|
|
148
|
+
onPress: () => (onRemove ? onRemove(new Set([item.key])) : null),
|
|
149
|
+
},
|
|
150
|
+
rowProps: mergeProps(focusableProps, rowProps, domProps, linkProps, {
|
|
151
|
+
tabIndex,
|
|
152
|
+
onKeyDown: onRemove ? onKeyDown : undefined,
|
|
153
|
+
'aria-describedby': descProps['aria-describedby'],
|
|
154
|
+
}),
|
|
155
|
+
gridCellProps: mergeProps(gridCellProps, {
|
|
156
|
+
'aria-errormessage': props['aria-errormessage'],
|
|
157
|
+
'aria-label': props['aria-label'],
|
|
158
|
+
}),
|
|
159
|
+
...stateWithoutDescription,
|
|
160
|
+
allowsRemoving: !!onRemove,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Ported from react-aria (source: .react-spectrum/packages/react-aria/src/tag/useTagGroup.ts).
|
|
2
|
+
// octane adaptations:
|
|
3
|
+
// - `ListState` comes from the ported stately list hook; `DOMAttributes` is a local
|
|
4
|
+
// structural prop-bag alias; React's `ReactNode` errorMessage type → `any` (octane
|
|
5
|
+
// renderables).
|
|
6
|
+
// - Public-hook slot threading (splitSlot/subSlot); explicit dependency arrays are kept
|
|
7
|
+
// verbatim.
|
|
8
|
+
import { AriaGridListProps, useGridList } from '../gridlist/useGridList';
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
AriaLabelingProps,
|
|
12
|
+
CollectionBase,
|
|
13
|
+
DOMProps,
|
|
14
|
+
HelpTextProps,
|
|
15
|
+
Key,
|
|
16
|
+
KeyboardDelegate,
|
|
17
|
+
LabelableProps,
|
|
18
|
+
MultipleSelection,
|
|
19
|
+
RefObject,
|
|
20
|
+
SelectionBehavior,
|
|
21
|
+
} from '@react-types/shared';
|
|
22
|
+
import { filterDOMProps } from '../utils/filterDOMProps';
|
|
23
|
+
import { ListKeyboardDelegate } from '../selection/ListKeyboardDelegate';
|
|
24
|
+
import type { ListState } from '../stately/list/useListState';
|
|
25
|
+
import { mergeProps } from '../utils/mergeProps';
|
|
26
|
+
import { useEffect, useRef, useState } from 'octane';
|
|
27
|
+
import { useField } from '../label/useField';
|
|
28
|
+
import { useFocusWithin } from '../interactions/useFocusWithin';
|
|
29
|
+
import { useLocale } from '../i18n/I18nProvider';
|
|
30
|
+
|
|
31
|
+
import { S, splitSlot, subSlot } from '../internal';
|
|
32
|
+
|
|
33
|
+
// octane adaptation: minimal structural DOMAttributes (upstream's drags React's synthetic
|
|
34
|
+
// handler types along).
|
|
35
|
+
type DOMAttributes = Record<string, any>;
|
|
36
|
+
|
|
37
|
+
export interface TagGroupAria {
|
|
38
|
+
/** Props for the tag grouping element. */
|
|
39
|
+
gridProps: DOMAttributes;
|
|
40
|
+
/** Props for the tag group's visible label (if any). */
|
|
41
|
+
labelProps: DOMAttributes;
|
|
42
|
+
/** Props for the tag group description element, if any. */
|
|
43
|
+
descriptionProps: DOMAttributes;
|
|
44
|
+
/** Props for the tag group error message element, if any. */
|
|
45
|
+
errorMessageProps: DOMAttributes;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface AriaTagGroupProps<T>
|
|
49
|
+
extends
|
|
50
|
+
CollectionBase<T>,
|
|
51
|
+
MultipleSelection,
|
|
52
|
+
Pick<AriaGridListProps<T>, 'escapeKeyBehavior' | 'onAction'>,
|
|
53
|
+
DOMProps,
|
|
54
|
+
LabelableProps,
|
|
55
|
+
AriaLabelingProps,
|
|
56
|
+
Omit<HelpTextProps, 'errorMessage'> {
|
|
57
|
+
/**
|
|
58
|
+
* How multiple selection should behave in the collection.
|
|
59
|
+
*
|
|
60
|
+
* @default 'toggle'
|
|
61
|
+
*/
|
|
62
|
+
selectionBehavior?: SelectionBehavior;
|
|
63
|
+
/** Whether selection should occur on press up instead of press down. */
|
|
64
|
+
shouldSelectOnPressUp?: boolean;
|
|
65
|
+
/** Handler that is called when a user deletes a tag. */
|
|
66
|
+
onRemove?: (keys: Set<Key>) => void;
|
|
67
|
+
/** An error message for the field. */
|
|
68
|
+
errorMessage?: any;
|
|
69
|
+
/**
|
|
70
|
+
* Whether pressing the escape key should clear selection in the TagGroup or not.
|
|
71
|
+
*
|
|
72
|
+
* Most experiences should not modify this option as it eliminates a keyboard user's ability to
|
|
73
|
+
* easily clear selection. Only use if the escape key is being handled externally or should not
|
|
74
|
+
* trigger selection clearing contextually.
|
|
75
|
+
*
|
|
76
|
+
* @default 'clearSelection'
|
|
77
|
+
*/
|
|
78
|
+
escapeKeyBehavior?: 'clearSelection' | 'none';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface AriaTagGroupOptions<T> extends Omit<AriaTagGroupProps<T>, 'children'> {
|
|
82
|
+
/**
|
|
83
|
+
* An optional keyboard delegate to handle arrow key navigation,
|
|
84
|
+
* to override the default.
|
|
85
|
+
*/
|
|
86
|
+
keyboardDelegate?: KeyboardDelegate;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface HookData {
|
|
90
|
+
onRemove?: (keys: Set<Key>) => void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const hookData: WeakMap<ListState<any>, HookData> = new WeakMap<ListState<any>, HookData>();
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Provides the behavior and accessibility implementation for a tag group component. A tag group is
|
|
97
|
+
* a focusable list of labels, categories, keywords, filters, or other items, with support for
|
|
98
|
+
* keyboard navigation, selection, and removal.
|
|
99
|
+
*
|
|
100
|
+
* @param props - Props to be applied to the tag group.
|
|
101
|
+
* @param state - State for the tag group, as returned by `useListState`.
|
|
102
|
+
* @param ref - A ref to a DOM element for the tag group.
|
|
103
|
+
*/
|
|
104
|
+
export function useTagGroup<T>(
|
|
105
|
+
props: AriaTagGroupOptions<T>,
|
|
106
|
+
state: ListState<T>,
|
|
107
|
+
ref: RefObject<HTMLElement | null>,
|
|
108
|
+
): TagGroupAria;
|
|
109
|
+
// Slot-threading form: sibling ported hooks pass their derived sub-slot as the trailing arg.
|
|
110
|
+
export function useTagGroup<T>(
|
|
111
|
+
props: AriaTagGroupOptions<T>,
|
|
112
|
+
state: ListState<T>,
|
|
113
|
+
ref: RefObject<HTMLElement | null>,
|
|
114
|
+
slot: symbol | undefined,
|
|
115
|
+
): TagGroupAria;
|
|
116
|
+
export function useTagGroup(...args: any[]): TagGroupAria {
|
|
117
|
+
const [user, slotArg] = splitSlot(args);
|
|
118
|
+
const slot = slotArg ?? S('useTagGroup');
|
|
119
|
+
const props = user[0] as AriaTagGroupOptions<any>;
|
|
120
|
+
const state = user[1] as ListState<any>;
|
|
121
|
+
const ref = user[2] as RefObject<HTMLElement | null>;
|
|
122
|
+
|
|
123
|
+
let { direction } = useLocale(subSlot(slot, 'locale'));
|
|
124
|
+
let keyboardDelegate =
|
|
125
|
+
props.keyboardDelegate ||
|
|
126
|
+
new ListKeyboardDelegate({
|
|
127
|
+
collection: state.collection,
|
|
128
|
+
ref,
|
|
129
|
+
orientation: 'horizontal',
|
|
130
|
+
direction,
|
|
131
|
+
disabledKeys: state.disabledKeys,
|
|
132
|
+
disabledBehavior: state.selectionManager.disabledBehavior,
|
|
133
|
+
});
|
|
134
|
+
let { labelProps, fieldProps, descriptionProps, errorMessageProps } = useField(
|
|
135
|
+
{
|
|
136
|
+
...props,
|
|
137
|
+
labelElementType: 'span',
|
|
138
|
+
},
|
|
139
|
+
subSlot(slot, 'field'),
|
|
140
|
+
);
|
|
141
|
+
let { gridProps } = useGridList(
|
|
142
|
+
{
|
|
143
|
+
...props,
|
|
144
|
+
...fieldProps,
|
|
145
|
+
keyboardDelegate,
|
|
146
|
+
shouldFocusWrap: true,
|
|
147
|
+
linkBehavior: 'override',
|
|
148
|
+
keyboardNavigationBehavior: 'tab',
|
|
149
|
+
},
|
|
150
|
+
state,
|
|
151
|
+
ref,
|
|
152
|
+
subSlot(slot, 'gridList'),
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
let [isFocusWithin, setFocusWithin] = useState(false, subSlot(slot, 'focusWithin'));
|
|
156
|
+
let { focusWithinProps } = useFocusWithin(
|
|
157
|
+
{
|
|
158
|
+
onFocusWithinChange: setFocusWithin,
|
|
159
|
+
},
|
|
160
|
+
subSlot(slot, 'focusWithinHook'),
|
|
161
|
+
);
|
|
162
|
+
let domProps = filterDOMProps(props);
|
|
163
|
+
|
|
164
|
+
// If the last tag is removed, focus the container.
|
|
165
|
+
let prevCount = useRef(state.collection.size, subSlot(slot, 'prevCount'));
|
|
166
|
+
useEffect(
|
|
167
|
+
() => {
|
|
168
|
+
if (ref.current && prevCount.current > 0 && state.collection.size === 0 && isFocusWithin) {
|
|
169
|
+
ref.current.focus();
|
|
170
|
+
}
|
|
171
|
+
prevCount.current = state.collection.size;
|
|
172
|
+
},
|
|
173
|
+
[state.collection.size, isFocusWithin, ref],
|
|
174
|
+
subSlot(slot, 'focusContainerFx'),
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
hookData.set(state, { onRemove: props.onRemove });
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
gridProps: mergeProps(gridProps, domProps, {
|
|
181
|
+
role: state.collection.size ? 'grid' : 'group',
|
|
182
|
+
'aria-atomic': false,
|
|
183
|
+
'aria-relevant': 'additions',
|
|
184
|
+
'aria-live': isFocusWithin ? 'polite' : 'off',
|
|
185
|
+
...focusWithinProps,
|
|
186
|
+
...fieldProps,
|
|
187
|
+
}),
|
|
188
|
+
labelProps,
|
|
189
|
+
descriptionProps,
|
|
190
|
+
errorMessageProps,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Ported from react-aria (source: .react-spectrum/packages/react-aria/src/textfield/useFormattedTextField.ts).
|
|
2
|
+
// octane adaptations:
|
|
3
|
+
// - Handlers receive NATIVE events: octane's `onBeforeInput` prop IS the native
|
|
4
|
+
// `beforeinput` event, so the upstream "React polyfill" fallback branch (for browsers
|
|
5
|
+
// without native beforeinput support) receives the same native InputEvent as the
|
|
6
|
+
// directly-attached listener; the handler logic ports unchanged.
|
|
7
|
+
// - `InputEventHandler` React type → a plain native-InputEvent handler.
|
|
8
|
+
// - Public-hook slot threading; explicit dependency arrays are kept verbatim.
|
|
9
|
+
import { AriaTextFieldProps, TextFieldAria, useTextField } from './useTextField';
|
|
10
|
+
import { getEventTarget } from '../utils/shadowdom/DOMFunctions';
|
|
11
|
+
import { useEffect, useRef } from 'octane';
|
|
12
|
+
import { mergeProps } from '../utils/mergeProps';
|
|
13
|
+
import type { RefObject } from '@react-types/shared';
|
|
14
|
+
import { useEffectEvent } from '../utils/useEffectEvent';
|
|
15
|
+
|
|
16
|
+
import { S, splitSlot, subSlot } from '../internal';
|
|
17
|
+
|
|
18
|
+
interface FormattedTextFieldState {
|
|
19
|
+
validate: (val: string) => boolean;
|
|
20
|
+
setInputValue: (val: string) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function supportsNativeBeforeInputEvent() {
|
|
24
|
+
return (
|
|
25
|
+
typeof window !== 'undefined' &&
|
|
26
|
+
window.InputEvent &&
|
|
27
|
+
typeof InputEvent.prototype.getTargetRanges === 'function'
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useFormattedTextField(
|
|
32
|
+
props: AriaTextFieldProps,
|
|
33
|
+
state: FormattedTextFieldState,
|
|
34
|
+
inputRef: RefObject<HTMLInputElement | null>,
|
|
35
|
+
): TextFieldAria;
|
|
36
|
+
// Slot-threading form: sibling ported hooks pass their derived sub-slot as the trailing arg.
|
|
37
|
+
export function useFormattedTextField(
|
|
38
|
+
props: AriaTextFieldProps,
|
|
39
|
+
state: FormattedTextFieldState,
|
|
40
|
+
inputRef: RefObject<HTMLInputElement | null>,
|
|
41
|
+
slot: symbol | undefined,
|
|
42
|
+
): TextFieldAria;
|
|
43
|
+
export function useFormattedTextField(...args: any[]): TextFieldAria {
|
|
44
|
+
const [user, slotArg] = splitSlot(args);
|
|
45
|
+
const slot = slotArg ?? S('useFormattedTextField');
|
|
46
|
+
const props = user[0] as AriaTextFieldProps;
|
|
47
|
+
const state = user[1] as FormattedTextFieldState;
|
|
48
|
+
const inputRef = user[2] as RefObject<HTMLInputElement | null>;
|
|
49
|
+
|
|
50
|
+
// All browsers implement the 'beforeinput' event natively except Firefox
|
|
51
|
+
// (currently behind a flag as of Firefox 84). React's polyfill does not
|
|
52
|
+
// run in all cases that the native event fires, e.g. when deleting text.
|
|
53
|
+
// Use the native event if available so that we can prevent invalid deletions.
|
|
54
|
+
// We do not attempt to polyfill this in Firefox since it would be very complicated,
|
|
55
|
+
// the benefit of doing so is fairly minor, and it's going to be natively supported soon.
|
|
56
|
+
let onBeforeInputFallback = useEffectEvent(
|
|
57
|
+
(e: InputEvent) => {
|
|
58
|
+
let input = inputRef.current;
|
|
59
|
+
if (!input) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Compute the next value of the input if the event is allowed to proceed.
|
|
64
|
+
// See https://www.w3.org/TR/input-events-2/#interface-InputEvent-Attributes for a full list of input types.
|
|
65
|
+
let nextValue: string | null = null;
|
|
66
|
+
switch (e.inputType) {
|
|
67
|
+
case 'historyUndo':
|
|
68
|
+
case 'historyRedo':
|
|
69
|
+
// Explicitly allow undo/redo. e.data is null in this case, but there's no need to validate,
|
|
70
|
+
// because presumably the input would have already been validated previously.
|
|
71
|
+
return;
|
|
72
|
+
case 'insertLineBreak':
|
|
73
|
+
// Explicitly allow "insertLineBreak" event, to allow onSubmit for "enter" key. e.data is null in this case.
|
|
74
|
+
return;
|
|
75
|
+
case 'deleteContent':
|
|
76
|
+
case 'deleteByCut':
|
|
77
|
+
case 'deleteByDrag':
|
|
78
|
+
nextValue =
|
|
79
|
+
input.value.slice(0, input.selectionStart!) + input.value.slice(input.selectionEnd!);
|
|
80
|
+
break;
|
|
81
|
+
case 'deleteContentForward':
|
|
82
|
+
// This is potentially incorrect, since the browser may actually delete more than a single UTF-16
|
|
83
|
+
// character. In reality, a full Unicode grapheme cluster consisting of multiple UTF-16 characters
|
|
84
|
+
// or code points may be deleted. However, in our currently supported locales, there are no such cases.
|
|
85
|
+
// If we support additional locales in the future, this may need to change.
|
|
86
|
+
nextValue =
|
|
87
|
+
input.selectionEnd === input.selectionStart
|
|
88
|
+
? input.value.slice(0, input.selectionStart!) +
|
|
89
|
+
input.value.slice(input.selectionEnd! + 1)
|
|
90
|
+
: input.value.slice(0, input.selectionStart!) +
|
|
91
|
+
input.value.slice(input.selectionEnd!);
|
|
92
|
+
break;
|
|
93
|
+
case 'deleteContentBackward':
|
|
94
|
+
nextValue =
|
|
95
|
+
input.selectionEnd === input.selectionStart
|
|
96
|
+
? input.value.slice(0, input.selectionStart! - 1) +
|
|
97
|
+
input.value.slice(input.selectionStart!)
|
|
98
|
+
: input.value.slice(0, input.selectionStart!) +
|
|
99
|
+
input.value.slice(input.selectionEnd!);
|
|
100
|
+
break;
|
|
101
|
+
case 'deleteSoftLineBackward':
|
|
102
|
+
case 'deleteHardLineBackward':
|
|
103
|
+
nextValue = input.value.slice(input.selectionStart!);
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
if (e.data != null) {
|
|
107
|
+
nextValue =
|
|
108
|
+
input.value.slice(0, input.selectionStart!) +
|
|
109
|
+
e.data +
|
|
110
|
+
input.value.slice(input.selectionEnd!);
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// If we did not compute a value, or the new value is invalid, prevent the event
|
|
116
|
+
// so that the browser does not update the input text, move the selection, or add to
|
|
117
|
+
// the undo/redo stack.
|
|
118
|
+
if (nextValue == null || !state.validate(nextValue)) {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
subSlot(slot, 'beforeInputFallback'),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
useEffect(
|
|
126
|
+
() => {
|
|
127
|
+
if (!supportsNativeBeforeInputEvent() || !inputRef.current) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let input = inputRef.current;
|
|
132
|
+
input.addEventListener('beforeinput', onBeforeInputFallback, false);
|
|
133
|
+
return () => {
|
|
134
|
+
input.removeEventListener('beforeinput', onBeforeInputFallback, false);
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
[inputRef],
|
|
138
|
+
subSlot(slot, 'beforeInputFx'),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
let onBeforeInput: ((e: InputEvent) => void) | null = !supportsNativeBeforeInputEvent()
|
|
142
|
+
? (e: InputEvent) => {
|
|
143
|
+
let target = getEventTarget(e) as HTMLInputElement;
|
|
144
|
+
let nextValue =
|
|
145
|
+
target.value.slice(0, target.selectionStart!) +
|
|
146
|
+
e.data +
|
|
147
|
+
target.value.slice(target.selectionEnd!);
|
|
148
|
+
|
|
149
|
+
if (!state.validate(nextValue)) {
|
|
150
|
+
e.preventDefault();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
: null;
|
|
154
|
+
|
|
155
|
+
let {
|
|
156
|
+
labelProps,
|
|
157
|
+
inputProps: textFieldProps,
|
|
158
|
+
descriptionProps,
|
|
159
|
+
errorMessageProps,
|
|
160
|
+
...validation
|
|
161
|
+
} = useTextField(props, inputRef, subSlot(slot, 'textField'));
|
|
162
|
+
|
|
163
|
+
let compositionStartState = useRef<{
|
|
164
|
+
value: string;
|
|
165
|
+
selectionStart: number | null;
|
|
166
|
+
selectionEnd: number | null;
|
|
167
|
+
} | null>(null, subSlot(slot, 'compositionStart'));
|
|
168
|
+
return {
|
|
169
|
+
inputProps: mergeProps(textFieldProps, {
|
|
170
|
+
onBeforeInput,
|
|
171
|
+
onCompositionStart() {
|
|
172
|
+
// Chrome does not implement Input Events Level 2, which specifies the insertFromComposition
|
|
173
|
+
// and deleteByComposition inputType values for the beforeinput event. These are meant to occur
|
|
174
|
+
// at the end of a composition (e.g. Pinyin IME, Android auto correct, etc.), and crucially, are
|
|
175
|
+
// cancelable. The insertCompositionText and deleteCompositionText input types are not cancelable,
|
|
176
|
+
// nor would we want to cancel them because the input from the user is incomplete at that point.
|
|
177
|
+
// In Safari, insertFromComposition/deleteFromComposition will fire, however, allowing us to cancel
|
|
178
|
+
// the final composition result if it is invalid. As a fallback for Chrome and Firefox, which either
|
|
179
|
+
// don't support Input Events Level 2, or beforeinput at all, we store the state of the input when
|
|
180
|
+
// the compositionstart event fires, and undo the changes in compositionend (below) if it is invalid.
|
|
181
|
+
// Unfortunately, this messes up the undo/redo stack, but until insertFromComposition/deleteByComposition
|
|
182
|
+
// are implemented, there is no other way to prevent composed input.
|
|
183
|
+
// See https://bugs.chromium.org/p/chromium/issues/detail?id=1022204
|
|
184
|
+
let { value, selectionStart, selectionEnd } = inputRef.current!;
|
|
185
|
+
compositionStartState.current = { value, selectionStart, selectionEnd };
|
|
186
|
+
},
|
|
187
|
+
onCompositionEnd() {
|
|
188
|
+
if (inputRef.current && !state.validate(inputRef.current.value)) {
|
|
189
|
+
// Restore the input value in the DOM immediately so we can synchronously update the selection position.
|
|
190
|
+
// But also update the value in state as well so it is correct for future updates.
|
|
191
|
+
let { value, selectionStart, selectionEnd } = compositionStartState.current!;
|
|
192
|
+
inputRef.current.value = value;
|
|
193
|
+
inputRef.current.setSelectionRange(selectionStart, selectionEnd);
|
|
194
|
+
state.setInputValue(value);
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
}),
|
|
198
|
+
labelProps,
|
|
199
|
+
descriptionProps,
|
|
200
|
+
errorMessageProps,
|
|
201
|
+
...validation,
|
|
202
|
+
};
|
|
203
|
+
}
|