1414 * limitations under the License.
1515 */
1616
17- import { useEffect , useMemo , useRef , useState } from 'react'
17+ import { MouseEvent , useEffect , useMemo , useRef , useState } from 'react'
1818
1919import { Checkbox } from '@Common/Checkbox'
2020import { DEFAULT_BASE_PAGE_SIZE } from '@Common/Constants'
@@ -29,7 +29,15 @@ import { ComponentSizeType } from '@Shared/constants'
2929import { BulkSelection } from '../BulkSelection'
3030import BulkSelectionActionWidget from './BulkSelectionActionWidget'
3131import { ACTION_GUTTER_SIZE , BULK_ACTION_GUTTER_LABEL , EVENT_TARGET , SHIMMER_DUMMY_ARRAY } from './constants'
32- import { BulkActionStateType , FiltersTypeEnum , PaginationEnum , RowType , SignalsType , TableContentProps } from './types'
32+ import {
33+ BulkActionStateType ,
34+ ExpandedRowPrefixType ,
35+ FiltersTypeEnum ,
36+ PaginationEnum ,
37+ RowType ,
38+ SignalsType ,
39+ TableContentProps ,
40+ } from './types'
3341import useTableWithKeyboardShortcuts from './useTableWithKeyboardShortcuts'
3442import { getStickyColumnConfig , scrollToShowActiveElementIfNeeded } from './utils'
3543
@@ -57,6 +65,7 @@ const TableContent = <
5765 getRows,
5866 totalRows,
5967 rowStartIconConfig,
68+ onRowClick,
6069} : TableContentProps < RowData , FilterVariant , AdditionalProps > ) => {
6170 const rowsContainerRef = useRef < HTMLDivElement > ( null )
6271 const parentRef = useRef < HTMLDivElement > ( null )
@@ -194,7 +203,9 @@ const TableContent = <
194203 handleSorting ( newSortBy )
195204 }
196205
197- const toggleExpandAll = ( ) => {
206+ const toggleExpandAll = ( e : MouseEvent < HTMLButtonElement > ) => {
207+ e . stopPropagation ( )
208+
198209 setExpandState (
199210 visibleRows . reduce ( ( acc , row ) => {
200211 if ( ( row as RowType < RowData > ) . expandableRows ) {
@@ -272,21 +283,29 @@ const TableContent = <
272283 return visibleRows . map ( ( row , visibleRowIndex ) => {
273284 const isRowActive = activeRowIndex === visibleRowIndex
274285 const isRowBulkSelected = ! ! bulkSelectionState [ row . id ] || isBulkSelectionApplied
275- const isExpandedRow = row . id . startsWith ( 'expanded-row' )
286+ const isExpandedRow = row . id . startsWith ( 'expanded-row-' satisfies ExpandedRowPrefixType )
287+
288+ const handleChangeActiveRowIndex = ( e : MouseEvent < HTMLDivElement > ) => {
289+ e . stopPropagation ( )
276290
277- const handleChangeActiveRowIndex = ( ) => {
278291 setActiveRowIndex ( visibleRowIndex )
292+
293+ onRowClick ?.( row )
279294 }
280295
281296 const handleToggleBulkSelectionForRow = ( ) => {
282297 handleToggleBulkSelectionOnRow ( row )
283298 }
284299
285- const toggleExpandRow = ( ) => {
286- setExpandState ( {
287- ...expandState ,
288- [ row . id ] : ! expandState [ row . id ] ,
289- } )
300+ const toggleExpandRow = ( e : MouseEvent < HTMLButtonElement > ) => {
301+ e . stopPropagation ( )
302+
303+ if ( ( row as RowType < RowData > ) . expandableRows ) {
304+ setExpandState ( {
305+ ...expandState ,
306+ [ row . id ] : ! expandState [ row . id ] ,
307+ } )
308+ }
290309 }
291310
292311 const hasBulkOrExpandAction =
@@ -306,7 +325,9 @@ const TableContent = <
306325 isRowBulkSelected ? 'generic-table__row--bulk-selected' : ''
307326 } ${ isExpandedRow ? 'generic-table__row--expanded-row' : '' } ${
308327 rowStartIconConfig && hasBulkOrExpandAction ? 'with-start-icon-and-bulk-or-expand-action' : ''
309- } ${ ! isExpandedRow && expandState [ row . id ] ? 'generic-table__row--is-expanded' : '' } `}
328+ } ${ ! isExpandedRow && expandState [ row . id ] ? 'generic-table__row--is-expanded' : '' } ${
329+ onRowClick ? 'pointer' : ''
330+ } `}
310331 style = { {
311332 gridTemplateColumns,
312333 } }
@@ -332,7 +353,7 @@ const TableContent = <
332353 rotateBy = { expandState [ row . id ] ? 90 : 0 }
333354 />
334355 }
335- ariaLabel = "Expand row"
356+ ariaLabel = "Expand/Collapse row"
336357 showAriaLabelInTippy = { false }
337358 variant = { ButtonVariantType . borderLess }
338359 size = { ComponentSizeType . xs }
@@ -345,7 +366,7 @@ const TableContent = <
345366 { /* empty div needed for alignment; therefore hide if rowStartIconConfig (only applies to parent rows) is present */ }
346367 { isAnyRowExpandable &&
347368 ( isExpandedRow || ( ! ( row as RowType < RowData > ) . expandableRows && ! rowStartIconConfig ) ) && (
348- < div />
369+ < div className = "dc__position-rel expanded-tree-line" />
349370 ) }
350371
351372 { visibleColumns . map ( ( { field, horizontallySticky : isStickyColumn , CellComponent } , index ) => {
@@ -388,6 +409,7 @@ const TableContent = <
388409 isRowActive = { isRowActive }
389410 isExpandedRow = { isExpandedRow }
390411 isRowInExpandState = { expandState [ row . id ] }
412+ expandRowCallback = { toggleExpandRow }
391413 { ...additionalProps }
392414 />
393415 ) : (
@@ -453,7 +475,7 @@ const TableContent = <
453475 rotateBy = { areAllRowsExpanded ? 90 : 0 }
454476 />
455477 }
456- ariaLabel = "Expand row "
478+ ariaLabel = "Expand/Collapse all rows "
457479 showAriaLabelInTippy = { false }
458480 variant = { ButtonVariantType . borderLess }
459481 size = { ComponentSizeType . xs }
0 commit comments