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

Fix DialogContainer when not compiled with React Compiler #1222

Merged
Merged
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
5 changes: 5 additions & 0 deletions .changeset/real-trains-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystar/ui': patch
---

Fix `DialogContainer` when not compiled with React Compiler
10 changes: 3 additions & 7 deletions design-system/pkg/src/dialog/DialogContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useOverlayTriggerState } from '@react-stately/overlays';
import React, { ReactNode, useState } from 'react';
import React, { isValidElement, ReactElement, useState } from 'react';

import { Modal } from '@keystar/ui/overlays';

Expand All @@ -20,13 +20,9 @@ export function DialogContainer(props: DialogContainerProps) {
isKeyboardDismissDisabled,
} = props;

let childArray = React.Children.toArray(children);
if (childArray.length > 1) {
throw new Error('Only a single child can be passed to DialogContainer.');
}
const child = isValidElement(children) ? children : null;

let child = React.isValidElement(childArray[0]) ? childArray[0] : null;
let [lastChild, setLastChild] = useState<ReactNode>(child);
let [lastChild, setLastChild] = useState<ReactElement | null>(child);
if (child && child !== lastChild) {
setLastChild(child);
}
Expand Down
2 changes: 1 addition & 1 deletion design-system/pkg/src/dialog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type DialogTriggerProps = {

export interface DialogContainerProps {
/** The dialog to display, if any. */
children: ReactNode;
children: Exclude<ReactNode, Iterable<ReactNode>> | string;
/** Handler that is called when the [×] button of a dismissable dialog is clicked. */
onDismiss: () => void;
/**
Expand Down
Loading