Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proof of concept dialog element #61

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const ModalWrapper: React.FC<ModalWrapperProps> = ({
focusTrapOptions,
components,
}) => {
const dialogRef = useRef<HTMLDivElement>(null);
const dialogRef = useRef<HTMLDialogElement>(null);
const _focusTrapOptions = useMemo(
() => ({
onDeactivate: close,
Expand All @@ -52,8 +52,9 @@ export const ModalWrapper: React.FC<ModalWrapperProps> = ({
return createPortal(
<components.Wrapper>
<components.Overlay />
<div
<dialog
ref={dialogRef}
id="dialog-poc"
role="dialog"
aria-modal="true"
tabIndex={-1}
Expand All @@ -62,7 +63,7 @@ export const ModalWrapper: React.FC<ModalWrapperProps> = ({
<components.Modal title={title} description={description} close={close}>
{children}
</components.Modal>
</div>
</dialog>
</components.Wrapper>,
document.getElementById(elementId) as HTMLElement
);
Expand Down
5 changes: 3 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ export const useModal: UseModal = (elementId = 'root', options) => {
);
const [isOpen, setOpen] = useState<boolean>(false);

const open = useCallback(() => {
setOpen(true);
const open = useCallback(async () => {
await setOpen(true);
document.getElementById('dialog-poc').showModal();
}, [setOpen]);

const close = useCallback(() => {
Expand Down