fix: Fix Table filter display issue when use non-string type (#15817)

* fix filter display logic

* update test case
This commit is contained in:
zombieJ 2019-04-02 22:06:51 +08:00 committed by GitHub
parent 778c2b1dff
commit 87a9c421a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View File

@ -361,7 +361,7 @@ describe('Table.filter', () => {
jest.useRealTimers();
});
describe('should support value types', () => {
describe.only('should support value types', () => {
[['Light', 93], ['Bamboo', false]].forEach(([text, value]) => {
it(`${typeof value} type`, () => {
const onFilter = jest.fn();
@ -383,6 +383,10 @@ describe('Table.filter', () => {
.find('MenuItem')
.first()
.simulate('click');
// This test can be remove if refactor
expect(typeof wrapper.find('FilterMenu').state().selectedKeys[0]).toEqual('string');
dropdownWrapper.find('.confirm').simulate('click');
wrapper.update();
@ -390,6 +394,25 @@ describe('Table.filter', () => {
onFilter.mock.calls.forEach(([val]) => {
expect(val).toBe(value);
});
// This test can be remove if refactor
expect(typeof wrapper.find('FilterMenu').state().selectedKeys[0]).toEqual(typeof value);
// Another time of Filter show
// https://github.com/ant-design/ant-design/issues/15593
getDropdownWrapper(wrapper)
.find('MenuItem')
.first()
.simulate('click');
expect(
wrapper
.find('FilterMenu')
.find('Checkbox')
.at(0)
.props().checked,
).toEqual(true);
jest.useRealTimers();
});
});

View File

@ -153,10 +153,14 @@ class FilterMenu<T> extends React.Component<FilterMenuProps<T>, FilterMenuState<
const { column } = this.props;
const { selectedKeys } = this.state;
const multiple = 'filterMultiple' in column ? column.filterMultiple : true;
// We still need trade key as string since Menu render need string
const internalSelectedKeys = (selectedKeys || []).map(key => key.toString());
const input = multiple ? (
<Checkbox checked={selectedKeys && selectedKeys.indexOf(item.value.toString()) >= 0} />
<Checkbox checked={internalSelectedKeys.indexOf(item.value.toString()) >= 0} />
) : (
<Radio checked={selectedKeys && selectedKeys.indexOf(item.value.toString()) >= 0} />
<Radio checked={internalSelectedKeys.indexOf(item.value.toString()) >= 0} />
);
return (