diff --git a/src/components/ds/ui/Dialog.tsx b/src/components/ds/ui/Dialog.tsx
index 5e523c2d6..b0287b8c9 100644
--- a/src/components/ds/ui/Dialog.tsx
+++ b/src/components/ds/ui/Dialog.tsx
@@ -39,7 +39,11 @@ const sizeStyles: Record
= {
xl: 'max-w-xl',
}
+export type RestoreFocusRef = React.RefObject
+
type DialogContentProps = {
+ /** Explicit opener or fallback for externally controlled dialogs. */
+ restoreFocusRef?: RestoreFocusRef
children: React.ReactNode
size?: DialogSize
className?: string
@@ -48,7 +52,10 @@ type DialogContentProps = {
export const DialogContent = React.forwardRef<
HTMLDivElement,
DialogContentProps
->(function DialogContent({ children, size = 'sm', className }, ref) {
+>(function DialogContent(
+ { children, size = 'sm', className, restoreFocusRef },
+ ref,
+) {
return (
+ restoreFocusRef?.current?.isConnected ? restoreFocusRef.current : true
+ }
className={twMerge(
// Centring uses the independent `translate` property (that is what
// Tailwind v4 compiles these to), which leaves `transform` free for
diff --git a/src/components/npm-stats/BaselineSection.tsx b/src/components/npm-stats/BaselineSection.tsx
index c2010d371..eb178de81 100644
--- a/src/components/npm-stats/BaselineSection.tsx
+++ b/src/components/npm-stats/BaselineSection.tsx
@@ -16,6 +16,7 @@ import {
DialogBody,
DialogContent,
DialogHeader,
+ DialogTrigger,
} from '~/components/ds/ui'
import { PackageSearch } from './PackageSearch'
import { getBaselineDisplayName, type PackageGroup } from './shared'
@@ -137,14 +138,14 @@ export function BaselineSection({
const addButton = (
-
+
)
@@ -234,7 +235,7 @@ export function BaselineSection({
)
return (
- <>
+
-