Skip to content

Commit 927c8b6

Browse files
authored
minor: hook up Dialog.Title better in modal to fix Radix errors (#2608)
minor: hook up dialog.title better in modal to fix errors
1 parent 01a0ac9 commit 927c8b6

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

app/ui/lib/Modal.tsx

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import * as Dialog from '@radix-ui/react-dialog'
99
import { animated, useTransition } from '@react-spring/web'
1010
import cn from 'classnames'
11-
import React, { forwardRef, useId } from 'react'
1211
import type { MergeExclusive } from 'type-fest'
1312

1413
import { Close12Icon } from '@oxide/design-system/icons/react'
@@ -42,7 +41,6 @@ export function Modal({
4241
narrow,
4342
overlay = true,
4443
}: ModalProps) {
45-
const titleId = useId()
4644
const AnimatedDialogContent = animated(Dialog.Content)
4745

4846
const config = { tension: 650, mass: 0.125 }
@@ -74,7 +72,7 @@ export function Modal({
7472
'pointer-events-auto fixed left-1/2 top-[min(50%,500px)] z-modal m-0 flex max-h-[min(800px,80vh)] w-full flex-col justify-between rounded-lg border p-0 bg-raise border-secondary elevation-2',
7573
narrow ? 'max-w-[24rem]' : 'max-w-[28rem]'
7674
)}
77-
aria-labelledby={titleId}
75+
aria-describedby={undefined} // radix warns without this
7876
style={{
7977
transform: y.to((value) => `translate3d(-50%, ${-50 + value}%, 0px)`),
8078
}}
@@ -85,12 +83,12 @@ export function Modal({
8583
// https://github.com/oxidecomputer/console/issues/1745
8684
onFocusOutside={(e) => e.preventDefault()}
8785
>
88-
<Dialog.Title asChild>
89-
<ModalTitle id={titleId}>{title}</ModalTitle>
86+
<Dialog.Title className="border-b px-4 py-4 text-sans-semi-lg bg-secondary border-b-secondary">
87+
{title}
9088
</Dialog.Title>
9189
{children}
9290
<Dialog.Close
93-
className="absolute right-2 top-4 flex items-center justify-center rounded p-2 hover:bg-hover"
91+
className="absolute right-2 top-3.5 flex items-center justify-center rounded p-2 hover:bg-hover"
9492
aria-label="Close"
9593
>
9694
<Close12Icon className="text-default" />
@@ -104,24 +102,6 @@ export function Modal({
104102
)
105103
}
106104

107-
interface ModalTitleProps {
108-
children?: React.ReactNode
109-
id?: string
110-
}
111-
112-
// not exported because we want to use the `title` prop on Modal so the aria
113-
// label gets hooked up properly
114-
const ModalTitle = forwardRef<HTMLDivElement, ModalTitleProps>(({ children, id }, ref) => (
115-
<div
116-
ref={ref}
117-
className="flex items-center justify-between border-b px-4 py-4 bg-secondary border-b-secondary"
118-
>
119-
<h2 className="text-sans-semi-lg" id={id}>
120-
{children}
121-
</h2>
122-
</div>
123-
))
124-
125105
Modal.Body = classed.div`py-2 overflow-y-auto`
126106

127107
Modal.Section = classed.div`p-4 space-y-4 border-b border-secondary text-default last-of-type:border-none text-sans-md`

0 commit comments

Comments
 (0)