You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I try to implement javascript navigation when Menu.Item is clicked. When menu item is an anchor element I prevent browser default action and attach onClick handler to navigate. Now this works great except menu stays opened. Does not happen when navigating and selecting with keyboard.
// This the click handler which navigatesconstnavigate: MouseEventHandler<HTMLAnchorElement>=(event)=>{event.preventDefault();// Commenting out this line returns the behavior, but causes page refreshhistory.push(event.currentTarget.pathname);};// This is a header component where menu is located<HeadercreateFeedAnchorProps={{href: "/create-feed",onClick: navigate}}authenticatedUserDropdownProps={{userName: "Giorgi Botsvadze",items: [{icon: UserIcon,label: "My Account",href: "/account",onClick: navigate,},{icon: CogIcon,label: "Admin Tools",href: "/admin-tools",onClick: navigate,},{icon: LogoutIcon,label: "Logout",href: "/auth/logout",onClick: navigate,},],}}/>// Somewhere in Header in Menu componentconst{icon: Icon, label, ...htmlAnchorAttributes}=authenticatedUserDropdownProps;<likey={index}><Menu.Item>{({ active })=>(<a{...htmlAnchorAttributes}className={clsx("tw-h-8 tw-px-5 hover:tw-no-underline hover:tw-text-black tw-flex tw-items-center tw-text-sm tw-font-semibold tw-text-black",active ? "tw-bg-slate-100" : "tw-bg-white")}><IconclassName="tw-mr-2 tw-w-5 tw-h-5 tw-shrink-0"/><span>{label}</span></a>)}</Menu.Item></li>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I try to implement javascript navigation when
Menu.Item
is clicked. When menu item is ananchor
element I prevent browser default action and attachonClick
handler to navigate. Now this works great except menu stays opened. Does not happen when navigating and selecting with keyboard.Beta Was this translation helpful? Give feedback.
All reactions