Skip to content

Commit

Permalink
fix(Nav): subNav should be selected if it has selected child, close #520
Browse files Browse the repository at this point in the history
  • Loading branch information
youluna committed Aug 7, 2019
1 parent 57f7b2f commit 3eca52f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/menu/view/sub-menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ export default class SubMenu extends Component {
return openKeys.indexOf(_key) > -1;
}

getChildSelected() {
const { _key, root } = this.props;
const { selectMode } = root.props;
const { selectedKeys } = root.state;

const _keyPos = root.k2n[_key].pos;

return (
!!selectMode &&
selectedKeys.some(key => root.k2n[key].pos.indexOf(_keyPos) > -1)
);
}

handleMouseEnter(e) {
this.handleOpen(true);

Expand Down Expand Up @@ -150,6 +163,8 @@ export default class SubMenu extends Component {
} = root.props;
const triggerType = propsTriggerType || rootTriggerType;
const open = this.getOpen();
const isChildSelected = this.getChildSelected();

const others = obj.pickOthers(
Object.keys(SubMenu.propTypes),
this.props
Expand All @@ -169,6 +184,10 @@ export default class SubMenu extends Component {
type: 'submenu',
component: 'div',
parentMode,
className: cx({
[`${prefix}opened`]: open,
[`${prefix}child-selected`]: isChildSelected,
}),
};
const arrorProps = {
type:
Expand All @@ -194,9 +213,6 @@ export default class SubMenu extends Component {
} else {
itemProps.onClick = this.handleClick;
}
if (open) {
itemProps.className = `${prefix}opened`;
}

const newSubMenuContentClassName = cx({
[`${prefix}menu-sub-menu`]: true,
Expand Down
4 changes: 4 additions & 0 deletions src/nav/scss/mixin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@
background-color: $openedBgColor;
color: $openedColor;
}
&.#{$css-prefix}child-selected {
background-color: $openedBgColor;
color: $openedColor;
}

&:before {
background-color: $activeColor;
Expand Down
15 changes: 15 additions & 0 deletions test/nav/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,21 @@ describe('Nav', () => {
assert(wrapper.find('li.next-nav-group-label').length === 1);
});

it('should support showChildSelected', () => {
wrapper = mount(
<Nav showChildSelected selectedKeys="1">
<SubNav label="Group label">
<Item key="1">First</Item>
<Item key="2">Second</Item>
</SubNav>
</Nav>
);

const subNavItem = wrapper.find('li.next-nav-sub-nav-item').at(0);

assert(subNavItem.find('.next-nav-item').hasClass('next-child-selected'));
});

it('should support iconOnly', done => {
wrapper = mount(
<Nav iconOnly style={{ width: '200px' }}>
Expand Down

0 comments on commit 3eca52f

Please sign in to comment.