Skip to content

Commit b4a03d7

Browse files
committed
fix(Nav): correct inline level when iconOnly switched, close #1676
1 parent 0176594 commit b4a03d7

File tree

2 files changed

+45
-23
lines changed

2 files changed

+45
-23
lines changed

src/menu/view/menu.jsx

+5-16
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const addIndicators = ({ children, lastVisibleIndex, prefix, renderMore }) => {
8282
return arr;
8383
};
8484

85-
const getNewChildren = ({ children, root, lastVisibleIndex, hozInLine, prefix, renderMore }) => {
85+
const getNewChildren = ({ children, root, mode, lastVisibleIndex, hozInLine, prefix, renderMore }) => {
8686
const k2n = {};
8787
const p2n = {};
8888

@@ -144,7 +144,7 @@ const getNewChildren = ({ children, root, lastVisibleIndex, hozInLine, prefix, r
144144
// parent know children's inlineLevel
145145
// if parent's mode is popup, then children's inlineLevel must be 1;
146146
// else inlineLevel should add 1
147-
const childLevel = (child.props.mode || props.root.props.mode) === 'popup' ? 1 : inlineLevel + 1;
147+
const childLevel = (child.props.mode || mode) === 'popup' ? 1 : inlineLevel + 1;
148148

149149
switch (child.type.menuChildType) {
150150
case 'submenu':
@@ -400,10 +400,7 @@ class Menu extends Component {
400400

401401
const { newChildren, _k2n, _p2n } = getNewChildren({
402402
root: this,
403-
hozInLine,
404-
prefix,
405-
children,
406-
renderMore,
403+
...this.props,
407404
});
408405

409406
const tabbableKey = focusable ? getFirstAvaliablelChildKey('0', _p2n) : undefined;
@@ -445,14 +442,10 @@ class Menu extends Component {
445442
state.focusedKey = nextProps.focusedKey;
446443
}
447444

448-
const { hozInLine, children, prefix, renderMore } = nextProps;
449445
const { newChildren, _k2n, _p2n } = getNewChildren({
450446
root: prevState.root,
451-
hozInLine,
452447
lastVisibleIndex: prevState.lastVisibleIndex,
453-
prefix,
454-
children,
455-
renderMore,
448+
...nextProps,
456449
});
457450

458451
state.newChildren = newChildren;
@@ -592,15 +585,11 @@ class Menu extends Component {
592585

593586
getUpdateChildren = () => {
594587
const { root, lastVisibleIndex } = this.state;
595-
const { prefix, hozInLine, children, renderMore } = this.props;
596588

597589
return getNewChildren({
598590
root,
599-
hozInLine,
600591
lastVisibleIndex,
601-
prefix,
602-
children,
603-
renderMore,
592+
...this.props,
604593
});
605594
};
606595

test/nav/index-spec.js

+40-7
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,42 @@ describe('Nav', () => {
411411
}, 500);
412412
});
413413

414+
it('should support iconOnly switch state', (done) => {
415+
wrapper = render(
416+
<Nav iconOnly={false} mode={"inline"} style={{ width: '200px' }} openKeys="icononly-switch-subnav">
417+
<SubNav icon="account" label="SubNav label" key="icononly-switch-subnav">
418+
<Item icon="account" key="1" id="icononly-switch-item-1">
419+
First
420+
</Item>
421+
<Item icon="account" key="2" id="icononly-switch-item-2">
422+
Second
423+
</Item>
424+
</SubNav>
425+
</Nav>
426+
);
427+
428+
assert(document.getElementById("icononly-switch-item-1").style.paddingLeft === '40px');
429+
assert(document.getElementById("icononly-switch-item-2").style.paddingLeft === '40px');
430+
431+
wrapper.setProps({
432+
iconOnly: true,
433+
mode: "popup"
434+
});
435+
436+
assert(document.getElementById("icononly-switch-item-1").style.paddingLeft === '');
437+
assert(document.getElementById("icononly-switch-item-2").style.paddingLeft === '');
438+
439+
wrapper.setProps({
440+
iconOnly: false,
441+
mode: "inline"
442+
});
443+
444+
assert(document.getElementById("icononly-switch-item-1").style.paddingLeft === '40px');
445+
assert(document.getElementById("icononly-switch-item-2").style.paddingLeft === '40px');
446+
447+
done();
448+
});
449+
414450
it('should support fixed', (done) => {
415451
wrapper = render(
416452
<Nav
@@ -439,13 +475,10 @@ describe('Nav', () => {
439475
</Nav>
440476
);
441477

442-
setTimeout(() => {
443-
const popup = document.querySelectorAll('.fixed-popup-sub3');
444-
assert(popup[0].style.top === '80px');
445-
assert(popup[0].style.left === '68px');
446-
447-
done();
448-
}, 500);
478+
const popup = document.querySelectorAll('.fixed-popup-sub3');
479+
assert(popup[0].style.top === '80px');
480+
assert(popup[0].style.left === '68px');
449481

482+
done();
450483
});
451484
});

0 commit comments

Comments
 (0)