diff --git a/services/web/frontend/js/features/history/components/file-tree/history-file-tree-doc.tsx b/services/web/frontend/js/features/history/components/file-tree/history-file-tree-doc.tsx index a6fe5851d4..c8acfb9df7 100644 --- a/services/web/frontend/js/features/history/components/file-tree/history-file-tree-doc.tsx +++ b/services/web/frontend/js/features/history/components/file-tree/history-file-tree-doc.tsx @@ -14,14 +14,15 @@ export default function HistoryFileTreeDoc({ file, name, }: HistoryFileTreeDocProps) { - const { isSelected, onClick } = useFileTreeItemSelection(file) + const { isSelected, handleClick, handleKeyDown } = + useFileTreeItemSelection(file) return (
  • { + const handleEvent = useCallback(() => { if (file.pathname !== selection.selectedFile?.pathname) { setSelection({ ...selection, @@ -14,7 +14,20 @@ export function useFileTreeItemSelection(file: FileDiff) { } }, [file, selection, setSelection]) + const handleClick = useCallback(() => { + handleEvent() + }, [handleEvent]) + + const handleKeyDown = useCallback( + event => { + if (event.key === 'Enter' || event.key === ' ') { + handleEvent() + } + }, + [handleEvent] + ) + const isSelected = selection.selectedFile?.pathname === file.pathname - return { isSelected, onClick: handleClick } + return { isSelected, handleClick, handleKeyDown } }