Skip to content

Commit

Permalink
fix(prompt): filter footer children in one pass (#4002)
Browse files Browse the repository at this point in the history
* fix(prompt): filter footer children in one pass

* fix(prompt): apply suggestion

Co-authored-by: Gaël Dostie <[email protected]>

---------

Co-authored-by: Gaël Dostie <[email protected]>
  • Loading branch information
sfeng-coveo and gdostie authored Jan 23, 2025
1 parent 85d2568 commit a753fd3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/mantine/src/components/prompt/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ export const Prompt = factory<PromptFactory>((_props, ref) => {
});
const stylesApiProps = {classNames, styles};

const convertedChildren = Children.toArray(children) as ReactElement[];
const footers: ReactElement[] = [];
const otherChildren: ReactElement[] = [];

const otherChildren = convertedChildren.filter((child) => child.type !== Modal.Footer);
const footer = convertedChildren.find((child) => child.type === Modal.Footer);
Children.forEach(children, (child: ReactElement) => {
(child.type === Modal.Footer ? footers : otherChildren).push(child);
});

return (
<PromptContextProvider value={{variant, getStyles}}>
Expand All @@ -118,7 +120,7 @@ export const Prompt = factory<PromptFactory>((_props, ref) => {
<Modal.Body {...getStyles('body', stylesApiProps)}>
<Box {...getStyles('inner', stylesApiProps)}>{otherChildren}</Box>
</Modal.Body>
{footer}
{footers}
</Modal.Content>
</Modal.Root>
</PromptContextProvider>
Expand Down

0 comments on commit a753fd3

Please sign in to comment.