Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Dialog): forward rest props and fix contract prop precedence (#4078)

Cindy Zhang5f424ba1a498
diff --git a/.changeset/dialog-rest-forwarding.md b/.changeset/dialog-rest-forwarding.md
new file mode 100644
index 0000000000..1a2724d70c
--- /dev/null
+++ b/.changeset/dialog-rest-forwarding.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Forward rest props in Dialog and DialogHeader. DialogHeader now passes through data-testid, aria-*, and other attributes. Dialog's inline path forwards all rest props. Standard path spreads rest before contract props so onClick, onCancel, aria-modal, and role cannot be clobbered.
+
+@cixzhang
diff --git a/packages/core/src/Dialog/Dialog.tsx b/packages/core/src/Dialog/Dialog.tsx
index 0976150032..1f27ca2b38 100644
--- a/packages/core/src/Dialog/Dialog.tsx
+++ b/packages/core/src/Dialog/Dialog.tsx
@@ -508,6 +508,10 @@ export function Dialog({
</div>
);
+ // Filter out native open to prevent InvalidStateError when accidentally passed
+ const hasPosition = position != null && !isFullscreen;
+ const {open: _open, ...safeProps} = props as Record<string, unknown>;
+
// --- Inline rendering path (for documentation previews) ---
if (isInline) {
if (!isOpen) {
@@ -516,6 +520,7 @@ export function Dialog({
return (
<div
+ {...safeProps}
{...mergeProps(
themeProps('dialog', {variant}),
stylex.props(
@@ -526,30 +531,18 @@ export function Dialog({
),
className,
style,
- )}
- data-testid={
- (props as Record<string, unknown>)['data-testid'] as
- | string
- | undefined
- }>
+ )}>
{innerContent}
</div>
);
}
// --- Standard modal rendering path ---
- const hasPosition = position != null && !isFullscreen;
-
- // Filter out native open to prevent InvalidStateError when accidentally passed
- const {open: _open, ...safeProps} = props as Record<string, unknown>;
return (
<dialog
ref={mergeRefs(ref, dialogRef)}
- onClick={handleClick}
- onCancel={handleCancel}
- aria-modal="true"
- role={purpose === 'required' ? 'alertdialog' : undefined}
+ {...safeProps}
{...mergeProps(
themeProps('dialog', {variant}),
stylex.props(
@@ -570,7 +563,10 @@ export function Dialog({
className,
style,
)}
- {...safeProps}>
+ onClick={handleClick}
+ onCancel={handleCancel}
+ aria-modal="true"
+ {...(purpose === 'required' ? {role: 'alertdialog'} : undefined)}>
{innerContent}
</dialog>
);
diff --git a/packages/core/src/Dialog/DialogHeader.tsx b/packages/core/src/Dialog/DialogHeader.tsx
index 6f723daa18..a6fcb2a16a 100644
--- a/packages/core/src/Dialog/DialogHeader.tsx
+++ b/packages/core/src/Dialog/DialogHeader.tsx
@@ -131,6 +131,7 @@ export function DialogHeader({
className,
style,
ref,
+ ...rest
}: DialogHeaderProps) {
const t = useTranslator();
const titleRef = useRef<HTMLHeadingElement>(null);
@@ -152,7 +153,8 @@ export function DialogHeader({
hasDivider={hasDivider}
xstyle={xstyle}
className={className}
- style={style}>
+ style={style}
+ {...rest}>
<div {...stylex.props(styles.container)}>
{startContent && (
<div {...stylex.props(styles.actions)}>{startContent}</div>