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

Checkbox aria checked #1514

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@ describe('va-checkbox', () => {
expect(checkboxEl).toEqualAttribute('aria-checked', 'mixed');
});

it('does not set aria-checked when toggled off', async () => {
const page = await newE2EPage();
await page.setContent(
'<va-checkbox label="Just another checkbox here" />',
);
const checkboxEl = await page.find('va-checkbox >>> input');

expect(checkboxEl).not.toHaveAttribute('aria-checked');
});

it('does not set the data-indeterminate attribute if checked is set', async () => {
const page = await newE2EPage();
await page.setContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ export class VaCheckbox {
.join(' ')
// Return null so we don't add the attribute if we have an empty string
.trim() || null;

let ariaChecked: boolean | string | null;
if (indeterminate && !checked) {
ariaChecked = 'mixed';
} else if (!indeterminate && !checked) {
ariaChecked = null;
} else {
ariaChecked = checked;
}

return (
<Host>
Expand Down Expand Up @@ -266,7 +275,7 @@ export class VaCheckbox {
aria-invalid={error ? 'true' : 'false'}
disabled={disabled}
data-indeterminate={indeterminate && !checked}
aria-checked={indeterminate && !checked ? 'mixed' : checked}
aria-checked={ariaChecked}
/>
<label htmlFor="checkbox-element" class="va-checkbox__label">
<span part="label">{label}</span>&nbsp;
Expand Down
Loading