Skip to content

Commit

Permalink
UX-59 - add accessibility state labels to switch component (#456)
Browse files Browse the repository at this point in the history
* 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
alastair-simon authored Jan 20, 2025
1 parent 66b4e13 commit fbca9df
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-cameras-joke.md
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
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");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
:name="formFieldName || identification"
:checked="inputState"
:disabled="isDisabled"
:aria-checked="inputState"
:aria-label="label"
role="checkbox"
@change.stop="onChange"
/>
<div class="mt-field__switch-state">
Expand Down

0 comments on commit fbca9df

Please sign in to comment.