Fix openKeys is not working when mode is switched, close #4876

This commit is contained in:
afc163 2017-02-15 16:24:56 +08:00
parent 9fede4a5cd
commit 4cbcc05b02
2 changed files with 18 additions and 1 deletions

View File

@ -98,4 +98,21 @@ describe('Menu', () => {
wrapper.update();
// just expect no error emit
});
it('should always follow openKeys when mode is switched', () => {
const wrapper = mount(
<Menu openKeys={['1']} mode="inline">
<SubMenu key="1" title="submenu1">
<Menu.Item key="submenu1">Option 1</Menu.Item>
<Menu.Item key="submenu2">Option 2</Menu.Item>
</SubMenu>
<Menu.Item key="2">menu2</Menu.Item>
</Menu>
);
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).not.toBe(true);
wrapper.setProps({ mode: 'vertical' });
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).not.toBe(true);
wrapper.setProps({ mode: 'inline' });
expect(wrapper.find('.ant-menu-sub').at(0).hasClass('ant-menu-hidden')).not.toBe(true);
});
});

View File

@ -88,7 +88,7 @@ export default class Menu extends React.Component<MenuProps, any> {
this.switchModeFromInline = true;
}
if ('openKeys' in nextProps) {
this.setOpenKeys(nextProps.openKeys);
this.setState({ openKeys: nextProps.openKeys });
}
}
handleClick = (e) => {