-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(checkbox): support w3c WAI-ARIA (a11y) pattern (#1130)
- Loading branch information
Showing
5 changed files
with
95 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
packages/oruga/src/components/checkbox/tests/__snapshots__/checkbox.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`OCheckbox tests > render correctly 1`] = ` | ||
"<label class="o-chk" data-oruga="checkbox" role="checkbox" aria-checked="false"><input id="v-0" type="checkbox" data-oruga-input="checkbox" class="o-chk__input" autocomplete="off" true-value="true" false-value="false"> | ||
<!--v-if--> | ||
</label>" | ||
"<div class="o-chk" data-oruga="checkbox"><input id="v-0" type="checkbox" data-oruga-input="checkbox" class="o-chk__input" true-value="true" false-value="false" autocomplete="off" aria-checked="false" aria-labelledby="v-1"><label id="v-1" for="v-0" class="o-chk__label"> | ||
<!-- | ||
@slot Content slot, default is label prop | ||
-->My Input | ||
</label></div>" | ||
`; |
49 changes: 49 additions & 0 deletions
49
packages/oruga/src/components/checkbox/tests/checkbox.axe.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { afterEach, describe, expect, test } from "vitest"; | ||
import { enableAutoUnmount, mount } from "@vue/test-utils"; | ||
import { axe } from "jest-axe"; | ||
|
||
import OCheckbox from "../Checkbox.vue"; | ||
|
||
describe("Checkbox axe tests", () => { | ||
enableAutoUnmount(afterEach); | ||
|
||
const a11yCases = [ | ||
{ | ||
title: "axe checkbox - base case", | ||
props: { label: "Checkbox Label" }, | ||
}, | ||
{ | ||
title: "axe checkbox - indeterminate case", | ||
props: { label: "Checkbox Label", indeterminate: true }, | ||
}, | ||
{ | ||
title: "axe checkbox - id case", | ||
props: { label: "Checkbox Label", id: "my-id" }, | ||
}, | ||
{ | ||
title: "axe checkbox - variant case", | ||
props: { label: "Checkbox Label", variant: "success" }, | ||
}, | ||
{ | ||
title: "axe checkbox - size case", | ||
props: { label: "Checkbox Label", size: "large" }, | ||
}, | ||
{ | ||
title: "axe checkbox - required case", | ||
props: { label: "Checkbox Label", required: true }, | ||
}, | ||
{ | ||
title: "axe checkbox - disabled case", | ||
props: { label: "Checkbox Label", disabled: true }, | ||
}, | ||
]; | ||
|
||
test.each(a11yCases)("$title", async ({ props }) => { | ||
const wrapper = mount(OCheckbox, { | ||
props: { ...props }, | ||
attachTo: document.body, | ||
}); | ||
|
||
expect(await axe(wrapper.element)).toHaveNoViolations(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters