diff --git a/app/components/DocumentListItem.tsx b/app/components/DocumentListItem.tsx index 86aa856c84..03083c2189 100644 --- a/app/components/DocumentListItem.tsx +++ b/app/components/DocumentListItem.tsx @@ -2,6 +2,7 @@ import { observer } from "mobx-react"; import * as React from "react"; import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; +import { useFocusEffect, useRovingTabIndex } from "react-roving-tabindex"; import styled, { css } from "styled-components"; import breakpoint from "styled-components-breakpoint"; import { s } from "@shared/styles"; @@ -48,6 +49,19 @@ function DocumentListItem( const user = useCurrentUser(); const [menuOpen, handleMenuOpen, handleMenuClose] = useBoolean(); + let itemRef: React.Ref = + React.useRef(null); + if (ref) { + itemRef = ref; + } + + const [tabIndex, focused, handleKeyDown, handleClick] = useRovingTabIndex( + itemRef, + false + ); + + useFocusEffect(focused, itemRef); + const { document, showParentDocuments, @@ -68,7 +82,7 @@ function DocumentListItem( return ( diff --git a/app/components/SearchListItem.tsx b/app/components/SearchListItem.tsx index 0c5b06b41f..ae42ec041a 100644 --- a/app/components/SearchListItem.tsx +++ b/app/components/SearchListItem.tsx @@ -1,6 +1,7 @@ import { observer } from "mobx-react"; import * as React from "react"; import { Link } from "react-router-dom"; +import { useFocusEffect, useRovingTabIndex } from "react-roving-tabindex"; import styled, { css } from "styled-components"; import breakpoint from "styled-components-breakpoint"; import { s, ellipsis } from "@shared/styles"; @@ -33,9 +34,22 @@ function DocumentListItem( ) { const { document, highlight, context, shareId, ...rest } = props; + let itemRef: React.Ref = + React.useRef(null); + if (ref) { + itemRef = ref; + } + + const [tabIndex, focused, handleKeyDown, handleClick] = useRovingTabIndex( + itemRef, + false + ); + + useFocusEffect(focused, itemRef); + return ( { + if (rest.onClick) { + rest.onClick(ev); + } + handleClick(); + }} >