Skip to content

Commit 29398e7

Browse files
authored
Use real links in dropdown menus (#2343)
add DropdownMenu.LinkItem so we can use real links when possible
1 parent 68e2dc8 commit 29398e7

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

app/components/TopBar.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* Copyright Oxide Computer Company
77
*/
88
import React from 'react'
9-
import { useNavigate } from 'react-router-dom'
109

1110
import { navToLogin, useApiMutation } from '@oxide/api'
1211
import { DirectionDownIcon, Profile16Icon } from '@oxide/design-system/icons/react'
@@ -17,7 +16,6 @@ import { DropdownMenu } from '~/ui/lib/DropdownMenu'
1716
import { pb } from '~/util/path-builder'
1817

1918
export function TopBar({ children }: { children: React.ReactNode }) {
20-
const navigate = useNavigate()
2119
const logout = useApiMutation('logout', {
2220
onSuccess: () => navToLogin({ includeCurrent: false }),
2321
})
@@ -63,9 +61,7 @@ export function TopBar({ children }: { children: React.ReactNode }) {
6361
</Button>
6462
</DropdownMenu.Trigger>
6563
<DropdownMenu.Content align="end" sideOffset={8}>
66-
<DropdownMenu.Item onSelect={() => navigate(pb.profile())}>
67-
Settings
68-
</DropdownMenu.Item>
64+
<DropdownMenu.LinkItem to={pb.profile()}>Settings</DropdownMenu.LinkItem>
6965
{loggedIn ? (
7066
<DropdownMenu.Item onSelect={() => logout.mutate({})}>
7167
Sign out

app/ui/lib/DropdownMenu.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ import {
1616
} from '@radix-ui/react-dropdown-menu'
1717
import cn from 'classnames'
1818
import { forwardRef, type ForwardedRef } from 'react'
19+
import { Link } from 'react-router-dom'
1920

2021
type DivRef = ForwardedRef<HTMLDivElement>
2122

23+
// remove possibility of disabling links for now. if we put it back, make sure
24+
// to forwardRef on LinkItem so the disabled tooltip can work
25+
type LinkitemProps = Omit<DropdownMenuItemProps, 'disabled'> & { to: string }
26+
2227
export const DropdownMenu = {
2328
Root,
2429
Trigger,
@@ -38,4 +43,9 @@ export const DropdownMenu = {
3843
Item: forwardRef(({ className, ...props }: DropdownMenuItemProps, ref: DivRef) => (
3944
<Item {...props} className={cn('DropdownMenuItem ox-menu-item', className)} ref={ref} />
4045
)),
46+
LinkItem: ({ className, children, to, ...props }: LinkitemProps) => (
47+
<Item {...props} className={cn('DropdownMenuItem ox-menu-item', className)} asChild>
48+
<Link to={to}>{children}</Link>
49+
</Item>
50+
),
4151
}

app/ui/styles/components/menu-button.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@apply z-30 min-w-36 rounded border p-0 bg-raise border-secondary;
1111

1212
& .DropdownMenuItem {
13-
@apply block cursor-pointer select-none border-b py-2 pl-3 pr-6 text-left text-sans-md text-secondary border-secondary last-of-type:border-b-0;
13+
@apply block cursor-pointer select-none border-b py-2 pl-3 pr-6 text-left text-sans-md text-secondary border-secondary last:border-b-0;
1414

1515
&.destructive {
1616
@apply text-destructive;

0 commit comments

Comments
 (0)