From 77c758714db424d17f111789da693c2dd6831608 Mon Sep 17 00:00:00 2001 From: Laurent Nguyen Date: Wed, 31 Jul 2024 16:52:23 +0200 Subject: [PATCH] Fix initial condition for shift/ctrl selection to work (#1908) --- src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx | 7 +++++-- .../Tabs/DocumentsTabV2/DocumentsTableComponent.tsx | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx index b243968b6..ab79a8a93 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx +++ b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx @@ -92,6 +92,9 @@ export class DocumentsTabV2 extends TabsBase { // Use this value to initialize the very time the component is rendered const RESET_INDEX = -1; +// Auto-select first row. Define as constant to show where first row is selected +export const INITIAL_SELECTED_ROW_INDEX = 0; + const filterButtonStyle: CSSProperties = { marginLeft: 8, }; @@ -506,8 +509,8 @@ export const DocumentsTabComponent: React.FunctionComponent documentIds.length - 1 ) { // reset clicked row or the current clicked row is out of bounds - currentClickedRowIndex = 0; - setSelectedRows(new Set([0])); + currentClickedRowIndex = INITIAL_SELECTED_ROW_INDEX; + setSelectedRows(new Set([INITIAL_SELECTED_ROW_INDEX])); onDocumentClicked(currentClickedRowIndex, documentIds); } } diff --git a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.tsx b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.tsx index a04844964..9b135fc8d 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.tsx +++ b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTableComponent.tsx @@ -23,6 +23,7 @@ import { useTableSelection, } from "@fluentui/react-components"; import { NormalizedEventKey } from "Common/Constants"; +import { INITIAL_SELECTED_ROW_INDEX } from "Explorer/Tabs/DocumentsTabV2/DocumentsTabV2"; import { selectionHelper } from "Explorer/Tabs/DocumentsTabV2/SelectionHelper"; import { isEnvironmentCtrlPressed, isEnvironmentShiftPressed } from "Utils/KeyboardUtils"; import React, { useCallback, useMemo } from "react"; @@ -123,7 +124,7 @@ export const DocumentsTableComponent: React.FC = [columnHeaders], ); - const [selectionStartIndex, setSelectionStartIndex] = React.useState(undefined); + const [selectionStartIndex, setSelectionStartIndex] = React.useState(INITIAL_SELECTED_ROW_INDEX); const onTableCellClicked = useCallback( (e: React.MouseEvent, index: number) => { if (isSelectionDisabled) {