Skip to content

Commit 181bee0

Browse files
committed
fix: should not show expand column if not config expandable
1 parent 5995c99 commit 181bee0

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/hooks/useColumns.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,12 @@ function useColumns<RecordType>(
221221

222222
return cloneColumns.map(col => (col === EXPAND_COLUMN ? expandColumn : col));
223223
}
224-
return baseColumns;
224+
225+
if (process.env.NODE_ENV !== 'production' && baseColumns.includes(EXPAND_COLUMN)) {
226+
warning(false, '`expandable` is not config but there exist `EXPAND_COLUMN` in `columns`.');
227+
}
228+
229+
return baseColumns.filter(col => col !== EXPAND_COLUMN);
225230
}, [expandable, baseColumns, getRowKey, expandedKeys, expandIcon, direction]);
226231

227232
// ========================= Transform ========================

tests/ExpandRow.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ describe('Table.Expand', () => {
201201
});
202202

203203
describe('config expand column index', () => {
204+
it('not show EXPAND_COLUMN if expandable is false', () => {
205+
resetWarned();
206+
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
207+
208+
const wrapper = mount(
209+
createTable({
210+
columns: [...sampleColumns, Table.EXPAND_COLUMN],
211+
}),
212+
);
213+
214+
expect(wrapper.exists('.rc-table-row-expand-icon-cell')).toBeFalsy();
215+
216+
expect(errorSpy).toHaveBeenCalledWith(
217+
'Warning: `expandable` is not config but there exist `EXPAND_COLUMN` in `columns`.',
218+
);
219+
errorSpy.mockRestore();
220+
});
221+
204222
it('renders expand icon to the specify column', () => {
205223
resetWarned();
206224
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});

0 commit comments

Comments
 (0)