Skip to content

Commit c61db22

Browse files
authored
fix(nav): Set secondary nav preview on click (#95124)
If you were very quick you could click on a nav item like "Settings" and move your mouse away before the secondary nav menu changed. It was previously only triggering on hover, but this adds a click event as well.
1 parent 585b1dd commit c61db22

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

static/app/views/nav/primary/components.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {Theme} from '@emotion/react';
33
import {css, useTheme} from '@emotion/react';
44
import styled from '@emotion/styled';
55
import {useHover} from '@react-aria/interactions';
6+
import {mergeProps} from '@react-aria/utils';
67

78
import type {ButtonProps} from 'sentry/components/core/button';
89
import {Button} from 'sentry/components/core/button';
@@ -170,7 +171,7 @@ function useActivateNavGroupOnHover(group: PrimaryNavGroup) {
170171

171172
// Slightly delay changing the active nav group to prevent accidentally triggering a new menu
172173
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
173-
return useHover({
174+
const {hoverProps} = useHover({
174175
onHoverStart: () => {
175176
if (timeoutRef.current) {
176177
clearTimeout(timeoutRef.current);
@@ -191,6 +192,15 @@ function useActivateNavGroupOnHover(group: PrimaryNavGroup) {
191192
}
192193
},
193194
});
195+
196+
return mergeProps(hoverProps, {
197+
onClick: () => {
198+
setActivePrimaryNavGroup(group);
199+
if (timeoutRef.current) {
200+
clearTimeout(timeoutRef.current);
201+
}
202+
},
203+
});
194204
}
195205

196206
function SidebarNavLink({
@@ -206,22 +216,24 @@ function SidebarNavLink({
206216
const location = useLocation();
207217
const isActive = isLinkActive(normalizeUrl(activeTo, location), location.pathname);
208218
const label = PRIMARY_NAV_GROUP_CONFIG[group].label;
209-
const {hoverProps} = useActivateNavGroupOnHover(group);
219+
const hoverProps = useActivateNavGroupOnHover(group);
220+
const linkProps = mergeProps(hoverProps, {
221+
onClick: () => {
222+
recordPrimaryItemClick(analyticsKey, organization);
223+
},
224+
});
210225

211226
return (
212227
<NavLink
213228
to={to}
214229
state={{source: SIDEBAR_NAVIGATION_SOURCE}}
215-
onClick={() => {
216-
recordPrimaryItemClick(analyticsKey, organization);
217-
}}
218230
aria-selected={activePrimaryNavGroup === group ? true : isActive}
219231
aria-current={isActive ? 'page' : undefined}
220232
isMobile={layout === NavLayout.MOBILE}
221233
{...{
222234
[NAV_PRIMARY_LINK_DATA_ATTRIBUTE]: true,
223235
}}
224-
{...hoverProps}
236+
{...linkProps}
225237
>
226238
{layout === NavLayout.MOBILE ? (
227239
<Fragment>

0 commit comments

Comments
 (0)