Skip to content

Commit e0c14f4

Browse files
authored
Update Menu contents when root property changes (#79)
1 parent a224654 commit e0c14f4

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-storefront",
3-
"version": "8.0.0",
3+
"version": "8.0.1",
44
"description": "Build and deploy e-commerce progressive web apps (PWAs) in record time.",
55
"module": "./index.js",
66
"license": "Apache-2.0",

src/menu/Menu.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ const Menu = React.memo(props => {
4848
stateRef.current = state
4949
}, [state])
5050

51+
useEffect(() => {
52+
setState({
53+
card: 0,
54+
cards: [{ ...root, root: true }],
55+
})
56+
}, [root])
57+
5158
// this ensures that the expanded state is reset when showing a new card
5259
const nextKey = useRef(0)
5360

test/menu/Menu.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,32 @@ describe('Menu', () => {
121121
expect(wrapper.find(ListItem).length).toBe(3)
122122
})
123123

124+
it('should update contents when root property is updated', () => {
125+
wrapper = mount(
126+
<Menu
127+
root={{
128+
items: [
129+
{ text: 'item1', href: '/item1', as: '/item1', items: [] },
130+
{ text: 'item2', href: '/item2', as: '/item2' },
131+
{ text: 'item3', href: '/item3', as: '/item3' },
132+
],
133+
}}
134+
/>,
135+
)
136+
wrapper.setProps({
137+
root: {
138+
items: [
139+
{ text: 'item1', href: '/item1', as: '/item1' },
140+
{ text: 'item2', href: '/item2', as: '/item2' },
141+
{ text: 'item3', href: '/item3', as: '/item3' },
142+
{ text: 'item4', href: '/item4', as: '/item4' },
143+
],
144+
},
145+
})
146+
wrapper.update()
147+
expect(wrapper.find(ListItem).length).toBe(4)
148+
})
149+
124150
it('should use menu back to come back from submenu', () => {
125151
wrapper = mount(
126152
<Menu

0 commit comments

Comments
 (0)