Commit 07915ba1 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Use `ModalDialog` for modal prompts

Replace deprecated `Modal` with `ModalDialog` for accessibility
improvements.
parent 7e35beb4
import { Button, Modal } from '@hypothesis/frontend-shared/lib/next'; import { Button, ModalDialog } from '@hypothesis/frontend-shared/lib/next';
import { render } from 'preact'; import { render } from 'preact';
import { createRef } from 'preact';
import type { RefObject } from 'preact';
import type { ComponentChildren } from 'preact'; import type { ComponentChildren } from 'preact';
export type ConfirmModalProps = { export type ConfirmModalProps = {
...@@ -25,6 +27,7 @@ export async function confirm({ ...@@ -25,6 +27,7 @@ export async function confirm({
message, message,
confirmAction = 'Yes', confirmAction = 'Yes',
}: ConfirmModalProps): Promise<boolean> { }: ConfirmModalProps): Promise<boolean> {
const cancelButton = createRef<HTMLElement | undefined>();
const container = document.createElement('div'); const container = document.createElement('div');
container.setAttribute('data-testid', 'confirm-container'); container.setAttribute('data-testid', 'confirm-container');
...@@ -43,10 +46,14 @@ export async function confirm({ ...@@ -43,10 +46,14 @@ export async function confirm({
}; };
render( render(
<Modal <ModalDialog
buttons={ buttons={
<> <>
<Button data-testid="cancel-button" onClick={() => close(false)}> <Button
elementRef={cancelButton}
data-testid="cancel-button"
onClick={() => close(false)}
>
Cancel Cancel
</Button> </Button>
<Button <Button
...@@ -58,11 +65,12 @@ export async function confirm({ ...@@ -58,11 +65,12 @@ export async function confirm({
</Button> </Button>
</> </>
} }
initialFocus={cancelButton as RefObject<HTMLElement>}
title={title} title={title}
onClose={() => close(false)} onClose={() => close(false)}
> >
{message} {message}
</Modal>, </ModalDialog>,
container container
); );
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment