Skip to content

Commit

Permalink
The headless ui dialog causes too many focus problems to keep it in. …
Browse files Browse the repository at this point in the history
…We'll need to look for an alternative.
  • Loading branch information
benmerckx committed Oct 11, 2023
1 parent 722e9fd commit 573ae03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/dashboard/view/Modal.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.root {
position: absolute;
position: fixed;
inset: 0;
z-index: 4;
padding: 20px 30px;
Expand Down
31 changes: 11 additions & 20 deletions src/dashboard/view/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
import {Dialog} from '@headlessui/react'
import {IconButton} from 'alinea/dashboard/view/IconButton'
import {IcRoundClose} from 'alinea/ui/icons/IcRoundClose'
import {fromModule} from 'alinea/ui/util/Styler'
import {ComponentPropsWithoutRef, PropsWithChildren, useRef} from 'react'
import {PropsWithChildren, useRef} from 'react'
import css from './Modal.module.scss'

const styles = fromModule(css)

export type ModalProps = PropsWithChildren<
{
open?: boolean
onClose: () => void
className?: string
} & ComponentPropsWithoutRef<typeof Dialog>
>
export type ModalProps = PropsWithChildren<{
open?: boolean
onClose: () => void
className?: string
}>
export function Modal({children, ...props}: ModalProps) {
const modalRef = useRef(null)

if (!props.open) return null
return (
<Dialog
{...props}
open={Boolean(props.open)}
ref={modalRef}
initialFocus={modalRef}
className={styles.root({open: props.open})}
>
<div {...props} ref={modalRef} className={styles.root({open: props.open})}>
<div className={styles.root.background()} onClick={props.onClose}></div>
<Dialog.Panel className={styles.root.inner.mergeProps(props)()}>
<div className={styles.root.inner.mergeProps(props)()}>
{children}
<IconButton
className={styles.root.inner.close()}
size={18}
icon={IcRoundClose}
onClick={props.onClose}
/>
</Dialog.Panel>
</Dialog>
</div>
</div>
)
}

0 comments on commit 573ae03

Please sign in to comment.