import React from 'react';
import Menu, { SubMenu, Item as MenuItem } from 'rc-menu';
import Dropdown from '../dropdown';
import Icon from '../icon';
import Checkbox from '../checkbox';
export default class FilterMenu extends React.Component {
static defaultProps = {
handleFilter() {},
column: null
}
constructor(props) {
super(props);
this.state = {
selectedKeys: this.props.selectedKeys,
keyPathOfSelectedItem: {}, // 记录所有有选中子菜单的祖先菜单
visible: false,
};
}
componentWillReceiveProps(nextProps) {
this.setState({
selectedKeys: nextProps.selectedKeys
});
}
setSelectedKeys = ({ selectedKeys }) => {
this.setState({ selectedKeys });
}
handleClearFilters = () => {
this.setState({
selectedKeys: []
}, this.handleConfirm);
}
handleConfirm = () => {
this.setState({
visible: false
});
this.props.confirmFilter(this.props.column, this.state.selectedKeys);
}
onVisibleChange = (visible) => {
this.setState({
visible,
});
if (!visible) {
this.props.confirmFilter(this.props.column, this.state.selectedKeys);
}
}
renderMenuItem(item) {
return (
);
}
renderMenus(items) {
let menuItems = items.map(item => {
if (item.children && item.children.length > 0) {
const keyPathOfSelectedItem = this.state.keyPathOfSelectedItem;
const containSelected = Object.keys(keyPathOfSelectedItem).some(key => {
const keyPath = keyPathOfSelectedItem[key];
return keyPath.indexOf(item.value) >= 0;
});
const subMenuCls = containSelected ? 'ant-dropdown-submenu-contain-selected' : '';
return (