Skip to content

Commit 9113a05

Browse files
Merge branch 'beta' into spark-77/update-radio-and-checkbox-components-for-shine
2 parents f455fac + 0b92e2c commit 9113a05

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

.changeset/true-guests-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@stackoverflow/stacks-svelte": minor
3+
---
4+
5+
Added aria-label and aria-labelledby props to PopoverContent

packages/stacks-svelte/src/components/Popover/Popover.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,75 @@ describe("Popover", () => {
193193
expect(innerContentElement).to.have.class("custom-class");
194194
});
195195

196+
it("should add aria-label to the popover when the ariaLabel prop is provided", async () => {
197+
render(Popover, {
198+
props: {
199+
...defaultProps,
200+
autoshow: true,
201+
children: createSvelteComponentsSnippet([
202+
defaultChildren.reference,
203+
{
204+
component: PopoverContent,
205+
props: {
206+
ariaLabel: "Popover with content",
207+
children: createRawSnippet(() => ({
208+
render: () => "<span>Popover Content</span>",
209+
})),
210+
},
211+
},
212+
]),
213+
},
214+
});
215+
216+
expect(screen.getByRole("dialog")).to.have.attribute(
217+
"aria-label",
218+
"Popover with content"
219+
);
220+
});
221+
222+
it("should add aria-labelledby to the popover when the ariaLabelledby prop is provided", async () => {
223+
render(Popover, {
224+
props: {
225+
...defaultProps,
226+
autoshow: true,
227+
children: createSvelteComponentsSnippet([
228+
defaultChildren.reference,
229+
{
230+
component: PopoverContent,
231+
props: {
232+
ariaLabelledby: "my-label-id",
233+
children: createRawSnippet(() => ({
234+
render: () => "<span>Popover Content</span>",
235+
})),
236+
},
237+
},
238+
]),
239+
},
240+
});
241+
242+
expect(screen.getByRole("dialog")).to.have.attribute(
243+
"aria-labelledby",
244+
"my-label-id"
245+
);
246+
});
247+
248+
it("should not add aria-label or aria-labelledby when not provided", async () => {
249+
render(Popover, {
250+
props: {
251+
...defaultProps,
252+
autoshow: true,
253+
children: createSvelteComponentsSnippet([
254+
defaultChildren.reference,
255+
defaultChildren.content,
256+
]),
257+
},
258+
});
259+
260+
const dialog = screen.getByRole("dialog");
261+
expect(dialog).not.to.have.attribute("aria-label");
262+
expect(dialog).not.to.have.attribute("aria-labelledby");
263+
});
264+
196265
it("add classes to the popover close button component when the class prop is provided", async () => {
197266
render(Popover, {
198267
props: {

packages/stacks-svelte/src/components/Popover/PopoverContent.svelte

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
* (if not specified, it will default to 'dialog' for popovers or 'tooltip' when in tooltip mode)
1010
*/
1111
role?: string | null;
12+
/**
13+
* Accessible label for the popover
14+
*/
15+
ariaLabel?: string;
16+
/**
17+
* ID of an element that labels the popover
18+
*/
19+
ariaLabelledby?: string;
1220
/**
1321
* Additional CSS classes added to the s-popover element
1422
*/
@@ -25,6 +33,8 @@
2533
2634
let {
2735
role = null,
36+
ariaLabel,
37+
ariaLabelledby,
2838
class: className = "",
2939
contentClass = "",
3040
children,
@@ -65,6 +75,8 @@
6575
id={`${pstate.id}-popover`}
6676
class={computedClass}
6777
role={computedRole}
78+
aria-label={ariaLabel}
79+
aria-labelledby={ariaLabelledby}
6880
use:pstate.floatingContent
6981
use:focusTrap={{ active: pstate.trapFocus && !!pstate.visible }}
7082
use:clickOutside

0 commit comments

Comments
 (0)