Skip to content
Closed
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
13 changes: 13 additions & 0 deletions apps/website/screens/components/dialog/code/DialogCodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ const sections = [
</tr>
</thead>
<tbody>
<tr>
<td>
<DxcFlex direction="column" gap="var(--spacing-gap-xs)" alignItems="baseline">
<StatusBadge status="new" />
ariaLabelledBy
</DxcFlex>
</td>
<td>
<TableCode>string</TableCode>
</td>
<td>Id of the element (usually the title of the dialog) that labels the dialog.</td>
<td>-</td>
</tr>
<tr>
<td>
<DxcFlex direction="column" gap="var(--spacing-gap-xs)" alignItems="baseline">
Expand Down
9 changes: 9 additions & 0 deletions packages/lib/src/dialog/Dialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ describe("Dialog component tests", () => {
expect(getByRole("dialog")).toBeTruthy();
expect(getByRole("dialog").getAttribute("aria-modal")).toBe("false");
});
test("Dialog is labelled by the element referenced in ariaLabelledBy", () => {
const { getByRole } = render(
<DxcDialog ariaLabelledBy="dialog-title">
<h2 id="dialog-title">Delivery address</h2>
</DxcDialog>
);
expect(getByRole("dialog", { name: "Delivery address" })).toBeTruthy();
expect(getByRole("dialog").getAttribute("aria-label")).toBeNull();
});
test("Calls correct function onCloseClick", () => {
const onCloseClick = jest.fn();
const { getByRole } = render(<DxcDialog onCloseClick={onCloseClick}>dialog-text</DxcDialog>);
Expand Down
9 changes: 8 additions & 1 deletion packages/lib/src/dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const CloseIconActionContainer = styled.div`
`;

const DxcDialog = ({
ariaLabelledBy,
children,
// Will have sense to be closable if onCloseClick is passed?
closable = true,
Expand Down Expand Up @@ -97,7 +98,13 @@ const DxcDialog = ({
createPortal(
<DialogContainer>
{overlay && <Overlay onClick={onBackgroundClick} />}
<Dialog aria-label="Dialog" aria-modal={overlay} closable={closable} role="dialog">
<Dialog
aria-label={ariaLabelledBy ? undefined : "Dialog"}
aria-labelledby={ariaLabelledBy}
aria-modal={overlay}
closable={closable}
role="dialog"
>
{!disableFocusLock ? (
<FocusLock>
{children}
Expand Down
4 changes: 4 additions & 0 deletions packages/lib/src/dialog/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ReactNode } from "react";

type Props = {
/**
* Id of the element (usually the title of the dialog) that labels the dialog.
*/
ariaLabelledBy?: string;
/**
* If true, the close button will be visible.
*/
Expand Down