Skip to content

Commit 6574c5c

Browse files
committed
feat: add AlertDialogContent component to alert dialog implementation
- Introduced AlertDialogContent for rendering dialog content when open. - Added props for asChild and forceMount to enhance flexibility. - Updated accessibility attributes for better screen reader support.
1 parent df80bc7 commit 6574c5c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

packages/primitives/src/primitives/alert/alert-dialog.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,56 @@ export const AlertDialogOverlay = React.forwardRef<any, AlertDialogOverlayProps>
116116
}
117117
);
118118

119+
AlertDialogOverlay.displayName = "AlertDialogOverlay";
120+
121+
/* ---------------------------------- AlertDialogContent ---------------------------------- */
122+
123+
export type AlertDialogContentProps = ViewProps & {
124+
/**
125+
* Replace the host element by cloning the child.
126+
*/
127+
asChild?: boolean;
128+
129+
/**
130+
* Force mount the content even when closed (useful for animations).
131+
*/
132+
forceMount?: boolean;
133+
};
134+
135+
/**
136+
* AlertDialog content container.
137+
* Renders the dialog content when open.
138+
*/
139+
export const AlertDialogContent = React.forwardRef<any, AlertDialogContentProps>(
140+
(props, ref) => {
141+
const { asChild, forceMount, children, ...rest } = props;
142+
const context = useAlertDialogContext();
143+
144+
if (!context.open && !forceMount) {
145+
return null;
146+
}
147+
148+
const Comp = asChild ? Slot : View;
149+
150+
return (
151+
<Comp
152+
ref={ref}
153+
role="alertdialog"
154+
aria-modal={true}
155+
aria-labelledby={context.titleId}
156+
aria-describedby={context.descriptionId}
157+
{...rest}
158+
>
159+
{children}
160+
</Comp>
161+
);
162+
}
163+
);
164+
165+
AlertDialogContent.displayName = "AlertDialogContent";
166+
167+
/* ---------------------------------- AlertDialogTitle ---------------------------------- */
168+
119169
export type AlertDialogTitleProps = ViewProps;
120170

121171
export const AlertDialogTitle = React.forwardRef<any, AlertDialogTitleProps>(

0 commit comments

Comments
 (0)