Skip to content

Commit ec83dc4

Browse files
fix(docs): close version dropdown on variant change by useLocationChange Closes npm/cli#8414
1 parent 42b4395 commit ec83dc4

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/components/variant-select.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ const StyledOverlay = styled(ActionMenu.Overlay)`
1616

1717
const VariantItem = ({title, shortName, url, active}) => {
1818
return (
19-
<ActionList.Item state= {{scrollUpdate: false}} id={shortName} active={active}>
20-
<LinkNoUnderline
21-
to={url}
22-
>
23-
{title}
24-
</LinkNoUnderline>
25-
</ActionList.Item>)
19+
<ActionList.Item state={{scrollUpdate: false}} id={shortName} active={active}>
20+
<LinkNoUnderline to={url}>{title}</LinkNoUnderline>
21+
</ActionList.Item>
22+
)
2623
}
2724

2825
const useVariantFocus = () => {
@@ -42,6 +39,13 @@ const VariantMenu = ({title, latest, current, prerelease, legacy}) => {
4239
const [open, setOpen] = React.useState(false)
4340
const anchorRef = useVariantFocus()
4441
const labelId = 'label-versions-list-item'
42+
const locationChange = useLocationChange()
43+
44+
React.useEffect(() => {
45+
if (locationChange.change && getNav.didVariantChange(locationChange.previous, locationChange.current)) {
46+
setOpen(false)
47+
}
48+
}, [locationChange.change, locationChange.current, locationChange.previous])
4549

4650
return (
4751
<>

0 commit comments

Comments
 (0)