Implements AlertDialog with compound component pattern (Root, Content, Title, Description, Trigger, Cancel, Action, Portal, Overlay). Content uses role=alertdialog, aria-modal, aria-labelledby/describedby, focus trap, and scroll lock. Does not dismiss on Escape key. 8 tests passing.
23 lines
784 B
TypeScript
23 lines
784 B
TypeScript
import type { JSX } from "solid-js";
|
|
import { createUniqueId, onCleanup, onMount, splitProps } from "solid-js";
|
|
import { useInternalAlertDialogContext } from "./alert-dialog-context";
|
|
|
|
/** Props for AlertDialog.Title. */
|
|
export interface AlertDialogTitleProps extends JSX.HTMLAttributes<HTMLHeadingElement> {
|
|
children?: JSX.Element;
|
|
}
|
|
|
|
/** Title for the AlertDialog. Registers its ID for aria-labelledby. */
|
|
export function AlertDialogTitle(props: AlertDialogTitleProps): JSX.Element {
|
|
const [local, rest] = splitProps(props, ["children"]);
|
|
const ctx = useInternalAlertDialogContext();
|
|
const id = createUniqueId();
|
|
onMount(() => ctx.setTitleId(id));
|
|
onCleanup(() => ctx.setTitleId(undefined));
|
|
return (
|
|
<h2 id={id} {...rest}>
|
|
{local.children}
|
|
</h2>
|
|
);
|
|
}
|