Skip to content

Commit

Permalink
fix(Menu): update fix menu async load items renderMore issues, close a…
Browse files Browse the repository at this point in the history
  • Loading branch information
lancely committed Jan 22, 2024
1 parent c22f143 commit 42a2a37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
24 changes: 12 additions & 12 deletions components/menu/__tests__/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ describe('Menu', () => {
document.body.removeChild(div);
});

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

Expand All @@ -987,7 +987,7 @@ describe('Menu', () => {
items.push(i);
}
function App() {
const [categoryList, setCategoryList] = useState(items);
const [categoryList, setCategoryList] = useState([]);
useEffect(() => {
setCategoryList(items);
}, []);
Expand All @@ -1014,17 +1014,17 @@ describe('Menu', () => {
<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);
setTimeout(() => {
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();
}, 9000);
});




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

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

0 comments on commit 42a2a37

Please sign in to comment.