-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UX-59 - add accessibility state labels to switch component (#456)
* feat: add aria-checked, aria-label, role to input * add changeset * fix: change role switch to checkbox * test: add tests for mt-switch * format code
- Loading branch information
1 parent
66b4e13
commit fbca9df
Showing
3 changed files
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@shopware-ag/meteor-component-library": patch | ||
--- | ||
|
||
Add aria attributes to mt-switch |
43 changes: 43 additions & 0 deletions
43
packages/component-library/src/components/form/mt-switch/mt-switch.spec.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,43 @@ | ||
import { mount } from "@vue/test-utils"; | ||
import MtSwitch from "./mt-switch.vue"; | ||
|
||
async function createWrapper(props = {}, options = {}) { | ||
return mount(MtSwitch, { | ||
propsData: { | ||
label: "Test Switch", | ||
...props, | ||
}, | ||
...options, | ||
}); | ||
} | ||
|
||
describe("mt-switch", () => { | ||
let wrapper: Awaited<ReturnType<typeof createWrapper>>; | ||
|
||
afterEach(() => { | ||
wrapper?.unmount(); | ||
}); | ||
|
||
it("should update checked state when checked", async () => { | ||
wrapper = await createWrapper(); | ||
const checkbox = wrapper?.find('input[type="checkbox"]'); | ||
|
||
await wrapper.setProps({ checked: true }); | ||
expect(checkbox.element).toBeChecked(); | ||
|
||
await wrapper.setProps({ checked: false }); | ||
expect(checkbox.element).not.toBeChecked(); | ||
}); | ||
|
||
it("should have correct ARIA attributes", async () => { | ||
wrapper = await createWrapper({ | ||
checked: true, | ||
label: "Accessibility Test", | ||
}); | ||
const checkbox = wrapper.find('input[type="checkbox"]'); | ||
|
||
expect(checkbox.attributes("role")).toBe("checkbox"); | ||
expect(checkbox.attributes("aria-checked")).toBe("true"); | ||
expect(checkbox.attributes("aria-label")).toBe("Accessibility Test"); | ||
}); | ||
}); |
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