From 2f2d989eae0e8f89b0b21d65115e026cb3c1ec1d Mon Sep 17 00:00:00 2001 From: Roy Johnson Date: Wed, 18 Sep 2024 13:24:17 -0500 Subject: [PATCH] Focus on DisplayNote goes to the menu button --- .../highlights/components/DisplayNote.tsx | 13 +++++++-- .../__snapshots__/DisplayNote.spec.tsx.snap | 28 +++++++++++++++++-- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/app/content/highlights/components/DisplayNote.tsx b/src/app/content/highlights/components/DisplayNote.tsx index eb10c014dd..c27afc5e85 100644 --- a/src/app/content/highlights/components/DisplayNote.tsx +++ b/src/app/content/highlights/components/DisplayNote.tsx @@ -7,7 +7,7 @@ import Dropdown, { DropdownItem, DropdownList } from '../../../components/Dropdo import Times from '../../../components/Times'; import { textStyle } from '../../../components/Typography/base'; import { useDebouncedWindowSize, useFocusElement } from '../../../reactUtils'; -import theme from '../../../theme'; +import theme, { defaultFocusOutline } from '../../../theme'; import { mergeRefs } from '../../../utils'; import { highlightStyles } from '../../constants'; import { query } from '../../search/selectors'; @@ -92,13 +92,16 @@ const DisplayNote = React.forwardRef(( // eslint-disable-next-line react-hooks/exhaustive-deps }, [element, confirmationRef, confirmingDelete, textToggle, width, isTocOpen, searchQuery]); - useFocusElement(element, shouldFocusCard); + const buttonPseudoRef = { + current: element.current?.querySelector('button') ?? null + }; + + useFocusElement(buttonPseudoRef, shouldFocusCard); return (
button:focus { + ${defaultFocusOutline} + } } ${theme.breakpoints.touchDeviceQuery(css` diff --git a/src/app/content/highlights/components/__snapshots__/DisplayNote.spec.tsx.snap b/src/app/content/highlights/components/__snapshots__/DisplayNote.spec.tsx.snap index f9d9bfa86a..ae5d2319a7 100644 --- a/src/app/content/highlights/components/__snapshots__/DisplayNote.spec.tsx.snap +++ b/src/app/content/highlights/components/__snapshots__/DisplayNote.spec.tsx.snap @@ -103,6 +103,11 @@ exports[`DisplayNote matches snapshot 1`] = ` color: #5e6062; } +.c0 .c2 > button:focus { + outline: 0.2rem auto Highlight; + outline: 0.2rem auto -webkit-focus-ring-color; +} + @media screen and (max-width:75em) { .c0 { margin-left: 8rem; @@ -120,7 +125,6 @@ exports[`DisplayNote matches snapshot 1`] = ` className="c0" data-highlight-card={true} role="dialog" - tabIndex={-1} >
button:focus { + outline: 0.2rem auto Highlight; + outline: 0.2rem auto -webkit-focus-ring-color; +} + .c0 { width: 20rem; overflow: visible; @@ -309,6 +318,11 @@ exports[`DisplayNote matches snapshot when focused 1`] = ` color: #5e6062; } +.c0 .c2 > button:focus { + outline: 0.2rem auto Highlight; + outline: 0.2rem auto -webkit-focus-ring-color; +} + @media screen and (max-width:75em) { .c0 { margin-left: 8rem; @@ -326,7 +340,6 @@ exports[`DisplayNote matches snapshot when focused 1`] = ` className="c0" data-highlight-card={true} role="dialog" - tabIndex={-1} >
button:focus { + outline: 0.2rem auto Highlight; + outline: 0.2rem auto -webkit-focus-ring-color; +} + .c0 { width: 20rem; overflow: visible; @@ -565,6 +583,11 @@ exports[`DisplayNote matches snapshot when focused with opened dropdown 1`] = ` color: #5e6062; } +.c0 .c2 > button:focus { + outline: 0.2rem auto Highlight; + outline: 0.2rem auto -webkit-focus-ring-color; +} + @media screen and (max-width:75em) { .c0 { margin-left: 8rem; @@ -582,7 +605,6 @@ exports[`DisplayNote matches snapshot when focused with opened dropdown 1`] = ` className="c0" data-highlight-card={true} role="dialog" - tabIndex={-1} >