11import React from 'react'
22
3- import type { SectionRow } from '../index .js'
3+ import type { ItemKey , SectionRow } from '../types .js'
44
55import { ChevronIcon } from '../../../../icons/Chevron/index.js'
66import { DragHandleIcon } from '../../../../icons/DragHandle/index.js'
@@ -41,21 +41,28 @@ interface DivTableRowProps {
4141 placement ?: string
4242 targetItem : null | SectionRow
4343 } ) => void
44- onFocusChange ?: ( focusedIndex : number ) => void
45- onRowClick : ( { event, row } : { event : React . MouseEvent < HTMLElement > ; row : SectionRow } ) => void
44+ onFocusChange : ( focusedIndex : number ) => void
4645 onRowDrag : ( params : { event : PointerEvent ; item : null | SectionRow } ) => void
47- onRowKeyPress ?: ( params : { event : React . KeyboardEvent ; row : SectionRow } ) => void
46+ onRowKeyPress : ( params : { event : React . KeyboardEvent ; row : SectionRow } ) => void
47+ onSelectionChange : ( params : {
48+ itemKey : `${string } -${number | string } `
49+ options : {
50+ ctrlKey : boolean
51+ metaKey : boolean
52+ shiftKey : boolean
53+ }
54+ } ) => void
4855 openItemIDs ?: Set < number | string >
4956 rowItem : SectionRow
5057 segmentWidth : number
51- selectedRowIDs : ( number | string ) [ ]
58+ selectedItemKeys : Set < ItemKey >
5259 startOffset : number
5360 targetItems : ( null | SectionRow ) [ ]
5461 targetParentID : null | number | string
55- toggleRow : ( docID : number | string ) => void
62+ toggleRowExpand : ( docID : number | string ) => void
5663}
5764
58- export const NestedSectionsTableRow : React . FC < DivTableRowProps > = ( {
65+ export const Row : React . FC < DivTableRowProps > = ( {
5966 absoluteRowIndex,
6067 columns,
6168 dropContextName,
@@ -73,17 +80,17 @@ export const NestedSectionsTableRow: React.FC<DivTableRowProps> = ({
7380 loadingRowIDs,
7481 onDroppableHover,
7582 onFocusChange,
76- onRowClick,
7783 onRowDrag,
7884 onRowKeyPress,
85+ onSelectionChange,
7986 openItemIDs,
8087 rowItem,
8188 segmentWidth,
82- selectedRowIDs ,
89+ selectedItemKeys ,
8390 startOffset,
8491 targetItems,
8592 targetParentID,
86- toggleRow,
93+ toggleRowExpand : toggleRow ,
8794} ) => {
8895 const isOdd = absoluteRowIndex % 2 === 1
8996 const isFocused = focusedRowIndex !== undefined && focusedRowIndex === absoluteRowIndex
@@ -99,9 +106,13 @@ export const NestedSectionsTableRow: React.FC<DivTableRowProps> = ({
99106 const { actionNames, dataAttributeName, handleClick } = useActionDelegation ( {
100107 actions : {
101108 selectRow : ( event ) => {
102- onRowClick ( {
103- event : event as React . MouseEvent < HTMLElement > ,
104- row : rowItem ,
109+ onSelectionChange ( {
110+ itemKey : rowItem . rowID ,
111+ options : {
112+ ctrlKey : event . ctrlKey || event . metaKey ,
113+ metaKey : event . ctrlKey || event . metaKey ,
114+ shiftKey : event . shiftKey ,
115+ } ,
105116 } )
106117 } ,
107118 toggleExpand : ( ) => {
@@ -129,26 +140,16 @@ export const NestedSectionsTableRow: React.FC<DivTableRowProps> = ({
129140 . join ( ' ' ) }
130141 onClick = { handleClick }
131142 onFocus = { ( e ) => {
132- // Update focus index when row receives focus via tab, only if it's a valid focusable row
133- // Only update if the row itself is being focused, not a child element (like the chevron button)
134- if (
135- focusedRowIndex !== absoluteRowIndex &&
136- onFocusChange &&
137- e . target === e . currentTarget
138- ) {
143+ if ( e . target === e . currentTarget && focusedRowIndex !== absoluteRowIndex ) {
139144 onFocusChange ( absoluteRowIndex )
140145 }
141146 } }
142- onKeyDown = {
143- onRowKeyPress
144- ? ( event ) => {
145- onRowKeyPress ( { event, row : rowItem } )
146- }
147- : undefined
148- }
147+ onKeyDown = { ( event ) => {
148+ if ( event . target === event . currentTarget ) {
149+ onRowKeyPress ( { event, row : rowItem } )
150+ }
151+ } }
149152 onMouseDown = { ( e ) => {
150- // Prevent focus on mouse click to avoid the flash of focused state
151- // Focus should only be triggered via keyboard navigation
152153 e . preventDefault ( )
153154 } }
154155 ref = { rowRef }
@@ -158,24 +159,26 @@ export const NestedSectionsTableRow: React.FC<DivTableRowProps> = ({
158159 < div className = { baseClass } >
159160 < div className = { `${ baseClass } __cell` } ref = { firstCellRef } >
160161 < div className = { `${ baseClass } __actions` } >
161- < DraggableWithClick
162- attributes = { {
163- tabIndex : - 1 ,
164- } }
165- className = { `${ baseClass } __drag-handler` }
166- disabled = {
167- hasSelectedAncestor ||
168- ( selectedRowIDs . length > 1 && ! selectedRowIDs . includes ( rowItem . rowID ) )
169- }
170- onDrag = { ( event ) => {
171- onRowDrag ( {
172- event,
173- item : rowItem ,
174- } )
175- } }
176- >
177- < DragHandleIcon />
178- </ DraggableWithClick >
162+ { ! hasSelectedAncestor ? (
163+ < DraggableWithClick
164+ attributes = { {
165+ tabIndex : - 1 ,
166+ } }
167+ className = { `${ baseClass } __drag-handler` }
168+ disabled = {
169+ hasSelectedAncestor ||
170+ ( selectedItemKeys . size > 1 && ! selectedItemKeys . has ( rowItem . rowID ) )
171+ }
172+ onDrag = { ( event ) => {
173+ onRowDrag ( {
174+ event,
175+ item : rowItem ,
176+ } )
177+ } }
178+ >
179+ < DragHandleIcon />
180+ </ DraggableWithClick >
181+ ) : null }
179182 </ div >
180183 </ div >
181184
0 commit comments