Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion components/table/__tests__/Table.filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ describe('Table.filter', () => {
jest.useRealTimers();
});

describe('should support value types', () => {
describe.only('should support value types', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.only

[['Light', 93], ['Bamboo', false]].forEach(([text, value]) => {
it(`${typeof value} type`, () => {
const onFilter = jest.fn();
Expand All @@ -383,13 +383,36 @@ 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();

expect(onFilter.mock.calls.length > 0).toBeTruthy();
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();
});
});
Expand Down
8 changes: 6 additions & 2 deletions components/table/filterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down