Skip to content
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
10 changes: 10 additions & 0 deletions apps/website/screens/components/checkbox/code/CheckboxCodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ const sections = [
<td>Reference to the component.</td>
<td>-</td>
</tr>
<tr>
<td>ariaLabel</td>
<td>
<TableCode>string</TableCode>
</td>
<td>
Specifies a string to be used as the name for the checkbox element when no <Code>label</Code> is provided.
</td>
<td>'Checkbox'</td>
</tr>
</tbody>
</DxcTable>
),
Expand Down
6 changes: 6 additions & 0 deletions packages/lib/src/checkbox/Checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ describe("Checkbox component tests", () => {
expect(getByRole("checkbox").getAttribute("aria-required")).toBe("true");
expect(getByRole("checkbox").getAttribute("aria-readonly")).toBe("false");
expect(getByRole("checkbox").getAttribute("aria-disabled")).toBe("false");
expect(getByRole("checkbox").getAttribute("aria-label")).toBeNull();
});
test("Renders with correct aria-label", () => {
const { getByRole } = render(<DxcCheckbox ariaLabel="Example aria label" />);
const checkbox = getByRole("checkbox");
expect(checkbox.getAttribute("aria-label")).toBe("Example aria label");
});
test("Optional checkbox renders with correct aria-required", () => {
const { getByRole } = render(<DxcCheckbox label="Checkbox" optional />);
Expand Down
3 changes: 2 additions & 1 deletion packages/lib/src/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const DxcCheckbox = forwardRef<RefType, CheckboxPropsType>(
margin,
size = "fitContent",
tabIndex = 0,
ariaLabel = "Checkbox",
},
ref
): JSX.Element => {
Expand Down Expand Up @@ -94,7 +95,7 @@ const DxcCheckbox = forwardRef<RefType, CheckboxPropsType>(
aria-readonly={readOnly}
aria-required={!disabled && !optional}
aria-labelledby={label ? labelId : undefined}
aria-label={label ? undefined : "Checkbox"}
aria-label={label ? undefined : ariaLabel}
checked={checked ?? innerChecked}
disabled={disabled}
readOnly={readOnly}
Expand Down
4 changes: 4 additions & 0 deletions packages/lib/src/checkbox/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ type Props = {
* Value of the tabindex.
*/
tabIndex?: number;
/**
* Specifies a string to be used as the name for the checkbox element when no `label` is provided.
*/
ariaLabel?: string;
};

/**
Expand Down
Loading