mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 13:09:40 +08:00
fix: Fix Table filter display issue when use non-string type (#15817)
* fix filter display logic * update test case
This commit is contained in:
parent
778c2b1dff
commit
87a9c421a2
@ -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 (
|
||||
|
Loading…
Reference in New Issue
Block a user