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(dialog): ensure enableBackgroundUI is passed to Modal #7167

Merged
merged 1 commit into from
Jan 31, 2025
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
12 changes: 7 additions & 5 deletions src/components/dialog/dialog.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ export const Dialog = forwardRef<DialogHandle, DialogProps>(
topModalOverride,
closeButtonDataProps,
restoreFocusOnClose = true,
"aria-labelledby": ariaLabelledBy,
"aria-describedby": ariaDescribedBy,
"aria-label": ariaLabel,
...rest
},
ref,
Expand Down Expand Up @@ -197,12 +200,10 @@ export const Dialog = forwardRef<DialogHandle, DialogProps>(
size,
dialogHeight,
"aria-labelledby":
title && typeof title === "string" ? titleId : rest["aria-labelledby"],
title && typeof title === "string" ? titleId : ariaLabelledBy,
"aria-describedby":
subtitle && typeof subtitle === "string"
? subtitleId
: rest["aria-describedby"],
"aria-label": rest["aria-label"],
subtitle && typeof subtitle === "string" ? subtitleId : ariaDescribedBy,
"aria-label": ariaLabel,
};

return (
Expand All @@ -214,6 +215,7 @@ export const Dialog = forwardRef<DialogHandle, DialogProps>(
className={className ? `${className} carbon-dialog` : "carbon-dialog"}
topModalOverride={topModalOverride}
restoreFocusOnClose={restoreFocusOnClose}
{...rest}
>
<FocusTrap
autoFocus={!disableAutoFocus}
Expand Down
24 changes: 23 additions & 1 deletion src/components/dialog/dialog.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import {
waitForElementFocus,
} from "../../../playwright/support/helper";
import { CHARACTERS, SIZE } from "../../../playwright/support/constants";
import { getDataElementByValue } from "../../../playwright/components";
import {
getDataElementByValue,
backgroundUILocator,
} from "../../../playwright/components";

const specialCharacters = [CHARACTERS.DIACRITICS, CHARACTERS.SPECIALCHARACTERS];

Expand Down Expand Up @@ -102,6 +105,25 @@ test.describe("Testing Dialog component properties", () => {
});
});

[true, false].forEach((enableBackgroundUIValue) => {
test(`verify visibility of backgroundUILocatorElement when enableBackgroundUI prop is set to ${enableBackgroundUIValue}`, async ({
mount,
page,
}) => {
await mount(
<DialogComponent enableBackgroundUI={enableBackgroundUIValue} />,
);

const backgroundUILocatorElement = backgroundUILocator(page);

if (enableBackgroundUIValue) {
await expect(backgroundUILocatorElement).not.toBeVisible();
} else {
await expect(backgroundUILocatorElement).toBeVisible();
}
});
});

test("when showCloseIcon prop is false, should not render close icon", async ({
mount,
page,
Expand Down
Loading