From d377022417f986d333be206c34a1ddd51809f38b Mon Sep 17 00:00:00 2001 From: Vivek JM <24496671+vivekjm@users.noreply.github.com> Date: Sat, 20 Jun 2026 14:45:31 +0530 Subject: [PATCH] fix: handle fragments in dialog actions --- src/components/Dialog/DialogActions.tsx | 12 +++++++++--- src/components/__tests__/Dialog.test.tsx | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/components/Dialog/DialogActions.tsx b/src/components/Dialog/DialogActions.tsx index 7e3799451e..855f550f7c 100644 --- a/src/components/Dialog/DialogActions.tsx +++ b/src/components/Dialog/DialogActions.tsx @@ -48,18 +48,24 @@ export type Props = ViewProps & { */ const DialogActions = (props: Props) => { useInternalTheme(props.theme); - const actionsLength = React.Children.toArray(props.children).length; + + const actions = React.Children.toArray(props.children).flatMap((child) => + React.isValidElement<{ children?: React.ReactNode }>(child) && + child.type === React.Fragment + ? React.Children.toArray(child.props.children) + : child + ); return ( - {React.Children.map(props.children, (child, i) => + {actions.map((child, i) => React.isValidElement(child) ? React.cloneElement(child, { compact: true, uppercase: false, style: [ { - marginRight: i + 1 === actionsLength ? 0 : 8, + marginRight: i + 1 === actions.length ? 0 : 8, }, child.props.style, ], diff --git a/src/components/__tests__/Dialog.test.tsx b/src/components/__tests__/Dialog.test.tsx index eee5eaf631..d78427d7ee 100644 --- a/src/components/__tests__/Dialog.test.tsx +++ b/src/components/__tests__/Dialog.test.tsx @@ -152,6 +152,25 @@ describe('DialogActions', () => { expect(dialogActionButtons[0]).toHaveStyle({ margin: 10 }); expect(dialogActionButtons[1]).toHaveStyle({ margin: 0 }); }); + + it('should apply action props to children wrapped in a fragment', () => { + const { getByTestId } = render( + + <> + + + + + ); + + const dialogActionsContainer = getByTestId('dialog-actions'); + const dialogActionButtons = dialogActionsContainer.children; + + expect(getByTestId('button-cancel')).toBeDefined(); + expect(getByTestId('button-ok')).toBeDefined(); + expect(dialogActionButtons[0]).toHaveStyle({ marginRight: 8 }); + expect(dialogActionButtons[1]).toHaveStyle({ marginRight: 0 }); + }); }); const styles = StyleSheet.create({