Skip to content

Commit 33c8258

Browse files
authored
feat: Table expanded icon pass internal status (#413)
* feat: Pass parent status for render icon * add test case
1 parent 6b7d526 commit 33c8258

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/Table.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,24 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
246246
if (expandedRowRender) {
247247
return 'row';
248248
}
249-
if (mergedData.some(record => mergedChildrenColumnName in record)) {
249+
/* eslint-disable no-underscore-dangle */
250+
/**
251+
* Fix https://github.com/ant-design/ant-design/issues/21154
252+
* This is a workaround to not to break current behavior.
253+
* We can remove follow code after final release.
254+
*
255+
* To other developer:
256+
* Do not use `__PARENT_RENDER_ICON__` in prod since we will remove this when refactor
257+
*/
258+
if (
259+
(props.expandable &&
260+
internalHooks === INTERNAL_HOOKS &&
261+
(props.expandable as any).__PARENT_RENDER_ICON__) ||
262+
mergedData.some(record => mergedChildrenColumnName in record)
263+
) {
250264
return 'nest';
251265
}
266+
/* eslint-enable */
252267
return false;
253268
}, [!!expandedRowRender, mergedData]);
254269

tests/Internal.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import { mount } from 'enzyme';
3+
import Table from '../src';
4+
import { INTERNAL_HOOKS } from '../src/Table';
5+
6+
// All follow test is only for internal usage which should be removed when refactor
7+
describe('Table.Internal', () => {
8+
it('internal should pass `__PARENT_RENDER_ICON__` for expandable', () => {
9+
const wrapper = mount(
10+
<Table
11+
internalHooks={INTERNAL_HOOKS}
12+
columns={[{ dataIndex: 'key' }]}
13+
data={[{ key: 233 }]}
14+
expandable={{
15+
__PARENT_RENDER_ICON__: true,
16+
expandIcon: () => <div className="expand-icon" />,
17+
}}
18+
/>,
19+
);
20+
21+
expect(wrapper.find('.expand-icon')).toHaveLength(1);
22+
});
23+
});

0 commit comments

Comments
 (0)