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

chore(Modal): revert removal of unmountOnClose prop #2354

Merged
merged 2 commits into from
Aug 15, 2024
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
3 changes: 1 addition & 2 deletions packages/core/docs/vibe-3-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ codemod: `chips-component-migration`

- Modal no longer have the ability to remove the close button due to UX decision
- Removed `hideCloseButton` prop which is not needed anymore [codemod]
- Modal will not render if `show` is false
- `unmountOnClose` removed, modal will always unmount on close [codemod]
- The `unmountOnClose` prop default value changes to "true", meaning the Modal will not render if `show` is "false". To disable this behavior set `unmountOnClose` to "false".

### ModalHeader

Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export interface ModalProps {
*/
zIndex?: number;
/**
* If true, the modal will unmount when it's not shown
* When `false`, the modal will remain in the DOM when closed
*/
unmountOnClose?: boolean;
}
Expand All @@ -99,6 +99,7 @@ const Modal: FC<ModalProps> & { width?: typeof ModalWidthEnum } = ({
closeButtonAriaLabel = "Close",
contentSpacing = false,
zIndex = 10000,
unmountOnClose = true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment on line 85 but maybe we need to change the comment explaining about this prop

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will change

"data-testid": dataTestId
}: ModalProps) => {
const childrenArray: ReactElement[] = useMemo(
Expand Down Expand Up @@ -191,7 +192,7 @@ const Modal: FC<ModalProps> & { width?: typeof ModalWidthEnum } = ({
document.body
);

if (!shouldShow) {
if (unmountOnClose && !shouldShow) {
return null;
}

Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/components/Modal/__tests__/Modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const CLOSE_BUTTON_LABEL = "close";
const OPEN_BUTTON_TEXT = "Open";

const ModalManager = props => {
const { children, openOnStart = false, isAlertDialog = false, title } = props;
const { children, openOnStart = false, isAlertDialog = false, title, unmountOnClose } = props;
return (
<ModalExampleWrapper
buttonTitle="Open"
Expand All @@ -21,6 +21,7 @@ const ModalManager = props => {
title={title || MODAL_TITLE_TEXT}
alertDialog={isAlertDialog}
openModalTestId={OPEN_BUTTON_TEXT}
unmountOnClose={unmountOnClose}
>
{children}
</ModalExampleWrapper>
Expand Down Expand Up @@ -101,6 +102,16 @@ describe("Modal tests", () => {
expect(modal.getAttribute("role")).toMatch("dialog");
});

it("should have relevant aria attributes when hidden and unmountOnClose is false", () => {
const component = renderComponent({ unmountOnClose: false });
const modal = queryClosedModal(component);
expect(modal).toHaveAttribute("id");
expect(modal).toHaveAttribute("aria-modal");
expect(modal).toHaveAttribute("aria-labelledby");
expect(modal).toHaveAttribute("aria-hidden");
expect(modal.getAttribute("role")).toEqual("dialog");
});

it("should have relevant aria attributes when in alert mode", () => {
const component = renderComponent({ openOnStart: true, isAlertDialog: true });
const modal = queryClosedModal(component);
Expand Down