Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation menu - add prop to change default close delay #3171

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .yarn/versions/98967128.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
releases:
"@radix-ui/react-navigation-menu": minor
primitives: minor
10 changes: 10 additions & 0 deletions packages/react/navigation-menu/src/NavigationMenu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ export const CustomDurations = () => {

<h2>Custom (2000ms to move from one trigger to another)</h2>
<DurationNavigation delayDuration={500} skipDelayDuration={2000} />

<h1 style={{ marginTop: 50 }}>Close delay duration</h1>
<h2>Default (150ms)</h2>
<DurationNavigation />

<h2>Custom (500ms)</h2>
<DurationNavigation closeDelayDuration={500} />

<h2>Custom (1000ms)</h2>
<DurationNavigation closeDelayDuration={1000} />
</div>
);
};
Expand Down
8 changes: 7 additions & 1 deletion packages/react/navigation-menu/src/NavigationMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ interface NavigationMenuProps
* @defaultValue 300
*/
skipDelayDuration?: number;
/**
* The delay before closing menu when the pointer leaves trigger or content area.
* @defaultValue 150
*/
closeDelayDuration?: number;
}

const NavigationMenu = React.forwardRef<NavigationMenuElement, NavigationMenuProps>(
Expand All @@ -106,6 +111,7 @@ const NavigationMenu = React.forwardRef<NavigationMenuElement, NavigationMenuPro
defaultValue,
delayDuration = 200,
skipDelayDuration = 300,
closeDelayDuration = 150,
orientation = 'horizontal',
dir,
...NavigationMenuProps
Expand Down Expand Up @@ -141,7 +147,7 @@ const NavigationMenu = React.forwardRef<NavigationMenuElement, NavigationMenuPro

const startCloseTimer = React.useCallback(() => {
window.clearTimeout(closeTimerRef.current);
closeTimerRef.current = window.setTimeout(() => setValue(''), 150);
closeTimerRef.current = window.setTimeout(() => setValue(''), closeDelayDuration);
}, [setValue]);

const handleOpen = React.useCallback(
Expand Down