Skip to content

Commit 3eca52f

Browse files
committed
fix(Nav): subNav should be selected if it has selected child, close #520
1 parent 57f7b2f commit 3eca52f

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/menu/view/sub-menu.jsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ export default class SubMenu extends Component {
8787
return openKeys.indexOf(_key) > -1;
8888
}
8989

90+
getChildSelected() {
91+
const { _key, root } = this.props;
92+
const { selectMode } = root.props;
93+
const { selectedKeys } = root.state;
94+
95+
const _keyPos = root.k2n[_key].pos;
96+
97+
return (
98+
!!selectMode &&
99+
selectedKeys.some(key => root.k2n[key].pos.indexOf(_keyPos) > -1)
100+
);
101+
}
102+
90103
handleMouseEnter(e) {
91104
this.handleOpen(true);
92105

@@ -150,6 +163,8 @@ export default class SubMenu extends Component {
150163
} = root.props;
151164
const triggerType = propsTriggerType || rootTriggerType;
152165
const open = this.getOpen();
166+
const isChildSelected = this.getChildSelected();
167+
153168
const others = obj.pickOthers(
154169
Object.keys(SubMenu.propTypes),
155170
this.props
@@ -169,6 +184,10 @@ export default class SubMenu extends Component {
169184
type: 'submenu',
170185
component: 'div',
171186
parentMode,
187+
className: cx({
188+
[`${prefix}opened`]: open,
189+
[`${prefix}child-selected`]: isChildSelected,
190+
}),
172191
};
173192
const arrorProps = {
174193
type:
@@ -194,9 +213,6 @@ export default class SubMenu extends Component {
194213
} else {
195214
itemProps.onClick = this.handleClick;
196215
}
197-
if (open) {
198-
itemProps.className = `${prefix}opened`;
199-
}
200216

201217
const newSubMenuContentClassName = cx({
202218
[`${prefix}menu-sub-menu`]: true,

src/nav/scss/mixin.scss

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@
128128
background-color: $openedBgColor;
129129
color: $openedColor;
130130
}
131+
&.#{$css-prefix}child-selected {
132+
background-color: $openedBgColor;
133+
color: $openedColor;
134+
}
131135

132136
&:before {
133137
background-color: $activeColor;

test/nav/index-spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,21 @@ describe('Nav', () => {
209209
assert(wrapper.find('li.next-nav-group-label').length === 1);
210210
});
211211

212+
it('should support showChildSelected', () => {
213+
wrapper = mount(
214+
<Nav showChildSelected selectedKeys="1">
215+
<SubNav label="Group label">
216+
<Item key="1">First</Item>
217+
<Item key="2">Second</Item>
218+
</SubNav>
219+
</Nav>
220+
);
221+
222+
const subNavItem = wrapper.find('li.next-nav-sub-nav-item').at(0);
223+
224+
assert(subNavItem.find('.next-nav-item').hasClass('next-child-selected'));
225+
});
226+
212227
it('should support iconOnly', done => {
213228
wrapper = mount(
214229
<Nav iconOnly style={{ width: '200px' }}>

0 commit comments

Comments
 (0)