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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy