Files
Ayaan Gazali 18896e33de fix(studio): give two DropdownMenuTriggers asChild so they stop nesting buttons (#49264)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

Bug fix. Two `DropdownMenuTrigger`s wrap a `Button` without `asChild`,
so each renders a `<button>` inside a `<button>`. One of them also loses
its `aria-label`, leaving an icon-only menu trigger with no accessible
name.

## What is the current behavior?

`DropdownMenuTrigger` forwards to `DropdownMenuPrimitive.Trigger`, which
renders its own `<button>` unless `asChild` is set. So this:

```tsx
<DropdownMenuTrigger>
  <Button variant="default" className="px-1" icon={<MoreVertical />}
          aria-label={`Open actions for ${hook.title}`} />
</DropdownMenuTrigger>
```

produces `<button><button/></button>`, which is invalid HTML, and puts
the props on the inner element rather than on the thing that actually
opens the menu.

Measured by rendering `HookCard` before and after, rather than reasoning
about it:

| | before | after |
| --- | --- | --- |
| `container.querySelectorAll('button button').length` | 1 | 0 |
| `aria-label` on `[aria-haspopup="menu"]` | `null` | `Open actions for
Send Email` |

That second row is the part worth caring about. The `aria-label` was
written deliberately for a button whose only content is a `MoreVertical`
icon, and it lands on the nested inner button instead of the trigger, so
a screen reader gets no name for the control it actually operates.

Two sites:

- `components/interfaces/Auth/Hooks/HookCard.tsx`, the per-hook actions
menu. This is the one with the orphaned `aria-label`.
- `components/layouts/ProjectLayout/PauseFailedState.tsx`, the overflow
menu next to "Download backup".

## What is the new behavior?

Both get `asChild`, so the `Button` becomes the trigger. No nesting, and
the props land where they were meant to.

## Additional context

#48948 fixed exactly this in `RestoreFailedState.tsx`, which sits in the
same directory as `PauseFailedState.tsx` and has the same overflow-menu
shape. This is that fix applied to the two places it was not.

I swept all 4398 `.tsx` files across studio, www, docs, design-system,
ui-library, `packages/ui` and `packages/ui-patterns` for any Radix-style
trigger (`DropdownMenu`, `Tooltip`, `Popover`, `Dialog`, `Sheet`,
`AlertDialog`, `HoverCard`, `Collapsible`, `ContextMenu`, `Menubar`,
`Select`, `Tabs`, `Accordion`) that wraps a button-like element without
`asChild`. After discarding one false positive in
`EdgeFunctionDetails.tsx`, where the `Button` is a sibling of
`TabsTrigger` inside `TabsList` rather than its child, these two are the
only ones left. So this should be the end of the pattern rather than the
start of a series.

No test added, matching what #48948 did for the same change. The
`asChild` behaviour belongs to Radix, and a test asserting DOM nesting
around two JSX attributes would be testing the library. I did verify it
the other way round while developing: a throwaway render assertion
failed on unmodified master with a nested-button count of 1 and a null
trigger `aria-label`, and passed after the change. Happy to commit that
assertion if you would rather have it in the suite.

Gates: `test:prettier` passes repo wide, `typecheck --filter=studio
--force` passes 9/9, `--filter studio run lint:ratchet` reports rules
improved, and the tests covering both touched directories pass (18
files, 143 tests, including the `RestoringState` suite that came in with
#48948).

Freshman contributor. Found this with Claude Code's help by checking
whether the `asChild` fix in #48948 had siblings, and I confirmed the
nesting and the missing accessible name myself before touching anything.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved dropdown menu trigger behavior in the authentication hooks
and project layout interfaces.
* Existing buttons now correctly serve as menu triggers without changing
available actions or menu behavior.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-24 10:43:56 +02:00

173 lines
6.7 KiB
TypeScript

import { PermissionAction, SupportCategories } from '@supabase/shared-types/out/constants'
import { useParams } from 'common'
import { Download, MoreVertical, Trash } from 'lucide-react'
import { useState } from 'react'
import {
Button,
CriticalIcon,
Dialog,
DialogContent,
DialogHeader,
DialogSection,
DialogSectionSeparator,
DialogTitle,
DropdownMenu,
DropdownMenuContent,
DropdownMenuTrigger,
} from 'ui'
import { DeleteProjectModal } from '@/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectModal'
import { SupportLink } from '@/components/interfaces/Support/SupportLink'
import { LogicalBackupCliInstructions } from '@/components/layouts/ProjectLayout/LogicalBackupCliInstructions'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip'
import { InlineLink } from '@/components/ui/InlineLink'
import { useBackupDownloadMutation } from '@/data/database/backup-download-mutation'
import { useDownloadableBackupQuery } from '@/data/database/backup-query'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
export const PauseFailedState = () => {
const { ref } = useParams()
const { data: project } = useSelectedProjectQuery()
const [visible, setVisible] = useState(false)
const [showCliBackup, setShowCliBackup] = useState(false)
const { can: canDeleteProject } = useAsyncCheckPermissions(PermissionAction.UPDATE, 'projects', {
resource: { project_id: project?.id },
})
const { data, isPending: isLoadingBackups } = useDownloadableBackupQuery({ projectRef: ref })
const backups = data?.backups ?? []
const { mutate: downloadBackup, isPending: isDownloading } = useBackupDownloadMutation({
onSuccess: (res) => {
const { fileUrl } = res
// Trigger browser download by create,trigger and remove tempLink
const tempLink = document.createElement('a')
tempLink.href = fileUrl
document.body.appendChild(tempLink)
tempLink.click()
document.body.removeChild(tempLink)
},
})
const onClickDownloadBackup = () => {
if (!ref) return console.error('Project ref is required')
if (backups.length === 0 || data?.status === 'physical-backups-enabled')
return setShowCliBackup(true)
downloadBackup({ ref, backup: backups[0] })
}
const downloadBackupTooltipText = isLoadingBackups
? undefined
: data?.status === 'physical-backups-enabled'
? 'Project uses physical backups — click to see CLI backup instructions'
: backups.length === 0
? 'No downloadable backup available — click to see CLI backup instructions'
: undefined
return (
<>
<div className="flex items-center justify-center h-full">
<div className="bg-surface-100 border border-overlay rounded-md w-3/4 lg:w-1/2">
<div className="space-y-6 pt-6">
<div className="flex px-8 space-x-8">
<div className="mt-1">
<CriticalIcon className="w-5 h-5" />
</div>
<div className="space-y-1">
<p>Something went wrong while pausing your project</p>
<p className="text-sm text-foreground-light">
Your project's data is intact, but your project is inaccessible due to the failure
while pausing. Database backups for this project can still be accessed{' '}
<InlineLink href={`/project/${ref}/database/backups/scheduled`}>here</InlineLink>.
</p>
<p className="text-sm text-foreground-light">
Please contact support for assistance.
</p>
</div>
</div>
<div className="border-t border-overlay flex items-center justify-end gap-x-2 py-4 px-8">
<Button asChild variant="default">
<SupportLink
queryParams={{
category: SupportCategories.DATABASE_UNRESPONSIVE,
projectRef: project?.ref,
subject: 'Pausing failed for project',
}}
>
Contact support
</SupportLink>
</Button>
<ButtonTooltip
variant="default"
icon={<Download />}
disabled={isLoadingBackups}
loading={isDownloading || isLoadingBackups}
tooltip={{
content: {
side: 'bottom',
text: downloadBackupTooltipText,
},
}}
onClick={onClickDownloadBackup}
>
Download backup
</ButtonTooltip>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="default" className="px-1.5" icon={<MoreVertical />} />
</DropdownMenuTrigger>
<DropdownMenuContent className="w-72" align="end">
<DropdownMenuItemTooltip
onClick={() => setVisible(true)}
className="items-start gap-x-2"
disabled={!canDeleteProject}
tooltip={{
content: {
side: 'right',
text: !canDeleteProject
? 'You need additional permissions to delete this project'
: undefined,
},
}}
>
<div className="translate-y-0.5">
<Trash size={14} />
</div>
<div className="">
<p>Delete project</p>
<p className="text-foreground-lighter">
Project cannot be restored once it is deleted
</p>
</div>
</DropdownMenuItemTooltip>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
</div>
</div>
<Dialog open={showCliBackup} onOpenChange={setShowCliBackup}>
<DialogContent size="medium" onOpenAutoFocus={(e) => e.preventDefault()}>
<DialogHeader>
<DialogTitle>Back up your database with the Supabase CLI</DialogTitle>
</DialogHeader>
<DialogSectionSeparator />
<DialogSection>
<LogicalBackupCliInstructions showResetPassword={false} />
</DialogSection>
</DialogContent>
</Dialog>
<DeleteProjectModal visible={visible} onClose={() => setVisible(false)} />
</>
)
}