Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu#4640 #4722

Merged
merged 10 commits into from
Jan 25, 2024
47 changes: 46 additions & 1 deletion components/menu/__tests__/index-spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React,{useEffect, useState} from 'react';
import ReactDOM from 'react-dom';
import Enzyme, { mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Expand Down Expand Up @@ -978,6 +978,51 @@ describe('Menu', () => {
document.body.removeChild(div);
});

it('should show renderMore when hozInLine & async load more items ', done => {
const div = document.createElement('div');
document.body.appendChild(div);

const items = [];
for (let i = 0; i < 50; i++) {
items.push(i);
}
function App() {
const [categoryList, setCategoryList] = useState([]);
useEffect(() => {
setCategoryList(items);
}, []);

return (
<Menu
hozInLine
direction="hoz"
triggerType="hover"
mode="popup"
popupAutoWidth
>
{categoryList.map((index, v) => (
<SubMenu label="Sub Nav" key={index}>
<Item key="sub-12">Sub option 1</Item>
<Item key="sub-22">Sub option 2</Item>
</SubMenu>
))}
</Menu>
);
}
ReactDOM.render(
<App/>,
div
);
const menu = document.querySelector('.next-menu');
assert(menu.querySelectorAll('li.next-menu-item').length === 52);
assert(menu.querySelectorAll('li.next-menu-item.next-menu-more').length === 2);
assert(menu.querySelectorAll('li.menuitem-overflowed').length > 1);
ReactDOM.unmountComponentAtNode(div);
document.body.removeChild(div);
done();
});


it('should support hozInLine with header&footer in hoz', () => {
const div = document.createElement('div');
document.body.appendChild(div);
Expand Down
5 changes: 3 additions & 2 deletions components/menu/view/menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ class Menu extends Component {

componentDidMount() {
this.menuNode = findDOMNode(this);

this.adjustChildrenWidth();

if (this.props.hozInLine) {
Expand All @@ -488,7 +487,9 @@ class Menu extends Component {
}

componentDidUpdate(prevProps, prevState) {
if (prevState.lastVisibleIndex !== this.state.lastVisibleIndex) {
if ( prevState.lastVisibleIndex !== this.state.lastVisibleIndex
|| ( React.Children.toArray(this.props.children).length !== React.Children.toArray(prevProps.children).length)
) {
this.adjustChildrenWidth();
}
}
Expand Down
Loading