Browse Source
fix: Fix Table filter display issue when use non-string type (#15817)
* fix filter display logic
* update test case
pull/18967/head
zombieJ
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
30 additions and
3 deletions
-
components/table/__tests__/Table.filter.test.js
-
components/table/filterDropdown.tsx
|
|
@ -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(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
@ -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 ( |
|
|
|