fix: The 'indentSize' in the Table component couldn't be zero value (#25890)

* - Fixed the indentSize prop of Table.tsx to also accept 0 values

* - Undo Cascader component test snapshots

* - Added test case
- Used check with typeof === number instead of `undefined` and `null`

Co-authored-by: omri.g <omri.g@alibaba-inc.com>
This commit is contained in:
Omri Grossman 2020-07-30 05:16:44 +03:00 committed by GitHub
parent 36ec093962
commit 8800b56e47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 55 deletions

View File

@ -222,18 +222,13 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
}
if (onChange) {
onChange(
changeInfo.pagination!,
changeInfo.filters!,
changeInfo.sorter!,
{
onChange(changeInfo.pagination!, changeInfo.filters!, changeInfo.sorter!, {
currentDataSource: getFilterData(
getSortData(rawData, changeInfo.sorterStates!, childrenColumnName),
changeInfo.filterStates!,
),
action,
},
);
});
}
};
@ -409,7 +404,9 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
}
// Indent size
mergedExpandable.indentSize = mergedExpandable.indentSize || indentSize || 15;
if (typeof mergedExpandable.indentSize !== 'number') {
mergedExpandable.indentSize = typeof indentSize === 'number' ? indentSize : 15;
}
// ============================ Render ============================
const transformColumns = React.useCallback(

View File

@ -40,10 +40,7 @@ const data = [
describe('Table.expand', () => {
it('click to expand', () => {
const wrapper = mount(<Table columns={columns} dataSource={data} />);
wrapper
.find('.ant-table-row-expand-icon')
.last()
.simulate('click');
wrapper.find('.ant-table-row-expand-icon').last().simulate('click');
expect(wrapper.render()).toMatchSnapshot();
});
@ -59,10 +56,7 @@ describe('Table.expand', () => {
/>,
);
wrapper
.find('.ant-table-row-expand-icon')
.first()
.simulate('click');
wrapper.find('.ant-table-row-expand-icon').first().simulate('click');
expect(
wrapper
.find('.ant-table-row-expand-icon')
@ -70,10 +64,7 @@ describe('Table.expand', () => {
.hasClass('ant-table-row-expand-icon-expanded'),
).toBeTruthy();
wrapper
.find('.ant-table-row-expand-icon')
.first()
.simulate('click');
wrapper.find('.ant-table-row-expand-icon').first().simulate('click');
expect(
wrapper
.find('.ant-table-row-expand-icon')
@ -96,6 +87,16 @@ describe('Table.expand', () => {
expect(wrapper.find('.expand-icon')).toHaveLength(1);
});
it('row indent padding should be 0px when indentSize defined as 0', () => {
const wrapper = mount(<Table indentSize={0} columns={columns} dataSource={data} />);
const button = wrapper.find('.ant-table-row-expand-icon').at(0);
button.simulate('click');
expect(wrapper.find('.indent-level-1').at(0).prop('style')).toHaveProperty(
'paddingLeft',
'0px',
);
});
describe('expandIconColumnIndex', () => {
it('basic', () => {
const wrapper = mount(
@ -109,18 +110,8 @@ describe('Table.expand', () => {
/>,
);
expect(
wrapper
.find('td')
.at(0)
.text(),
).toEqual('bamboo');
expect(
wrapper
.find('td')
.at(1)
.find('.ant-table-row-expand-icon').length,
).toBeTruthy();
expect(wrapper.find('td').at(0).text()).toEqual('bamboo');
expect(wrapper.find('td').at(1).find('.ant-table-row-expand-icon').length).toBeTruthy();
});
it('work with selection', () => {
@ -136,24 +127,9 @@ describe('Table.expand', () => {
/>,
);
expect(
wrapper
.find('td')
.at(0)
.find('.ant-checkbox-input').length,
).toBeTruthy();
expect(
wrapper
.find('td')
.at(1)
.text(),
).toEqual('bamboo');
expect(
wrapper
.find('td')
.at(2)
.find('.ant-table-row-expand-icon').length,
).toBeTruthy();
expect(wrapper.find('td').at(0).find('.ant-checkbox-input').length).toBeTruthy();
expect(wrapper.find('td').at(1).text()).toEqual('bamboo');
expect(wrapper.find('td').at(2).find('.ant-table-row-expand-icon').length).toBeTruthy();
});
});
});