@@ -35,6 +35,7 @@ import {
3535 FiltersTypeEnum ,
3636 PaginationEnum ,
3737 RowType ,
38+ SignalEnum ,
3839 SignalsType ,
3940 TableContentProps ,
4041} from './types'
@@ -152,9 +153,10 @@ const TableContent = <
152153 ? `${ initialGridTemplateColumns } ${ typeof rowOnHoverComponentWidth === 'number' ? `minmax(${ rowOnHoverComponentWidth } px, 1fr)` : rowOnHoverComponentWidth } `
153154 : initialGridTemplateColumns
154155
155- const gridTemplateColumns = isAnyRowExpandable
156- ? `${ ACTION_GUTTER_SIZE } px ${ gridTemplateColumnsWithoutExpandButton } `
157- : gridTemplateColumnsWithoutExpandButton
156+ const gridTemplateColumns =
157+ isAnyRowExpandable || rowStartIconConfig
158+ ? `${ ACTION_GUTTER_SIZE } px ${ gridTemplateColumnsWithoutExpandButton } `
159+ : gridTemplateColumnsWithoutExpandButton
158160
159161 useEffect ( ( ) => {
160162 const scrollEventHandler = ( ) => {
@@ -188,7 +190,7 @@ const TableContent = <
188190
189191 useEffectAfterMount ( ( ) => {
190192 setActiveRowIndex ( 0 )
191- } , [ offset , visibleRows ] )
193+ } , [ offset ] )
192194
193195 useEffect ( ( ) => {
194196 setIdentifiers ?.(
@@ -203,6 +205,54 @@ const TableContent = <
203205 handleSorting ( newSortBy )
204206 }
205207
208+ useEffect ( ( ) => {
209+ if ( ! isAnyRowExpandable ) {
210+ return ( ) => { }
211+ }
212+
213+ const getExpandCollapseRowHandler =
214+ ( state : boolean ) =>
215+ ( { detail : { activeRowData } } ) => {
216+ if ( ( activeRowData as RowType < RowData > ) . expandableRows ) {
217+ setExpandState ( ( prev ) => ( {
218+ ...prev ,
219+ [ activeRowData . id ] : state ,
220+ } ) )
221+ }
222+ }
223+
224+ const handleExpandRow = getExpandCollapseRowHandler ( true )
225+ const handleCollapseRow = getExpandCollapseRowHandler ( false )
226+
227+ const signals = EVENT_TARGET as SignalsType
228+
229+ signals . addEventListener ( SignalEnum . EXPAND_ROW , handleExpandRow )
230+ signals . addEventListener ( SignalEnum . COLLAPSE_ROW , handleCollapseRow )
231+
232+ return ( ) => {
233+ signals . removeEventListener ( SignalEnum . EXPAND_ROW , handleExpandRow )
234+ signals . removeEventListener ( SignalEnum . COLLAPSE_ROW , handleCollapseRow )
235+ }
236+ } , [ isAnyRowExpandable ] )
237+
238+ useEffect ( ( ) => {
239+ if ( ! onRowClick ) {
240+ return ( ) => { }
241+ }
242+
243+ const handleEnterPress = ( { detail : { activeRowData } } ) => {
244+ onRowClick ( activeRowData , activeRowData . id . startsWith ( 'expanded-row-' satisfies ExpandedRowPrefixType ) )
245+ }
246+
247+ const signals = EVENT_TARGET as SignalsType
248+
249+ signals . addEventListener ( SignalEnum . ENTER_PRESSED , handleEnterPress )
250+
251+ return ( ) => {
252+ signals . removeEventListener ( SignalEnum . ENTER_PRESSED , handleEnterPress )
253+ }
254+ } , [ onRowClick ] )
255+
206256 const toggleExpandAll = ( e : MouseEvent < HTMLButtonElement > ) => {
207257 e . stopPropagation ( )
208258
@@ -247,22 +297,24 @@ const TableContent = <
247297 return Object . values ( bulkSelectionState )
248298 }
249299
300+ const showIconOrExpandActionGutter = isBulkSelectionConfigured || ! ! rowStartIconConfig || isAnyRowExpandable
301+
250302 const renderRows = ( ) => {
251- if ( loading ) {
303+ if ( loading && ! visibleColumns . length ) {
252304 return SHIMMER_DUMMY_ARRAY . map ( ( shimmerRowLabel ) => (
253305 < div
254306 key = { shimmerRowLabel }
255- className = { `px-20 flexbox py-12 dc__gap-16 ${ showSeparatorBetweenRows ? 'border__secondary--bottom' : '' } ` }
307+ className = { `px-20 flex left py-12 dc__gap-16 ${ showSeparatorBetweenRows ? 'border__secondary--bottom' : '' } ` }
256308 >
257- { isBulkSelectionConfigured ? < div className = "shimmer w-20" /> : null }
309+ { showIconOrExpandActionGutter ? < div className = "shimmer w-20" /> : null }
258310 { SHIMMER_DUMMY_ARRAY . map ( ( shimmerCellLabel ) => (
259311 < div key = { shimmerCellLabel } className = "shimmer w-200" />
260312 ) ) }
261313 </ div >
262314 ) )
263315 }
264316
265- if ( areFilteredRowsLoading ) {
317+ if ( areFilteredRowsLoading || ( loading && visibleColumns . length ) ) {
266318 return SHIMMER_DUMMY_ARRAY . map ( ( shimmerRowLabel ) => (
267319 < div
268320 key = { shimmerRowLabel }
@@ -271,6 +323,11 @@ const TableContent = <
271323 gridTemplateColumns,
272324 } }
273325 >
326+ { showIconOrExpandActionGutter ? (
327+ < div className = "py-12 flex" aria-label = "Loading..." >
328+ < div className = "shimmer h-16 w-20" />
329+ </ div >
330+ ) : null }
274331 { visibleColumns . map ( ( { label } ) => (
275332 < div key = { label } className = "py-12 flex" aria-label = "Loading..." >
276333 < div className = "shimmer h-16 w-100" />
@@ -364,7 +421,7 @@ const TableContent = <
364421 ariaLabel = "Expand/Collapse row"
365422 showAriaLabelInTippy = { false }
366423 variant = { ButtonVariantType . borderLess }
367- size = { ComponentSizeType . xs }
424+ size = { ComponentSizeType . xxs }
368425 style = { ButtonStyleType . neutral }
369426 onClick = { toggleExpandRow }
370427 />
@@ -467,9 +524,9 @@ const TableContent = <
467524 ref = { headerRef }
468525 className = "bg__primary dc__min-width-fit-content px-20 border__secondary--bottom dc__position-sticky dc__zi-2 dc__top-0 generic-table__header"
469526 >
470- { loading ? (
527+ { loading && ! visibleColumns . length ? (
471528 < div className = "flexbox py-12 dc__gap-16" >
472- { isBulkSelectionConfigured ? < div className = "shimmer w-20" /> : null }
529+ { showIconOrExpandActionGutter ? < div className = "shimmer w-20" /> : null }
473530 { SHIMMER_DUMMY_ARRAY . map ( ( label ) => (
474531 < div key = { label } className = "shimmer w-200" />
475532 ) ) }
@@ -498,13 +555,15 @@ const TableContent = <
498555 ariaLabel = "Expand/Collapse all rows"
499556 showAriaLabelInTippy = { false }
500557 variant = { ButtonVariantType . borderLess }
501- size = { ComponentSizeType . xs }
558+ size = { ComponentSizeType . xxs }
502559 style = { ButtonStyleType . neutral }
503560 onClick = { toggleExpandAll }
504561 />
505562 </ div >
506563 ) : null }
507564
565+ { ! isAnyRowExpandable && rowStartIconConfig && < div /> }
566+
508567 { visibleColumns . map (
509568 (
510569 {
0 commit comments