From 16131c30f8a2797ffac9b0f2056464ec3e58c685 Mon Sep 17 00:00:00 2001 From: Andrew Nguyen <52666982+Andrewnt219@users.noreply.github.com> Date: Wed, 17 Nov 2021 12:16:16 -0500 Subject: [PATCH] fix(devtools): improve devtools a11y (#2947) * fix(devtools): improve devtools container a11y default element changes to aside from footer because aside represents a portion of a document whose content is only indirectly related to the document's main content. aria-label is also added to replace the text "generic" in a11y tree. * fix(devtools): add aria to devtools toggle button aria-expanded indicates open/closed of the menu aria-haspopup indicates this is a menu button aria-controls to link to the menu, also added aria-label on the menu to label it. Read more: https://www.w3.org/TR/wai-aria-practices/examples/menu-button/menu-button-links.html * fix(devtools): menuitem are visible in a11y tree in closed devtools This is because the element is just hidden visually, but is still inside the DOM. The added conditional display only affects the inner container, which means the animation of opening/closing is reserved. --- src/devtools/devtools.tsx | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/devtools/devtools.tsx b/src/devtools/devtools.tsx index af098e5978..00a226de10 100644 --- a/src/devtools/devtools.tsx +++ b/src/devtools/devtools.tsx @@ -55,7 +55,7 @@ interface DevtoolsOptions { /** * Use this to render the devtools inside a different type of container element for a11y purposes. * Any string which corresponds to a valid intrinsic JSX element is allowed. - * Defaults to 'footer'. + * Defaults to 'aside'. */ containerElement?: string | any } @@ -91,7 +91,7 @@ export function ReactQueryDevtools({ closeButtonProps = {}, toggleButtonProps = {}, position = 'bottom-left', - containerElement: Container = 'footer', + containerElement: Container = 'aside', }: DevtoolsOptions): React.ReactElement | null { const rootRef = React.useRef(null) const panelRef = React.useRef(null) @@ -221,7 +221,11 @@ export function ReactQueryDevtools({ if (!isMounted()) return null return ( - + { setIsOpen(false) @@ -302,6 +309,9 @@ export function ReactQueryDevtools({ type="button" {...otherToggleButtonProps} aria-label="Open React Query Devtools" + aria-controls="ReactQueryDevtoolsPanel" + aria-haspopup="true" + aria-expanded="false" onClick={e => { setIsOpen(true) onToggleClick && onToggleClick(e) @@ -449,7 +459,13 @@ export const ReactQueryDevtoolsPanel = React.forwardRef< return ( - +