Skip to content

Commit

Permalink
fix: feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
DorianMaliszewski committed Sep 7, 2023
1 parent 6067c87 commit e19dd06
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/ui/src/components/Modal/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ export const Dialog = ({
backdropCss,
}: DialogProps) => {
const containerRef = useRef(document.createElement('div'))
const dialogRef = useRef(document.createElement('dialog'))
const dialogRef = useRef<HTMLDialogElement>(null)
const onCloseRef = useRef(onClose)

// Portal to put the modal in
useEffect(() => {
const element = containerRef.current
if (open) {
document.body.appendChild(element)
dialogRef.current.focus()
dialogRef.current?.focus()
}

return () => {
Expand Down Expand Up @@ -167,9 +167,10 @@ export const Dialog = ({
return
}

const focusableEls = dialogRef.current.querySelectorAll(
'a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled])',
)
const focusableEls =
dialogRef.current?.querySelectorAll(
'a[href]:not([disabled]), button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled])',
) ?? []

// Handle case when no interactive element are within the modal (including close icon)
if (focusableEls.length === 0) {
Expand Down

0 comments on commit e19dd06

Please sign in to comment.