Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions semcore/data-table/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangel

- Render grouped header in some cases.
- Styles for cells in accordion in different variants.
- Laggy animation in accordions.

## [16.3.0] - 2025-09-12

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ test.describe('Accordion in table', () => {
await test.step('Verify accordion collapses cell click', async () => {
messages = [];
const row = locators.row(page, 3);
await row.locator('[data-ui-name="Row.Cell"][aria-colindex="1"]').first().click();
await row.getByRole('gridcell').first().click();
await locators.rowTableInTable(page, 2, 6).waitFor({ state: 'hidden' });
await page.waitForEvent('console', {
predicate: (msg) => msg.type() === 'log' && msg.text() === 'Accordion close for row #1',
Expand Down
13 changes: 6 additions & 7 deletions semcore/data-table/src/components/Body/Cell.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Collapse, Flex } from '@semcore/base-components';
import { Box, Flex } from '@semcore/base-components';
import { Component, Root, sstyled, createComponent } from '@semcore/core';
import { getFocusableIn } from '@semcore/core/lib/utils/focus-lock/getFocusableIn';
import { isFocusInside } from '@semcore/core/lib/utils/focus-lock/isFocusInside';
Expand Down Expand Up @@ -136,6 +136,7 @@ class CellRoot<Data extends DataTableData, UniqKeyType> extends Component<DataTa
animationExpand,
style,
shadowVertical,
calculatedHeight,
} = this.asProps;

const cell = row[column.name];
Expand All @@ -161,13 +162,11 @@ class CellRoot<Data extends DataTableData, UniqKeyType> extends Component<DataTa

return sstyled(styles)(
<SCellWrapper
// @ts-ignore
gridArea={gridArea}
tag={isAccordionRow ? Collapse : undefined}
visible={animationExpand}
duration={duration}
delay={delay}
defaultHeight='100%'
timingFunction='linear'
duration={`${duration}ms`}
delay={`${delay}ms`}
h={isAccordionRow ? (animationExpand ? `${calculatedHeight}px` : `0px`) : undefined}
style={style}
fixed={column.fixed}
shadowVertical={column.showShadowVertical ? shadowVertical : undefined}
Expand Down
1 change: 1 addition & 0 deletions semcore/data-table/src/components/Body/Cell.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type CellPropsInner<Data extends DataTableData, UniqKeyType> = {
lastLeftFixedIndex: number;
firstRightFixedIndex: number;
withoutBorder?: boolean;
calculatedHeight: number;
};

export type DataTableCellType = (<UniqKeyType, Tag extends Intergalactic.Tag = 'div'>(
Expand Down
48 changes: 47 additions & 1 deletion semcore/data-table/src/components/Body/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { isInteractiveElement } from '@semcore/core/lib/utils/isInteractiveEleme
import ChevronRightM from '@semcore/icon/ChevronRight/m';
import * as React from 'react';

import { INDEX_OFFSET } from './Body';
import { Cell } from './Cell';
import type { DataTableCellProps, DataTableCellType } from './Cell.types';
import { MergedColumnsCell, MergedRowsCell } from './MergedCells';
Expand All @@ -18,6 +17,7 @@ import type { DataTableData, DTValue } from '../DataTable/DataTable.types';

type State = {
expandedForAnimation: boolean;
calculatedHeight: number;
};

export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<DataTableRowProps<Data, UniqKeyType>, {}, State, [], RowPropsInner<Data, UniqKeyType>> {
Expand All @@ -35,6 +35,7 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<

state: State = {
expandedForAnimation: false,
calculatedHeight: 0,
};

constructor(props: DataTableRowProps<Data, UniqKeyType>) {
Expand All @@ -47,6 +48,16 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
this.asProps.componentRef?.(this);
}

componentDidUpdate(prevProps: DataTableRowProps<Data, UniqKeyType>, prevState: State) {
const { animationExpand } = this.asProps;

if (animationExpand && this.rowElementRef.current && prevState.calculatedHeight === 0) {
const height = this.calculateRowHeight(this.rowElementRef.current);

this.setState({ calculatedHeight: height });
}
}

componentWillUnmount() {
this.asProps.componentRef?.(null);
}
Expand Down Expand Up @@ -221,6 +232,7 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
flatRows: this.asProps.flatRows,
shadowVertical,
withoutBorder,
calculatedHeight: this.state.calculatedHeight,
};

if (renderCell) {
Expand Down Expand Up @@ -531,6 +543,40 @@ export class RowRoot<Data extends DataTableData, UniqKeyType> extends Component<
obj === null
);
}

private calculateRowHeight(rowElement: HTMLElement): number {
const accordionFull = rowElement.cloneNode(true);

if (!(accordionFull instanceof HTMLElement)) {
return 0;
}

const columnsWidth: number[] = [];

const columns = Array.from(rowElement.children);
columns.forEach((column) => {
columnsWidth.push(column.getBoundingClientRect().width);
});

accordionFull.style.display = 'grid';
accordionFull.style.position = 'absolute';
accordionFull.style.visibility = 'hidden';
accordionFull.style.gridTemplateColumns = columnsWidth.join('px ') + 'px';

Array.from(accordionFull.children).forEach((child) => {
if (child instanceof HTMLElement) {
child.style.height = '100%';
}
});

document.body.appendChild(accordionFull);

const height = accordionFull.getBoundingClientRect().height;

document.body.removeChild(accordionFull);

return height;
}
}

export const Row = createComponent(RowRoot, {
Expand Down
8 changes: 8 additions & 0 deletions semcore/data-table/src/components/Body/style.shadow.css
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ SRow[sideIndents='wide'] {
}
}

SRow[isAccordionRow] > SCellWrapper {
transition-property: height;
transition-delay: var(--delay);
transition-duration: var(--duration);
transition-timing-function: linear;
overflow: clip;
}

SCellWrapper[fixed][shadowVertical] {
&:after {
content: '';
Expand Down
Loading