Fix Table multiple levels filter menu (#4548)

fix #4541
This commit is contained in:
Wei Zhu 2017-01-13 21:13:31 +08:00 committed by 偏右
parent 78fe0a686f
commit 65d1f721d3
2 changed files with 43 additions and 3 deletions

View File

@ -4,7 +4,7 @@ import { renderToJson } from 'enzyme-to-json';
import Table from '..';
describe('Table.filter', () => {
const filterFn = (value, record) => record.name === 'Lucy';
const filterFn = (value, record) => record.name.indexOf(value) !== -1;
const column = {
title: 'Name',
dataIndex: 'name',
@ -41,6 +41,10 @@ describe('Table.filter', () => {
);
}
function renderedNames(wrapper) {
return wrapper.find('TableRow').map(row => row.props().record.name);
}
it('renders filter correctly', () => {
const wrapper = render(createTable());
@ -116,7 +120,7 @@ describe('Table.filter', () => {
const wrapper = mount(createTable({
columns: [{
...column,
filteredValue: ['girl'],
filteredValue: ['Lucy'],
}],
}));
@ -154,4 +158,40 @@ describe('Table.filter', () => {
expect(handleChange).toBeCalledWith({}, { name: ['boy'] }, {});
});
it('three levels menu', () => {
const filters = [
{ text: 'Upper', value: 'Upper' },
{ text: 'Lower', value: 'Lower' },
{
text: 'Level2',
value: 'Level2',
children: [
{ text: 'Large', value: 'Large' },
{ text: 'Small', value: 'Small' },
{
text: 'Level3',
value: 'Level3',
children: [
{ text: 'Black', value: 'Black' },
{ text: 'White', value: 'White' },
{ text: 'Jack', value: 'Jack' },
],
},
],
},
];
const wrapper = mount(createTable({
columns: [{
...column,
filters,
}],
}));
const dropdownWrapper = mount(wrapper.find('Trigger').node.getComponent());
dropdownWrapper.find('.ant-dropdown-menu-submenu-title').at(0).simulate('mouseEnter');
dropdownWrapper.find('.ant-dropdown-menu-submenu-title').at(1).simulate('mouseEnter');
dropdownWrapper.find('MenuItem').last().simulate('click');
dropdownWrapper.find('.confirm').simulate('click');
expect(renderedNames(wrapper)).toEqual(['Jack']);
});
});

View File

@ -122,7 +122,7 @@ export default class FilterMenu extends React.Component<FilterMenuProps, any> {
const subMenuCls = containSelected ? `${this.props.dropdownPrefixCls}-submenu-contain-selected` : '';
return (
<SubMenu title={item.text} className={subMenuCls} key={item.value.toString()}>
{item.children.map(child => this.renderMenuItem(child))}
{this.renderMenus(item.children)}
</SubMenu>
);
}