From 6c9d6f5b05953988cb4fb1556bf435805479e07e Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 4 Mar 2024 15:37:11 -0600 Subject: Improve dialogs a11y (#3094) * Improve a11y on ios * Format * Remove android * Fix android --- src/components/Dialog/index.tsx | 83 ++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 38 deletions(-) (limited to 'src/components/Dialog/index.tsx') diff --git a/src/components/Dialog/index.tsx b/src/components/Dialog/index.tsx index ef4f4741b..fa375b0f4 100644 --- a/src/components/Dialog/index.tsx +++ b/src/components/Dialog/index.tsx @@ -15,7 +15,7 @@ import {useTheme, atoms as a, flatten} from '#/alf' import {Portal} from '#/components/Portal' import {createInput} from '#/components/forms/TextField' import {logger} from '#/logger' -import {useDialogStateContext} from '#/state/dialogs' +import {useDialogStateControlContext} from '#/state/dialogs' import { DialogOuterProps, @@ -82,7 +82,7 @@ export function Outer({ const hasSnapPoints = !!sheetOptions.snapPoints const insets = useSafeAreaInsets() const closeCallback = React.useRef<() => void>() - const {openDialogs} = useDialogStateContext() + const {setDialogIsOpen} = useDialogStateControlContext() /* * Used to manage open/closed, but index is otherwise handled internally by `BottomSheet` @@ -96,11 +96,11 @@ export function Outer({ const open = React.useCallback( ({index} = {}) => { - openDialogs.current.add(control.id) + setDialogIsOpen(control.id, true) // can be set to any index of `snapPoints`, but `0` is the first i.e. "open" setOpenIndex(index || 0) }, - [setOpenIndex, openDialogs, control.id], + [setOpenIndex, setDialogIsOpen, control.id], ) const close = React.useCallback(cb => { @@ -133,12 +133,12 @@ export function Outer({ closeCallback.current = undefined } - openDialogs.current.delete(control.id) + setDialogIsOpen(control.id, false) onClose?.() setOpenIndex(-1) } }, - [onClose, setOpenIndex, openDialogs, control.id], + [onClose, setOpenIndex, setDialogIsOpen, control.id], ) const context = React.useMemo(() => ({close}), [close]) @@ -146,38 +146,45 @@ export function Outer({ return ( isOpen && ( - - - - {children} - - + + + + + {children} + + + ) ) -- cgit 1.4.1