diff --git a/js/atoms/Block.test.ts b/js/atoms/Block.test.ts new file mode 100644 index 0000000000..fa5a1b5ce9 --- /dev/null +++ b/js/atoms/Block.test.ts @@ -0,0 +1,83 @@ +import { test, describe, assert, afterEach, beforeEach } from "vitest"; +import { tick, mount, unmount } from "svelte"; + +import Block from "./src/Block.svelte"; + +describe("Block Accessibility", () => { + let target: HTMLElement; + let component: any; + + beforeEach(() => { + target = document.body.appendChild(document.createElement("div")); + }); + + afterEach(() => { + if (component) { + unmount(component); + } + if (target.parentNode) { + target.parentNode.removeChild(target); + } + }); + + test("renders with aria-label when label prop is provided", async () => { + component = mount(Block, { + target, + props: { + label: "Test Block Label" + } + }); + await tick(); + const block = target.querySelector(".block"); + assert.equal(block?.getAttribute("aria-label"), "Test Block Label"); + }); + + test("renders with role='group' when type is fieldset", async () => { + component = mount(Block, { + target, + props: { + type: "fieldset", + label: "Fieldset Group" + } + }); + await tick(); + const block = target.querySelector(".block"); + assert.equal(block?.getAttribute("role"), "group"); + assert.equal(block?.tagName.toLowerCase(), "fieldset"); + }); + + test("renders without role when type is normal", async () => { + component = mount(Block, { + target, + props: { + type: "normal" + } + }); + await tick(); + const block = target.querySelector(".block"); + assert.isNull(block?.getAttribute("role")); + assert.equal(block?.tagName.toLowerCase(), "div"); + }); + + test("renders as div by default", async () => { + component = mount(Block, { + target, + props: {} + }); + await tick(); + const block = target.querySelector(".block"); + assert.equal(block?.tagName.toLowerCase(), "div"); + }); + + test("renders as fieldset when type is fieldset", async () => { + component = mount(Block, { + target, + props: { + type: "fieldset" + } + }); + await tick(); + const block = target.querySelector(".block"); + assert.equal(block?.tagName.toLowerCase(), "fieldset"); + }); +}); diff --git a/js/atoms/src/Block.svelte b/js/atoms/src/Block.svelte index 5b6d51a9ba..e2ac387047 100644 --- a/js/atoms/src/Block.svelte +++ b/js/atoms/src/Block.svelte @@ -21,6 +21,7 @@ export let resizable = false; export let rtl = false; export let fullscreen = false; + export let label: string | undefined = undefined; let old_fullscreen = fullscreen; let element: HTMLElement; @@ -129,6 +130,8 @@ style:border-width="var(--block-border-width)" class:auto-margin={scale === null} dir={rtl ? "rtl" : "ltr"} + role={type === "fieldset" ? "group" : undefined} + aria-label={label} > {#if resizable} diff --git a/js/core/src/Blocks.svelte b/js/core/src/Blocks.svelte index 46c5ab2cf1..7ba5606cf9 100644 --- a/js/core/src/Blocks.svelte +++ b/js/core/src/Blocks.svelte @@ -445,17 +445,21 @@
-
-
+ {#if footer_links.length > 0} -