@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,462 @@
|
|
|
1
|
+
// Ported from react-aria (source: .react-spectrum/packages/react-aria/src/overlays/useOverlayPosition.ts).
|
|
2
|
+
// octane adaptations: `DOMAttributes` is a local structural prop-bag alias (upstream's is typed
|
|
3
|
+
// over React's synthetic handlers); public-hook slot threading (splitSlot/subSlot) per the
|
|
4
|
+
// binding convention — the internal `useResize` helper also threads a slot; the explicit `deps`
|
|
5
|
+
// arrays are kept verbatim; string-indexed `overlay.style[key]` writes stay `any`.
|
|
6
|
+
import { calculatePosition, getRect, PositionResult } from './calculatePosition';
|
|
7
|
+
import type { RefObject } from '@react-types/shared';
|
|
8
|
+
import { getActiveElement, isFocusWithin } from '../utils/shadowdom/DOMFunctions';
|
|
9
|
+
import { useCallback, useEffect, useRef, useState } from 'octane';
|
|
10
|
+
import { useCloseOnScroll } from './useCloseOnScroll';
|
|
11
|
+
import { useLayoutEffect } from '../utils/useLayoutEffect';
|
|
12
|
+
import { useLocale } from '../i18n/I18nProvider';
|
|
13
|
+
import { useResizeObserver } from '../utils/useResizeObserver';
|
|
14
|
+
|
|
15
|
+
import { S, splitSlot, subSlot } from '../internal';
|
|
16
|
+
|
|
17
|
+
// octane adaptation: minimal structural DOMAttributes (upstream's drags React's synthetic
|
|
18
|
+
// handler types along).
|
|
19
|
+
type DOMAttributes = Record<string, any>;
|
|
20
|
+
|
|
21
|
+
export type Placement =
|
|
22
|
+
| 'bottom'
|
|
23
|
+
| 'bottom left'
|
|
24
|
+
| 'bottom right'
|
|
25
|
+
| 'bottom start'
|
|
26
|
+
| 'bottom end'
|
|
27
|
+
| 'top'
|
|
28
|
+
| 'top left'
|
|
29
|
+
| 'top right'
|
|
30
|
+
| 'top start'
|
|
31
|
+
| 'top end'
|
|
32
|
+
| 'left'
|
|
33
|
+
| 'left top'
|
|
34
|
+
| 'left bottom'
|
|
35
|
+
| 'start'
|
|
36
|
+
| 'start top'
|
|
37
|
+
| 'start bottom'
|
|
38
|
+
| 'right'
|
|
39
|
+
| 'right top'
|
|
40
|
+
| 'right bottom'
|
|
41
|
+
| 'end'
|
|
42
|
+
| 'end top'
|
|
43
|
+
| 'end bottom';
|
|
44
|
+
|
|
45
|
+
export type Axis = 'top' | 'bottom' | 'left' | 'right';
|
|
46
|
+
export type SizeAxis = 'width' | 'height';
|
|
47
|
+
export type PlacementAxis = Axis | 'center';
|
|
48
|
+
|
|
49
|
+
export interface PositionProps {
|
|
50
|
+
/**
|
|
51
|
+
* The placement of the element with respect to its anchor element.
|
|
52
|
+
*
|
|
53
|
+
* @default 'bottom'
|
|
54
|
+
*/
|
|
55
|
+
placement?: Placement;
|
|
56
|
+
/**
|
|
57
|
+
* The placement padding that should be applied between the element and its
|
|
58
|
+
* surrounding container.
|
|
59
|
+
*
|
|
60
|
+
* @default 12
|
|
61
|
+
*/
|
|
62
|
+
containerPadding?: number;
|
|
63
|
+
/**
|
|
64
|
+
* The additional offset applied along the main axis between the element and its
|
|
65
|
+
* anchor element.
|
|
66
|
+
*
|
|
67
|
+
* @default 0
|
|
68
|
+
*/
|
|
69
|
+
offset?: number;
|
|
70
|
+
/**
|
|
71
|
+
* The additional offset applied along the cross axis between the element and its
|
|
72
|
+
* anchor element.
|
|
73
|
+
*
|
|
74
|
+
* @default 0
|
|
75
|
+
*/
|
|
76
|
+
crossOffset?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Whether the element should flip its orientation (e.g. top to bottom or left to right) when
|
|
79
|
+
* there is insufficient room for it to render completely.
|
|
80
|
+
*
|
|
81
|
+
* @default true
|
|
82
|
+
*/
|
|
83
|
+
shouldFlip?: boolean;
|
|
84
|
+
// /**
|
|
85
|
+
// * The element that should be used as the bounding container when calculating container offset
|
|
86
|
+
// * or whether it should flip.
|
|
87
|
+
// */
|
|
88
|
+
// boundaryElement?: Element,
|
|
89
|
+
/** Whether the element is rendered. */
|
|
90
|
+
isOpen?: boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface AriaPositionProps extends PositionProps {
|
|
94
|
+
/**
|
|
95
|
+
* Cross size of the overlay arrow in pixels.
|
|
96
|
+
*
|
|
97
|
+
* @default 0
|
|
98
|
+
*/
|
|
99
|
+
arrowSize?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Element that that serves as the positioning boundary.
|
|
102
|
+
*
|
|
103
|
+
* @default document.body
|
|
104
|
+
*/
|
|
105
|
+
boundaryElement?: Element;
|
|
106
|
+
/**
|
|
107
|
+
* The ref for the element which the overlay positions itself with respect to.
|
|
108
|
+
*/
|
|
109
|
+
targetRef: RefObject<Element | null>;
|
|
110
|
+
/**
|
|
111
|
+
* The ref for the overlay element.
|
|
112
|
+
*/
|
|
113
|
+
overlayRef: RefObject<Element | null>;
|
|
114
|
+
/**
|
|
115
|
+
* The ref for the arrow element.
|
|
116
|
+
*/
|
|
117
|
+
arrowRef?: RefObject<Element | null>;
|
|
118
|
+
/**
|
|
119
|
+
* A ref for the scrollable region within the overlay.
|
|
120
|
+
*
|
|
121
|
+
* @default overlayRef
|
|
122
|
+
*/
|
|
123
|
+
scrollRef?: RefObject<Element | null>;
|
|
124
|
+
/**
|
|
125
|
+
* Whether the overlay should update its position automatically.
|
|
126
|
+
*
|
|
127
|
+
* @default true
|
|
128
|
+
*/
|
|
129
|
+
shouldUpdatePosition?: boolean;
|
|
130
|
+
/** Handler that is called when the overlay should close. */
|
|
131
|
+
onClose?: (() => void) | null;
|
|
132
|
+
/**
|
|
133
|
+
* The maxHeight specified for the overlay element.
|
|
134
|
+
* By default, it will take all space up to the current viewport height.
|
|
135
|
+
*/
|
|
136
|
+
maxHeight?: number;
|
|
137
|
+
/**
|
|
138
|
+
* The minimum distance the arrow's edge should be from the edge of the overlay element.
|
|
139
|
+
*
|
|
140
|
+
* @default 0
|
|
141
|
+
*/
|
|
142
|
+
arrowBoundaryOffset?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Overrides the target element's bounding rectangle. Useful for positioning relative to
|
|
145
|
+
* a specific point such as the mouse cursor (e.g. context menus) or text selection.
|
|
146
|
+
*
|
|
147
|
+
* @default target.getBoundingClientRect()
|
|
148
|
+
* @param target - The target element.
|
|
149
|
+
*/
|
|
150
|
+
getTargetRect?: (target: Element) => DOMRect | null | undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface PositionAria {
|
|
154
|
+
/** Props for the overlay container element. */
|
|
155
|
+
overlayProps: DOMAttributes;
|
|
156
|
+
/** Props for the overlay tip arrow if any. */
|
|
157
|
+
arrowProps: DOMAttributes;
|
|
158
|
+
/** Placement of the overlay with respect to the overlay trigger. */
|
|
159
|
+
placement: PlacementAxis | null;
|
|
160
|
+
/** The origin of the target in the overlay's coordinate system. Useful for animations. */
|
|
161
|
+
triggerAnchorPoint: { x: number; y: number } | null;
|
|
162
|
+
/** Updates the position of the overlay. */
|
|
163
|
+
updatePosition(): void;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface ScrollAnchor {
|
|
167
|
+
type: 'top' | 'bottom';
|
|
168
|
+
offset: number;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
let visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Handles positioning overlays like popovers and menus relative to a trigger
|
|
175
|
+
* element, and updating the position when the window resizes.
|
|
176
|
+
*/
|
|
177
|
+
export function useOverlayPosition(props: AriaPositionProps): PositionAria;
|
|
178
|
+
// Slot-threading form: sibling ported hooks pass their derived sub-slot as the trailing arg.
|
|
179
|
+
export function useOverlayPosition(
|
|
180
|
+
props: AriaPositionProps,
|
|
181
|
+
slot: symbol | undefined,
|
|
182
|
+
): PositionAria;
|
|
183
|
+
export function useOverlayPosition(...args: any[]): PositionAria {
|
|
184
|
+
const [user, slotArg] = splitSlot(args);
|
|
185
|
+
const slot = slotArg ?? S('useOverlayPosition');
|
|
186
|
+
const props = user[0] as AriaPositionProps;
|
|
187
|
+
|
|
188
|
+
let { direction } = useLocale(subSlot(slot, 'locale'));
|
|
189
|
+
let {
|
|
190
|
+
arrowSize,
|
|
191
|
+
targetRef,
|
|
192
|
+
overlayRef,
|
|
193
|
+
arrowRef,
|
|
194
|
+
scrollRef = overlayRef,
|
|
195
|
+
placement = 'bottom' as Placement,
|
|
196
|
+
containerPadding = 12,
|
|
197
|
+
shouldFlip = true,
|
|
198
|
+
boundaryElement = typeof document !== 'undefined' ? document.body : null,
|
|
199
|
+
offset = 0,
|
|
200
|
+
crossOffset = 0,
|
|
201
|
+
shouldUpdatePosition = true,
|
|
202
|
+
isOpen = true,
|
|
203
|
+
onClose,
|
|
204
|
+
maxHeight,
|
|
205
|
+
arrowBoundaryOffset = 0,
|
|
206
|
+
getTargetRect,
|
|
207
|
+
} = props;
|
|
208
|
+
let [position, setPosition] = useState<PositionResult | null>(null, subSlot(slot, 'position'));
|
|
209
|
+
|
|
210
|
+
let deps = [
|
|
211
|
+
shouldUpdatePosition,
|
|
212
|
+
placement,
|
|
213
|
+
overlayRef.current,
|
|
214
|
+
targetRef.current,
|
|
215
|
+
arrowRef?.current,
|
|
216
|
+
scrollRef.current,
|
|
217
|
+
containerPadding,
|
|
218
|
+
shouldFlip,
|
|
219
|
+
boundaryElement,
|
|
220
|
+
offset,
|
|
221
|
+
crossOffset,
|
|
222
|
+
isOpen,
|
|
223
|
+
direction,
|
|
224
|
+
maxHeight,
|
|
225
|
+
arrowBoundaryOffset,
|
|
226
|
+
arrowSize,
|
|
227
|
+
];
|
|
228
|
+
|
|
229
|
+
// Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might
|
|
230
|
+
// just be a non-realistic use case
|
|
231
|
+
// Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles
|
|
232
|
+
let lastScale = useRef(visualViewport?.scale, subSlot(slot, 'lastScale'));
|
|
233
|
+
useEffect(
|
|
234
|
+
() => {
|
|
235
|
+
if (isOpen) {
|
|
236
|
+
lastScale.current = visualViewport?.scale;
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
[isOpen],
|
|
240
|
+
subSlot(slot, 'scale'),
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
let updatePosition = useCallback(
|
|
244
|
+
() => {
|
|
245
|
+
if (
|
|
246
|
+
shouldUpdatePosition === false ||
|
|
247
|
+
!isOpen ||
|
|
248
|
+
!overlayRef.current ||
|
|
249
|
+
!targetRef.current ||
|
|
250
|
+
!boundaryElement
|
|
251
|
+
) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (visualViewport?.scale !== lastScale.current) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Determine a scroll anchor based on the focused element.
|
|
260
|
+
// This stores the offset of the anchor element from the scroll container
|
|
261
|
+
// so it can be restored after repositioning. This way if the overlay height
|
|
262
|
+
// changes, the focused element appears to stay in the same position.
|
|
263
|
+
let anchor: ScrollAnchor | null = null;
|
|
264
|
+
if (scrollRef.current && isFocusWithin(scrollRef.current)) {
|
|
265
|
+
let anchorRect = getActiveElement()?.getBoundingClientRect();
|
|
266
|
+
let scrollRect = scrollRef.current.getBoundingClientRect();
|
|
267
|
+
// Anchor from the top if the offset is in the top half of the scrollable element,
|
|
268
|
+
// otherwise anchor from the bottom.
|
|
269
|
+
anchor = {
|
|
270
|
+
type: 'top',
|
|
271
|
+
offset: (anchorRect?.top ?? 0) - scrollRect.top,
|
|
272
|
+
};
|
|
273
|
+
if (anchor.offset > scrollRect.height / 2) {
|
|
274
|
+
anchor.type = 'bottom';
|
|
275
|
+
anchor.offset = (anchorRect?.bottom ?? 0) - scrollRect.bottom;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Always reset the overlay's previous max height if not defined by the user so that we can compensate for
|
|
280
|
+
// RAC collections populating after a second render and properly set a correct max height + positioning when it populates.
|
|
281
|
+
let overlay = overlayRef.current as HTMLElement;
|
|
282
|
+
if (!maxHeight && overlayRef.current) {
|
|
283
|
+
overlay.style.top = '0px';
|
|
284
|
+
overlay.style.bottom = '';
|
|
285
|
+
overlay.style.maxHeight = (window.visualViewport?.height ?? window.innerHeight) + 'px';
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
let position = calculatePosition({
|
|
289
|
+
placement: translateRTL(placement, direction),
|
|
290
|
+
overlayNode: overlayRef.current,
|
|
291
|
+
targetNode: targetRef.current,
|
|
292
|
+
scrollNode: scrollRef.current || overlayRef.current,
|
|
293
|
+
padding: containerPadding,
|
|
294
|
+
shouldFlip,
|
|
295
|
+
boundaryElement,
|
|
296
|
+
offset,
|
|
297
|
+
crossOffset,
|
|
298
|
+
maxHeight,
|
|
299
|
+
arrowSize: arrowSize ?? (arrowRef?.current ? getRect(arrowRef.current, true).width : 0),
|
|
300
|
+
arrowBoundaryOffset,
|
|
301
|
+
targetRect: getTargetRect?.(targetRef.current) as any,
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
if (!position.position) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Modify overlay styles directly so positioning happens immediately without the need of a second render
|
|
309
|
+
// This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers
|
|
310
|
+
overlay.style.top = '';
|
|
311
|
+
overlay.style.bottom = '';
|
|
312
|
+
overlay.style.left = '';
|
|
313
|
+
overlay.style.right = '';
|
|
314
|
+
|
|
315
|
+
Object.keys(position.position).forEach(
|
|
316
|
+
(key) => ((overlay.style as any)[key] = (position.position as any)![key] + 'px'),
|
|
317
|
+
);
|
|
318
|
+
overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : '';
|
|
319
|
+
|
|
320
|
+
// Restore scroll position relative to anchor element.
|
|
321
|
+
let activeElement = getActiveElement();
|
|
322
|
+
if (anchor && activeElement && scrollRef.current) {
|
|
323
|
+
let anchorRect = activeElement.getBoundingClientRect();
|
|
324
|
+
let scrollRect = scrollRef.current.getBoundingClientRect();
|
|
325
|
+
let newOffset = (anchorRect as any)[anchor.type] - (scrollRect as any)[anchor.type];
|
|
326
|
+
scrollRef.current.scrollTop += newOffset - anchor.offset;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Trigger a set state for a second render anyway for arrow positioning
|
|
330
|
+
setPosition(position);
|
|
331
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
332
|
+
},
|
|
333
|
+
deps,
|
|
334
|
+
subSlot(slot, 'updatePosition'),
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
// Update position when anything changes
|
|
338
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
339
|
+
useLayoutEffect(updatePosition, deps, subSlot(slot, 'layout'));
|
|
340
|
+
|
|
341
|
+
// Update position on window resize
|
|
342
|
+
useResize(updatePosition, subSlot(slot, 'resize'));
|
|
343
|
+
|
|
344
|
+
// Update position when the overlay changes size (might need to flip).
|
|
345
|
+
useResizeObserver(
|
|
346
|
+
{
|
|
347
|
+
ref: overlayRef,
|
|
348
|
+
onResize: updatePosition,
|
|
349
|
+
},
|
|
350
|
+
subSlot(slot, 'overlayResize'),
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
// Update position when the target changes size (might need to flip).
|
|
354
|
+
useResizeObserver(
|
|
355
|
+
{
|
|
356
|
+
ref: targetRef,
|
|
357
|
+
onResize: updatePosition,
|
|
358
|
+
},
|
|
359
|
+
subSlot(slot, 'targetResize'),
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
// Reposition the overlay and do not close on scroll while the visual viewport is resizing.
|
|
363
|
+
// This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
|
|
364
|
+
let isResizing = useRef(false, subSlot(slot, 'isResizing'));
|
|
365
|
+
useLayoutEffect(
|
|
366
|
+
() => {
|
|
367
|
+
let timeout: ReturnType<typeof setTimeout>;
|
|
368
|
+
let onResize = () => {
|
|
369
|
+
isResizing.current = true;
|
|
370
|
+
clearTimeout(timeout);
|
|
371
|
+
|
|
372
|
+
timeout = setTimeout(() => {
|
|
373
|
+
isResizing.current = false;
|
|
374
|
+
}, 500);
|
|
375
|
+
|
|
376
|
+
updatePosition();
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)
|
|
380
|
+
// We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.
|
|
381
|
+
let onScroll = () => {
|
|
382
|
+
if (isResizing.current) {
|
|
383
|
+
onResize();
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
visualViewport?.addEventListener('resize', onResize);
|
|
388
|
+
visualViewport?.addEventListener('scroll', onScroll);
|
|
389
|
+
return () => {
|
|
390
|
+
visualViewport?.removeEventListener('resize', onResize);
|
|
391
|
+
visualViewport?.removeEventListener('scroll', onScroll);
|
|
392
|
+
};
|
|
393
|
+
},
|
|
394
|
+
[updatePosition],
|
|
395
|
+
subSlot(slot, 'viewport'),
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
let close = useCallback(
|
|
399
|
+
() => {
|
|
400
|
+
if (!isResizing.current) {
|
|
401
|
+
onClose?.();
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
[onClose, isResizing],
|
|
405
|
+
subSlot(slot, 'close'),
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
// When scrolling a parent scrollable region of the trigger (other than the body),
|
|
409
|
+
// we hide the popover. Otherwise, its position would be incorrect.
|
|
410
|
+
useCloseOnScroll(
|
|
411
|
+
{
|
|
412
|
+
triggerRef: targetRef,
|
|
413
|
+
isOpen,
|
|
414
|
+
onClose: onClose && close,
|
|
415
|
+
},
|
|
416
|
+
subSlot(slot, 'closeOnScroll'),
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
return {
|
|
420
|
+
overlayProps: {
|
|
421
|
+
style: {
|
|
422
|
+
position: position ? 'absolute' : 'fixed',
|
|
423
|
+
top: !position ? 0 : undefined,
|
|
424
|
+
left: !position ? 0 : undefined,
|
|
425
|
+
zIndex: 100000, // should match the z-index in ModalTrigger
|
|
426
|
+
...position?.position,
|
|
427
|
+
maxHeight: position?.maxHeight ?? '100vh',
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
placement: position?.placement ?? null,
|
|
431
|
+
triggerAnchorPoint: position?.triggerAnchorPoint ?? null,
|
|
432
|
+
arrowProps: {
|
|
433
|
+
'aria-hidden': 'true',
|
|
434
|
+
role: 'presentation',
|
|
435
|
+
style: {
|
|
436
|
+
left: position?.arrowOffsetLeft,
|
|
437
|
+
top: position?.arrowOffsetTop,
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
updatePosition,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function useResize(onResize: () => void, slot: symbol | undefined) {
|
|
445
|
+
useLayoutEffect(
|
|
446
|
+
() => {
|
|
447
|
+
window.addEventListener('resize', onResize, false);
|
|
448
|
+
return () => {
|
|
449
|
+
window.removeEventListener('resize', onResize, false);
|
|
450
|
+
};
|
|
451
|
+
},
|
|
452
|
+
[onResize],
|
|
453
|
+
subSlot(slot, 'resize'),
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function translateRTL(position: string, direction: string) {
|
|
458
|
+
if (direction === 'rtl') {
|
|
459
|
+
return position.replace('start', 'right').replace('end', 'left') as Placement;
|
|
460
|
+
}
|
|
461
|
+
return position.replace('start', 'left').replace('end', 'right') as Placement;
|
|
462
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Ported from react-aria (source: .react-spectrum/packages/react-aria/src/overlays/useOverlayTrigger.ts).
|
|
2
|
+
// octane adaptations:
|
|
3
|
+
// - `OverlayTriggerState` type from the ported stately overlays state (upstream:
|
|
4
|
+
// 'react-stately/useOverlayTriggerState').
|
|
5
|
+
// - Upstream's dependency-less effect passes explicit `null` (octane's "run after every
|
|
6
|
+
// render").
|
|
7
|
+
// - Public-hook slot threading (splitSlot/subSlot) per the binding convention.
|
|
8
|
+
//
|
|
9
|
+
// NOTE: ported ahead of the rest of the overlays area (positioning/modal machinery is out
|
|
10
|
+
// of scope) because useMenuTrigger composes this aria/id wiring.
|
|
11
|
+
import type { AriaButtonProps } from '../button/useButton';
|
|
12
|
+
import type { DOMProps, RefObject } from '@react-types/shared';
|
|
13
|
+
import { onCloseMap } from './useCloseOnScroll';
|
|
14
|
+
import type { OverlayTriggerState } from '../stately/overlays/useOverlayTriggerState';
|
|
15
|
+
import { useEffect } from 'octane';
|
|
16
|
+
import { useId } from '../utils/useId';
|
|
17
|
+
|
|
18
|
+
import { S, splitSlot, subSlot } from '../internal';
|
|
19
|
+
|
|
20
|
+
export interface OverlayTriggerProps {
|
|
21
|
+
/** Type of overlay that is opened by the trigger. */
|
|
22
|
+
type: 'dialog' | 'menu' | 'listbox' | 'tree' | 'grid';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface OverlayTriggerAria {
|
|
26
|
+
/** Props for the trigger element. */
|
|
27
|
+
triggerProps: AriaButtonProps;
|
|
28
|
+
|
|
29
|
+
/** Props for the overlay container element. */
|
|
30
|
+
overlayProps: DOMProps;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Handles the behavior and accessibility for an overlay trigger, e.g. a button
|
|
35
|
+
* that opens a popover, menu, or other overlay that is positioned relative to the trigger.
|
|
36
|
+
*/
|
|
37
|
+
export function useOverlayTrigger(
|
|
38
|
+
props: OverlayTriggerProps,
|
|
39
|
+
state: OverlayTriggerState,
|
|
40
|
+
ref?: RefObject<Element | null>,
|
|
41
|
+
): OverlayTriggerAria;
|
|
42
|
+
// Slot-threading form: sibling ported hooks pass their derived sub-slot as the trailing arg.
|
|
43
|
+
export function useOverlayTrigger(
|
|
44
|
+
props: OverlayTriggerProps,
|
|
45
|
+
state: OverlayTriggerState,
|
|
46
|
+
ref: RefObject<Element | null> | undefined,
|
|
47
|
+
slot: symbol | undefined,
|
|
48
|
+
): OverlayTriggerAria;
|
|
49
|
+
export function useOverlayTrigger(...args: any[]): OverlayTriggerAria {
|
|
50
|
+
const [user, slotArg] = splitSlot(args);
|
|
51
|
+
const slot = slotArg ?? S('useOverlayTrigger');
|
|
52
|
+
const props = user[0] as OverlayTriggerProps;
|
|
53
|
+
const state = user[1] as OverlayTriggerState;
|
|
54
|
+
const ref = user[2] as RefObject<Element | null> | undefined;
|
|
55
|
+
|
|
56
|
+
let { type } = props;
|
|
57
|
+
let { isOpen } = state;
|
|
58
|
+
|
|
59
|
+
// Backward compatibility. Share state close function with useOverlayPosition so it can close on scroll
|
|
60
|
+
// without forcing users to pass onClose.
|
|
61
|
+
useEffect(
|
|
62
|
+
() => {
|
|
63
|
+
if (ref && ref.current) {
|
|
64
|
+
onCloseMap.set(ref.current, state.close);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
null,
|
|
68
|
+
subSlot(slot, 'closeMap'),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Aria 1.1 supports multiple values for aria-haspopup other than just menus.
|
|
72
|
+
// https://www.w3.org/TR/wai-aria-1.1/#aria-haspopup
|
|
73
|
+
// However, we only add it for menus for now because screen readers often
|
|
74
|
+
// announce it as a menu even for other values.
|
|
75
|
+
let ariaHasPopup: undefined | boolean | 'listbox' = undefined;
|
|
76
|
+
if (type === 'menu') {
|
|
77
|
+
ariaHasPopup = true;
|
|
78
|
+
} else if (type === 'listbox') {
|
|
79
|
+
ariaHasPopup = 'listbox';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let overlayId = useId(subSlot(slot, 'overlayId'));
|
|
83
|
+
return {
|
|
84
|
+
triggerProps: {
|
|
85
|
+
'aria-haspopup': ariaHasPopup,
|
|
86
|
+
'aria-expanded': isOpen,
|
|
87
|
+
'aria-controls': isOpen ? overlayId : undefined,
|
|
88
|
+
onPress: state.toggle,
|
|
89
|
+
},
|
|
90
|
+
overlayProps: {
|
|
91
|
+
id: overlayId,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|