Skip to content

Commit 6784ad1

Browse files
committed
fix: Menu miss pass the style into sub MenuItem
fix ant-design/ant-design#16935
1 parent 4f839f8 commit 6784ad1

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/DOMWrap.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ class DOMWrap extends React.Component {
8080
}
8181

8282
getOverflowedSubMenuItem = (keyPrefix, overflowedItems, renderPlaceholder) => {
83-
const { overflowedIndicator, level, mode, prefixCls, theme, style: propStyle } = this.props;
83+
const { overflowedIndicator, level, mode, prefixCls, theme } = this.props;
8484
if (level !== 1 || mode !== 'horizontal') {
8585
return null;
8686
}
8787
// put all the overflowed item inside a submenu
8888
// with a title of overflow indicator ('...')
8989
const copy = this.props.children[0];
90-
const { children: throwAway, title, ...rest } = copy.props;
90+
const { children: throwAway, title, style: propStyle, ...rest } = copy.props;
9191

9292
let style = { ...propStyle };
9393
let key = `${keyPrefix}-overflowed-indicator`;

tests/SubPopupMenu.spec.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import { mount } from 'enzyme';
33
import { saveRef } from '../src/SubPopupMenu';
44
import Menu, { MenuItem } from '../src';
55

6-
describe('SubPopupMenu saveRef', () => {
6+
describe('SubPopupMenu', () => {
77
let subPopupMenu;
88

9-
109
beforeEach(() => {
1110
subPopupMenu = { instanceArray: [] };
1211
});
@@ -30,11 +29,14 @@ describe('SubPopupMenu saveRef', () => {
3029
<Menu activeKey="1">
3130
<MenuItem key="1">1</MenuItem>
3231
<MenuItem key="2">2</MenuItem>
33-
</Menu>
32+
</Menu>,
3433
);
3534

3635
function getItemActive(index) {
37-
return wrapper.find('MenuItem').at(index).instance().props.active;
36+
return wrapper
37+
.find('MenuItem')
38+
.at(index)
39+
.instance().props.active;
3840
}
3941
expect(getItemActive(0)).toBe(true);
4042
expect(getItemActive(1)).toBe(false);
@@ -44,4 +46,28 @@ describe('SubPopupMenu saveRef', () => {
4446
expect(getItemActive(0)).toBe(false);
4547
expect(getItemActive(1)).toBe(true);
4648
});
49+
50+
it('not pass style into sub menu item', () => {
51+
const wrapper = mount(
52+
<Menu mode="horizontal" style={{ background: 'green' }}>
53+
<MenuItem style={{ color: 'red' }} key="1">
54+
1
55+
</MenuItem>
56+
</Menu>,
57+
);
58+
59+
expect(
60+
wrapper
61+
.find('li.rc-menu-overflowed-submenu')
62+
.at(0)
63+
.props().style,
64+
).toEqual({ color: 'red', display: 'none' });
65+
66+
expect(
67+
wrapper
68+
.find('li.rc-menu-item')
69+
.at(0)
70+
.props().style,
71+
).toEqual({ color: 'red' });
72+
});
4773
});

0 commit comments

Comments
 (0)