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
8 changes: 6 additions & 2 deletions packages/@react-spectrum/table/src/TableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ function TableView<T extends object>(props: SpectrumTableProps<T>, ref: DOMRef<H
);
}

if (item.props.allowsResizing) {
if (item.props.allowsResizing && !item.hasChildNodes) {
return <ResizableTableColumnHeader tableRef={domRef} column={item} />;
}

Expand Down Expand Up @@ -581,6 +581,11 @@ function TableColumnHeader(props) {
let {state, isEmpty} = useTableContext();
let {pressProps, isPressed} = usePress({isDisabled: isEmpty});
let columnProps = column.props as SpectrumColumnProps<unknown>;
useEffect(() => {
if (column.hasChildNodes && columnProps.allowsResizing) {
console.warn(`Column key: ${column.key}. Columns with child columns don't allow resizing.`);
}
}, [column.hasChildNodes, column.key, columnProps.allowsResizing]);

let {columnHeaderProps} = useTableColumnHeader({
node: column,
Expand All @@ -602,7 +607,6 @@ function TableColumnHeader(props) {
'spectrum-Table-headCell',
{
'is-active': isPressed,
'is-resizable': columnProps.allowsResizing,
'is-sortable': columnProps.allowsSorting,
'is-sorted-desc': state.sortDescriptor?.column === column.key && state.sortDescriptor?.direction === 'descending',
'is-sorted-asc': state.sortDescriptor?.column === column.key && state.sortDescriptor?.direction === 'ascending',
Expand Down
19 changes: 19 additions & 0 deletions packages/@react-spectrum/table/stories/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,25 @@ storiesOf('TableView', module)
</TableView>
)
)
.add(
'dynamic with nested columns with resizing',
() => (
<TableView aria-label="TableView with nested columns" selectionMode="multiple" width={700} height={300} overflowMode="wrap" onSelectionChange={s => onSelectionChange([...s])}>
<TableHeader columns={nestedColumns}>
{column =>
<Column allowsResizing childColumns={column.children}>{column.name}</Column>
}
</TableHeader>
<TableBody items={items}>
{item =>
(<Row key={item.foo}>
{key => <Cell>{item[key]}</Cell>}
</Row>)
}
</TableBody>
</TableView>
)
)
.add(
'focusable cells',
() => (
Expand Down
27 changes: 27 additions & 0 deletions packages/@react-spectrum/table/test/TableSizing.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,33 @@ describe('TableViewSizing', function () {
expect(tree.queryByRole('slider')).toBeNull();
});
});

it('should prevent columns with child columns from being resizable', function () {
let warn = jest.spyOn(global.console, 'warn').mockImplementation();
let tree = render(
<TableView aria-label="Table" selectionMode="multiple">
<TableHeader columns={nestedColumns}>
{column => <Column allowsResizing childColumns={column.children}>{column.name}</Column>}
</TableHeader>
<TableBody items={items}>
{item =>
(<Row key={item.foo}>
{key => <Cell>{item[key]}</Cell>}
</Row>)
}
</TableBody>
</TableView>
);

let headers = tree.getAllByRole('columnheader');
for (let colheader of headers) {
if (parseInt(colheader.getAttribute('aria-colspan'), 10) > 1) {
expect(within(colheader).queryByRole('button')).toBeFalsy();
}
}
expect(warn).toHaveBeenCalledTimes(3);
warn.mockRestore();
});
});

describe('updating columns', function () {
Expand Down