@octanejs/aria 0.0.1 → 0.0.3
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,602 @@
|
|
|
1
|
+
// Ported from react-aria (source: .react-spectrum/packages/react-aria/src/combobox/useComboBox.ts).
|
|
2
|
+
// octane adaptations:
|
|
3
|
+
// - The combobox text input is a TEXT input: upstream feeds the input value via a synthetic
|
|
4
|
+
// `onChange` passed to useTextField. octane's useTextField already wires that `onChange`
|
|
5
|
+
// onto the NATIVE `input` event (see textfield/useTextField.ts). So this port keeps
|
|
6
|
+
// `onChange: state.setInputValue` VERBATIM — the onChange→onInput DOM wiring lives in
|
|
7
|
+
// useTextField, and the value-level `onInputChange(value)` public callback is unchanged.
|
|
8
|
+
// - onKeyDown receives the ported BaseEvent Proxy (from useKeyboard/createEventHandler via
|
|
9
|
+
// useTextField's useFocusable). `.nativeEvent.isComposing` → `e.isComposing` (the Proxy
|
|
10
|
+
// forwards the read to the live native event); `continuePropagation`/`preventDefault` work
|
|
11
|
+
// through the Proxy. FocusEvent/TouchEvent become native DOM events; element types → `any`.
|
|
12
|
+
// - The Parcel glob intl import becomes the generated '../intl/combobox' dictionary index.
|
|
13
|
+
// - Public-hook slot threading (splitSlot/subSlot) per the binding convention; the module-local
|
|
14
|
+
// `useValueId` helper takes a threaded slot; dep-less upstream useEffects become explicit `null`.
|
|
15
|
+
import type {
|
|
16
|
+
AriaLabelingProps,
|
|
17
|
+
DOMProps,
|
|
18
|
+
InputDOMProps,
|
|
19
|
+
KeyboardDelegate,
|
|
20
|
+
LayoutDelegate,
|
|
21
|
+
PressEvent,
|
|
22
|
+
RefObject,
|
|
23
|
+
RouterOptions,
|
|
24
|
+
ValidationResult,
|
|
25
|
+
} from '@react-types/shared';
|
|
26
|
+
import { useEffect, useMemo, useRef, useState } from 'octane';
|
|
27
|
+
|
|
28
|
+
import { announce } from '../live-announcer/LiveAnnouncer';
|
|
29
|
+
import type { AriaButtonProps } from '../button/useButton';
|
|
30
|
+
import { ariaHideOutside } from '../overlays/ariaHideOutside';
|
|
31
|
+
import type { AriaListBoxOptions } from '../listbox/useListBox';
|
|
32
|
+
import { chain } from '../utils/chain';
|
|
33
|
+
import {
|
|
34
|
+
type ComboBoxState,
|
|
35
|
+
type SelectionMode,
|
|
36
|
+
type ComboBoxProps,
|
|
37
|
+
} from '../stately/combobox/useComboBoxState';
|
|
38
|
+
import { dispatchVirtualFocus } from '../focus/virtualFocus';
|
|
39
|
+
import { getActiveElement, getEventTarget, nodeContains } from '../utils/shadowdom/DOMFunctions';
|
|
40
|
+
import { getChildNodes } from '../stately/collections/getChildNodes';
|
|
41
|
+
import { getItemCount } from '../stately/collections/getItemCount';
|
|
42
|
+
import { getItemId, listData } from '../listbox/utils';
|
|
43
|
+
import { getOwnerDocument } from '../utils/domHelpers';
|
|
44
|
+
import intlMessages from '../intl/combobox';
|
|
45
|
+
import { isAppleDevice } from '../utils/platform';
|
|
46
|
+
import { ListKeyboardDelegate } from '../selection/ListKeyboardDelegate';
|
|
47
|
+
import { mergeProps } from '../utils/mergeProps';
|
|
48
|
+
import { privateValidationStateProp } from '../stately/form/useFormValidationState';
|
|
49
|
+
import { useEvent } from '../utils/useEvent';
|
|
50
|
+
import { useFormReset } from '../utils/useFormReset';
|
|
51
|
+
import { useId } from '../utils/useId';
|
|
52
|
+
import { useLabels } from '../utils/useLabels';
|
|
53
|
+
import { useLocalizedStringFormatter } from '../i18n/useLocalizedStringFormatter';
|
|
54
|
+
import { useMenuTrigger } from '../menu/useMenuTrigger';
|
|
55
|
+
import { useRouter } from '../utils/openLink';
|
|
56
|
+
import { useSelectableCollection } from '../selection/useSelectableCollection';
|
|
57
|
+
import { useTextField } from '../textfield/useTextField';
|
|
58
|
+
import { useUpdateEffect } from '../utils/useUpdateEffect';
|
|
59
|
+
|
|
60
|
+
import { S, splitSlot, subSlot } from '../internal';
|
|
61
|
+
|
|
62
|
+
// octane adaptation: element/DOM attribute types collapse to structural bags (upstream's
|
|
63
|
+
// versions are typed over React's SyntheticEvent / JSX intrinsic-element machinery).
|
|
64
|
+
type DOMAttributes = Record<string, any>;
|
|
65
|
+
|
|
66
|
+
export interface AriaComboBoxProps<T, M extends SelectionMode = 'single'>
|
|
67
|
+
extends ComboBoxProps<T, M>, DOMProps, InputDOMProps, AriaLabelingProps {
|
|
68
|
+
/** Whether keyboard navigation is circular. */
|
|
69
|
+
shouldFocusWrap?: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface AriaComboBoxOptions<T, M extends SelectionMode = 'single'> extends Omit<
|
|
73
|
+
AriaComboBoxProps<T, M>,
|
|
74
|
+
'children'
|
|
75
|
+
> {
|
|
76
|
+
/** The ref for the input element. */
|
|
77
|
+
inputRef: RefObject<HTMLInputElement | null>;
|
|
78
|
+
/** The ref for the list box popover. */
|
|
79
|
+
popoverRef: RefObject<Element | null>;
|
|
80
|
+
/** The ref for the list box. */
|
|
81
|
+
listBoxRef: RefObject<HTMLElement | null>;
|
|
82
|
+
/** The ref for the optional list box popup trigger button. */
|
|
83
|
+
buttonRef?: RefObject<Element | null>;
|
|
84
|
+
/** An optional keyboard delegate implementation, to override the default. */
|
|
85
|
+
keyboardDelegate?: KeyboardDelegate;
|
|
86
|
+
/**
|
|
87
|
+
* A delegate object that provides layout information for items in the collection.
|
|
88
|
+
* By default this uses the DOM, but this can be overridden to implement things like
|
|
89
|
+
* virtualized scrolling.
|
|
90
|
+
*/
|
|
91
|
+
layoutDelegate?: LayoutDelegate;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface ComboBoxAria<T> extends ValidationResult {
|
|
95
|
+
/** Props for the label element. */
|
|
96
|
+
labelProps: DOMAttributes;
|
|
97
|
+
/** Props for the combo box input element. */
|
|
98
|
+
inputProps: DOMAttributes;
|
|
99
|
+
/** Props for the list box, to be passed to `useListBox`. */
|
|
100
|
+
listBoxProps: AriaListBoxOptions<T>;
|
|
101
|
+
/** Props for the optional trigger button, to be passed to `useButton`. */
|
|
102
|
+
buttonProps: AriaButtonProps;
|
|
103
|
+
/** Props for the element representing the selected value. */
|
|
104
|
+
valueProps: DOMAttributes;
|
|
105
|
+
/** Props for the combo box description element, if any. */
|
|
106
|
+
descriptionProps: DOMAttributes;
|
|
107
|
+
/** Props for the combo box error message element, if any. */
|
|
108
|
+
errorMessageProps: DOMAttributes;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Provides the behavior and accessibility implementation for a combo box component. A combo box
|
|
113
|
+
* combines a text input with a listbox, allowing users to filter a list of options to items
|
|
114
|
+
* matching a query.
|
|
115
|
+
*
|
|
116
|
+
* @param props - Props for the combo box.
|
|
117
|
+
* @param state - State for the select, as returned by `useComboBoxState`.
|
|
118
|
+
*/
|
|
119
|
+
export function useComboBox<T, M extends SelectionMode = 'single'>(
|
|
120
|
+
props: AriaComboBoxOptions<T, M>,
|
|
121
|
+
state: ComboBoxState<T, M>,
|
|
122
|
+
): ComboBoxAria<T>;
|
|
123
|
+
// Slot-threading form: sibling ported hooks pass their derived sub-slot as the trailing arg.
|
|
124
|
+
export function useComboBox<T, M extends SelectionMode = 'single'>(
|
|
125
|
+
props: AriaComboBoxOptions<T, M>,
|
|
126
|
+
state: ComboBoxState<T, M>,
|
|
127
|
+
slot: symbol | undefined,
|
|
128
|
+
): ComboBoxAria<T>;
|
|
129
|
+
export function useComboBox(...args: any[]): ComboBoxAria<any> {
|
|
130
|
+
const [user, slotArg] = splitSlot(args);
|
|
131
|
+
const slot = slotArg ?? S('useComboBox');
|
|
132
|
+
const props = user[0] as AriaComboBoxOptions<any, any>;
|
|
133
|
+
const state = user[1] as ComboBoxState<any, any>;
|
|
134
|
+
|
|
135
|
+
let {
|
|
136
|
+
buttonRef,
|
|
137
|
+
popoverRef,
|
|
138
|
+
inputRef,
|
|
139
|
+
listBoxRef,
|
|
140
|
+
keyboardDelegate,
|
|
141
|
+
layoutDelegate,
|
|
142
|
+
// completionMode = 'suggest',
|
|
143
|
+
shouldFocusWrap,
|
|
144
|
+
isReadOnly,
|
|
145
|
+
isDisabled,
|
|
146
|
+
} = props;
|
|
147
|
+
let backupBtnRef = useRef(null, subSlot(slot, 'backupBtn'));
|
|
148
|
+
buttonRef = buttonRef ?? backupBtnRef;
|
|
149
|
+
|
|
150
|
+
let stringFormatter = useLocalizedStringFormatter(
|
|
151
|
+
intlMessages,
|
|
152
|
+
'@react-aria/combobox',
|
|
153
|
+
subSlot(slot, 'formatter'),
|
|
154
|
+
);
|
|
155
|
+
let { menuTriggerProps, menuProps } = useMenuTrigger<any>(
|
|
156
|
+
{
|
|
157
|
+
type: 'listbox',
|
|
158
|
+
isDisabled: isDisabled || isReadOnly,
|
|
159
|
+
},
|
|
160
|
+
state,
|
|
161
|
+
buttonRef,
|
|
162
|
+
subSlot(slot, 'menuTrigger'),
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
// Set listbox id so it can be used when calling getItemId later
|
|
166
|
+
listData.set(state, { id: menuProps.id });
|
|
167
|
+
|
|
168
|
+
// By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
|
|
169
|
+
// When virtualized, the layout object will be passed in as a prop and override this.
|
|
170
|
+
let { collection } = state;
|
|
171
|
+
let { disabledKeys } = state.selectionManager;
|
|
172
|
+
let delegate = useMemo(
|
|
173
|
+
() =>
|
|
174
|
+
keyboardDelegate ||
|
|
175
|
+
new ListKeyboardDelegate({
|
|
176
|
+
collection,
|
|
177
|
+
disabledKeys,
|
|
178
|
+
ref: listBoxRef,
|
|
179
|
+
layoutDelegate,
|
|
180
|
+
}),
|
|
181
|
+
[keyboardDelegate, layoutDelegate, collection, disabledKeys, listBoxRef],
|
|
182
|
+
subSlot(slot, 'delegate'),
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
// Use useSelectableCollection to get the keyboard handlers to apply to the textfield
|
|
186
|
+
let { collectionProps } = useSelectableCollection(
|
|
187
|
+
{
|
|
188
|
+
selectionManager: state.selectionManager,
|
|
189
|
+
keyboardDelegate: delegate,
|
|
190
|
+
disallowTypeAhead: true,
|
|
191
|
+
disallowEmptySelection: true,
|
|
192
|
+
shouldFocusWrap,
|
|
193
|
+
ref: inputRef,
|
|
194
|
+
// Prevent item scroll behavior from being applied here, should be handled in the user's Popover + ListBox component
|
|
195
|
+
isVirtualized: true,
|
|
196
|
+
},
|
|
197
|
+
subSlot(slot, 'selectable'),
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
let router = useRouter();
|
|
201
|
+
|
|
202
|
+
// For textfield specific keydown operations
|
|
203
|
+
let onKeyDown = (e: any) => {
|
|
204
|
+
// octane adaptation: `.nativeEvent.isComposing` → `e.isComposing` (the BaseEvent Proxy
|
|
205
|
+
// forwards the read to the live native event).
|
|
206
|
+
if (e.isComposing) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
switch (e.key) {
|
|
210
|
+
case 'Enter':
|
|
211
|
+
case 'Tab':
|
|
212
|
+
// Prevent form submission if menu is open since we may be selecting a option
|
|
213
|
+
if (state.isOpen && e.key === 'Enter') {
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// If the focused item is a link, trigger opening it. Items that are links are not selectable.
|
|
218
|
+
if (state.isOpen && listBoxRef.current && state.selectionManager.focusedKey != null) {
|
|
219
|
+
let collectionItem = state.collection.getItem(state.selectionManager.focusedKey);
|
|
220
|
+
if (collectionItem?.props.href) {
|
|
221
|
+
let item = listBoxRef.current.querySelector(
|
|
222
|
+
`[data-key="${CSS.escape(state.selectionManager.focusedKey.toString())}"]`,
|
|
223
|
+
);
|
|
224
|
+
if (e.key === 'Enter' && item instanceof HTMLAnchorElement) {
|
|
225
|
+
router.open(
|
|
226
|
+
item,
|
|
227
|
+
e,
|
|
228
|
+
collectionItem.props.href,
|
|
229
|
+
collectionItem.props.routerOptions as RouterOptions,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
state.close();
|
|
233
|
+
break;
|
|
234
|
+
} else if (collectionItem?.props.onAction) {
|
|
235
|
+
collectionItem.props.onAction();
|
|
236
|
+
state.close();
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (e.key === 'Enter' || state.isOpen) {
|
|
241
|
+
state.commit();
|
|
242
|
+
}
|
|
243
|
+
if (e.key === 'Tab') {
|
|
244
|
+
e.continuePropagation();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
break;
|
|
248
|
+
case 'Escape':
|
|
249
|
+
if (!state.selectionManager.isEmpty || state.inputValue === '' || props.allowsCustomValue) {
|
|
250
|
+
e.continuePropagation();
|
|
251
|
+
}
|
|
252
|
+
state.revert();
|
|
253
|
+
break;
|
|
254
|
+
case 'ArrowDown':
|
|
255
|
+
state.open('first', 'manual');
|
|
256
|
+
break;
|
|
257
|
+
case 'ArrowUp':
|
|
258
|
+
state.open('last', 'manual');
|
|
259
|
+
break;
|
|
260
|
+
case 'ArrowLeft':
|
|
261
|
+
case 'ArrowRight':
|
|
262
|
+
state.selectionManager.setFocusedKey(null);
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
let onBlur = (e: any) => {
|
|
268
|
+
let blurFromButton = buttonRef?.current && buttonRef.current === e.relatedTarget;
|
|
269
|
+
let blurIntoPopover = nodeContains(popoverRef.current, e.relatedTarget);
|
|
270
|
+
// Ignore blur if focused moved to the button(if exists) or into the popover.
|
|
271
|
+
if (blurFromButton || blurIntoPopover) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (props.onBlur) {
|
|
276
|
+
props.onBlur(e);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
state.setFocused(false);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
let onFocus = (e: any) => {
|
|
283
|
+
if (state.isFocused) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (props.onFocus) {
|
|
288
|
+
props.onFocus(e);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
state.setFocused(true);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
let valueId = useValueId(
|
|
295
|
+
[state.selectionManager.selectedKeys, state.selectionManager.selectionMode],
|
|
296
|
+
subSlot(slot, 'valueId'),
|
|
297
|
+
);
|
|
298
|
+
let { isInvalid, validationErrors, validationDetails } = state.displayValidation;
|
|
299
|
+
let { labelProps, inputProps, descriptionProps, errorMessageProps } = useTextField(
|
|
300
|
+
{
|
|
301
|
+
...props,
|
|
302
|
+
// In multi-select mode, only set required if the selection is empty.
|
|
303
|
+
isRequired:
|
|
304
|
+
props.selectionMode === 'multiple'
|
|
305
|
+
? props.isRequired && state.selectionManager.isEmpty
|
|
306
|
+
: props.isRequired,
|
|
307
|
+
onChange: state.setInputValue,
|
|
308
|
+
onKeyDown: !isReadOnly
|
|
309
|
+
? chain(state.isOpen && collectionProps.onKeyDown, onKeyDown, props.onKeyDown)
|
|
310
|
+
: props.onKeyDown,
|
|
311
|
+
onBlur,
|
|
312
|
+
value: state.inputValue,
|
|
313
|
+
defaultValue: state.defaultInputValue,
|
|
314
|
+
onFocus,
|
|
315
|
+
autoComplete: 'off',
|
|
316
|
+
validate: undefined,
|
|
317
|
+
[privateValidationStateProp]: state,
|
|
318
|
+
'aria-describedby':
|
|
319
|
+
[valueId, props['aria-describedby']].filter(Boolean).join(' ') || undefined,
|
|
320
|
+
},
|
|
321
|
+
inputRef,
|
|
322
|
+
subSlot(slot, 'textField'),
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
useFormReset(inputRef, state.defaultValue, state.setValue, subSlot(slot, 'formReset'));
|
|
326
|
+
|
|
327
|
+
// Press handlers for the ComboBox button
|
|
328
|
+
let onPress = (e: PressEvent) => {
|
|
329
|
+
if (e.pointerType === 'touch') {
|
|
330
|
+
// Focus the input field in case it isn't focused yet
|
|
331
|
+
inputRef.current?.focus();
|
|
332
|
+
state.toggle(null, 'manual');
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
let onPressStart = (e: PressEvent) => {
|
|
337
|
+
if (e.pointerType !== 'touch') {
|
|
338
|
+
inputRef.current?.focus();
|
|
339
|
+
state.toggle(
|
|
340
|
+
e.pointerType === 'keyboard' || e.pointerType === 'virtual' ? 'first' : null,
|
|
341
|
+
'manual',
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
let triggerLabelProps = useLabels(
|
|
347
|
+
{
|
|
348
|
+
id: menuTriggerProps.id,
|
|
349
|
+
'aria-label': stringFormatter.format('buttonLabel'),
|
|
350
|
+
'aria-labelledby': props['aria-labelledby'] || labelProps.id,
|
|
351
|
+
},
|
|
352
|
+
undefined,
|
|
353
|
+
subSlot(slot, 'triggerLabels'),
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
let listBoxProps = useLabels(
|
|
357
|
+
{
|
|
358
|
+
id: menuProps.id,
|
|
359
|
+
'aria-label': stringFormatter.format('listboxLabel'),
|
|
360
|
+
'aria-labelledby': props['aria-labelledby'] || labelProps.id,
|
|
361
|
+
},
|
|
362
|
+
undefined,
|
|
363
|
+
subSlot(slot, 'listBoxLabels'),
|
|
364
|
+
);
|
|
365
|
+
|
|
366
|
+
// If a touch happens on direct center of ComboBox input, might be virtual click from iPad so open ComboBox menu
|
|
367
|
+
let lastEventTime = useRef(0, subSlot(slot, 'lastEventTime'));
|
|
368
|
+
let onTouchEnd = (e: any) => {
|
|
369
|
+
if (isDisabled || isReadOnly) {
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Sometimes VoiceOver on iOS fires two touchend events in quick succession. Ignore the second one.
|
|
374
|
+
if (e.timeStamp - lastEventTime.current < 500) {
|
|
375
|
+
e.preventDefault();
|
|
376
|
+
inputRef.current?.focus();
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
let rect = (getEventTarget(e) as Element).getBoundingClientRect();
|
|
381
|
+
let touch = e.changedTouches[0];
|
|
382
|
+
|
|
383
|
+
let centerX = Math.ceil(rect.left + 0.5 * rect.width);
|
|
384
|
+
let centerY = Math.ceil(rect.top + 0.5 * rect.height);
|
|
385
|
+
|
|
386
|
+
if (touch.clientX === centerX && touch.clientY === centerY) {
|
|
387
|
+
e.preventDefault();
|
|
388
|
+
inputRef.current?.focus();
|
|
389
|
+
state.toggle(null, 'manual');
|
|
390
|
+
|
|
391
|
+
lastEventTime.current = e.timeStamp;
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
// VoiceOver has issues with announcing aria-activedescendant properly on change
|
|
396
|
+
// (especially on iOS). We use a live region announcer to announce focus changes
|
|
397
|
+
// manually. In addition, section titles are announced when navigating into a new section.
|
|
398
|
+
let focusedItem =
|
|
399
|
+
state.selectionManager.focusedKey != null && state.isOpen
|
|
400
|
+
? state.collection.getItem(state.selectionManager.focusedKey)
|
|
401
|
+
: undefined;
|
|
402
|
+
let sectionKey = focusedItem?.parentKey ?? null;
|
|
403
|
+
let itemKey = state.selectionManager.focusedKey ?? null;
|
|
404
|
+
let lastSection = useRef(sectionKey, subSlot(slot, 'lastSection'));
|
|
405
|
+
let lastItem = useRef(itemKey, subSlot(slot, 'lastItem'));
|
|
406
|
+
// intentional omit dependency array, want this to happen on every render
|
|
407
|
+
useEffect(
|
|
408
|
+
() => {
|
|
409
|
+
if (
|
|
410
|
+
isAppleDevice() &&
|
|
411
|
+
focusedItem != null &&
|
|
412
|
+
itemKey != null &&
|
|
413
|
+
itemKey !== lastItem.current
|
|
414
|
+
) {
|
|
415
|
+
let isSelected = state.selectionManager.isSelected(itemKey);
|
|
416
|
+
let section = sectionKey != null ? state.collection.getItem(sectionKey) : null;
|
|
417
|
+
let sectionTitle =
|
|
418
|
+
section?.['aria-label'] ||
|
|
419
|
+
(typeof section?.rendered === 'string' ? section.rendered : '') ||
|
|
420
|
+
'';
|
|
421
|
+
|
|
422
|
+
let announcement = stringFormatter.format('focusAnnouncement', {
|
|
423
|
+
isGroupChange: (section && sectionKey !== lastSection.current) ?? false,
|
|
424
|
+
groupTitle: sectionTitle,
|
|
425
|
+
groupCount: section ? [...getChildNodes(section, state.collection)].length : 0,
|
|
426
|
+
optionText: focusedItem['aria-label'] || focusedItem.textValue || '',
|
|
427
|
+
isSelected,
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
announce(announcement);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
lastSection.current = sectionKey;
|
|
434
|
+
lastItem.current = itemKey;
|
|
435
|
+
},
|
|
436
|
+
null,
|
|
437
|
+
subSlot(slot, 'announceFocus'),
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
// Announce the number of available suggestions when it changes
|
|
441
|
+
let optionCount = getItemCount(state.collection);
|
|
442
|
+
let lastSize = useRef(optionCount, subSlot(slot, 'lastSize'));
|
|
443
|
+
let lastOpen = useRef(state.isOpen, subSlot(slot, 'lastOpen'));
|
|
444
|
+
// intentional omit dependency array, want this to happen on every render
|
|
445
|
+
useEffect(
|
|
446
|
+
() => {
|
|
447
|
+
// Only announce the number of options available when the menu opens if there is no
|
|
448
|
+
// focused item, otherwise screen readers will typically read e.g. "1 of 6".
|
|
449
|
+
// The exception is VoiceOver since this isn't included in the message above.
|
|
450
|
+
let didOpenWithoutFocusedItem =
|
|
451
|
+
state.isOpen !== lastOpen.current &&
|
|
452
|
+
(state.selectionManager.focusedKey == null || isAppleDevice());
|
|
453
|
+
|
|
454
|
+
if (state.isOpen && (didOpenWithoutFocusedItem || optionCount !== lastSize.current)) {
|
|
455
|
+
let announcement = stringFormatter.format('countAnnouncement', { optionCount });
|
|
456
|
+
announce(announcement);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
lastSize.current = optionCount;
|
|
460
|
+
lastOpen.current = state.isOpen;
|
|
461
|
+
},
|
|
462
|
+
null,
|
|
463
|
+
subSlot(slot, 'announceCount'),
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
// Announce when a selection occurs for VoiceOver. Other screen readers typically do this automatically.
|
|
467
|
+
// TODO: do we need to do this for multi-select?
|
|
468
|
+
let lastSelectedKey = useRef(state.selectedKey, subSlot(slot, 'lastSelectedKey'));
|
|
469
|
+
// intentional omit dependency array, want this to happen on every render
|
|
470
|
+
useEffect(
|
|
471
|
+
() => {
|
|
472
|
+
if (
|
|
473
|
+
isAppleDevice() &&
|
|
474
|
+
state.isFocused &&
|
|
475
|
+
state.selectedItem &&
|
|
476
|
+
state.selectedKey !== lastSelectedKey.current
|
|
477
|
+
) {
|
|
478
|
+
let optionText = state.selectedItem['aria-label'] || state.selectedItem.textValue || '';
|
|
479
|
+
let announcement = stringFormatter.format('selectedAnnouncement', { optionText });
|
|
480
|
+
announce(announcement);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
lastSelectedKey.current = state.selectedKey;
|
|
484
|
+
},
|
|
485
|
+
null,
|
|
486
|
+
subSlot(slot, 'announceSelected'),
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
useEffect(
|
|
490
|
+
() => {
|
|
491
|
+
if (state.isOpen) {
|
|
492
|
+
return ariaHideOutside(
|
|
493
|
+
[inputRef.current, popoverRef.current].filter((element) => element != null),
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
[state.isOpen, inputRef, popoverRef],
|
|
498
|
+
subSlot(slot, 'hideOutside'),
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
useUpdateEffect(
|
|
502
|
+
() => {
|
|
503
|
+
// Re-show focus ring when there is no virtually focused item.
|
|
504
|
+
if (
|
|
505
|
+
!focusedItem &&
|
|
506
|
+
inputRef.current &&
|
|
507
|
+
getActiveElement(getOwnerDocument(inputRef.current)) === inputRef.current
|
|
508
|
+
) {
|
|
509
|
+
dispatchVirtualFocus(inputRef.current, null);
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
[focusedItem],
|
|
513
|
+
subSlot(slot, 'virtualFocus'),
|
|
514
|
+
);
|
|
515
|
+
|
|
516
|
+
useEvent(
|
|
517
|
+
listBoxRef,
|
|
518
|
+
'react-aria-item-action',
|
|
519
|
+
state.isOpen
|
|
520
|
+
? () => {
|
|
521
|
+
state.close();
|
|
522
|
+
}
|
|
523
|
+
: undefined,
|
|
524
|
+
subSlot(slot, 'itemAction'),
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
return {
|
|
528
|
+
labelProps,
|
|
529
|
+
buttonProps: {
|
|
530
|
+
...menuTriggerProps,
|
|
531
|
+
...triggerLabelProps,
|
|
532
|
+
excludeFromTabOrder: true,
|
|
533
|
+
preventFocusOnPress: true,
|
|
534
|
+
onPress,
|
|
535
|
+
onPressStart,
|
|
536
|
+
isDisabled: isDisabled || isReadOnly,
|
|
537
|
+
},
|
|
538
|
+
inputProps: mergeProps(inputProps, {
|
|
539
|
+
role: 'combobox',
|
|
540
|
+
'aria-expanded': menuTriggerProps['aria-expanded'],
|
|
541
|
+
'aria-controls': state.isOpen ? menuProps.id : undefined,
|
|
542
|
+
// TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)
|
|
543
|
+
'aria-autocomplete': 'list',
|
|
544
|
+
'aria-activedescendant': focusedItem ? getItemId(state, focusedItem.key) : undefined,
|
|
545
|
+
onTouchEnd,
|
|
546
|
+
// This disable's iOS's autocorrect suggestions, since the combo box provides its own suggestions.
|
|
547
|
+
autoCorrect: 'off',
|
|
548
|
+
// This disable's the macOS Safari spell check auto corrections.
|
|
549
|
+
spellCheck: 'false',
|
|
550
|
+
}),
|
|
551
|
+
listBoxProps: mergeProps(menuProps, listBoxProps, {
|
|
552
|
+
onAction: undefined,
|
|
553
|
+
autoFocus: state.focusStrategy || true,
|
|
554
|
+
shouldUseVirtualFocus: true,
|
|
555
|
+
shouldSelectOnPressUp: true,
|
|
556
|
+
shouldFocusOnHover: true,
|
|
557
|
+
linkBehavior: 'selection' as const,
|
|
558
|
+
['UNSTABLE_itemBehavior']: 'action',
|
|
559
|
+
}),
|
|
560
|
+
valueProps: {
|
|
561
|
+
id: valueId,
|
|
562
|
+
},
|
|
563
|
+
descriptionProps,
|
|
564
|
+
errorMessageProps,
|
|
565
|
+
isInvalid,
|
|
566
|
+
validationErrors,
|
|
567
|
+
validationDetails,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// This is a modified version of useSlotId that uses useEffect instead of useLayoutEffect.
|
|
572
|
+
// Triggering re-renders from useLayoutEffect breaks useComboBoxState's useEffect logic in React 18.
|
|
573
|
+
// These re-renders preempt async state updates in the useEffect, which ends up running multiple times
|
|
574
|
+
// prior to the state being updated. This results in onSelectionChange being called multiple times.
|
|
575
|
+
// TODO: refactor useComboBoxState to avoid this.
|
|
576
|
+
// octane adaptation: takes a threaded slot (the module is not octane-compiled).
|
|
577
|
+
function useValueId(
|
|
578
|
+
depArray: ReadonlyArray<any> = [],
|
|
579
|
+
slot?: symbol | undefined,
|
|
580
|
+
): string | undefined {
|
|
581
|
+
let id = useId(subSlot(slot, 'id'));
|
|
582
|
+
let [exists, setExists] = useState(true, subSlot(slot, 'exists'));
|
|
583
|
+
let [lastDeps, setLastDeps] = useState(depArray, subSlot(slot, 'lastDeps'));
|
|
584
|
+
|
|
585
|
+
// If the deps changed, set exists to true so we can test whether the element exists.
|
|
586
|
+
if (lastDeps.some((v, i) => !Object.is(v, depArray[i]))) {
|
|
587
|
+
setExists(true);
|
|
588
|
+
setLastDeps(depArray);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
useEffect(
|
|
592
|
+
() => {
|
|
593
|
+
if (exists && !document.getElementById(id)) {
|
|
594
|
+
setExists(false);
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
[id, exists, lastDeps],
|
|
598
|
+
subSlot(slot, 'existsEffect'),
|
|
599
|
+
);
|
|
600
|
+
|
|
601
|
+
return exists ? id : undefined;
|
|
602
|
+
}
|