Skip to content

Commit 2b5f3f1

Browse files
committed
fix(close-button): add a default slot containing visually hidden text for close button
1 parent 977d6de commit 2b5f3f1

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

1st-gen/packages/button/src/CloseButton.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ export class CloseButton extends SizedMixin(StyledButton, {
7575
public staticColor?: 'black' | 'white';
7676

7777
protected override get buttonContent(): TemplateResult[] {
78-
return [crossIcon[this.size]()];
78+
return [
79+
crossIcon[this.size](),
80+
html`
81+
<span id="label" class="visually-hidden">
82+
<slot @slotchange=${this.manageTextObservedSlot}></slot>
83+
</span>
84+
`,
85+
];
7986
}
8087
}

1st-gen/packages/button/test/close-button.test.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import '@spectrum-web-components/button/sp-close-button.js';
1414
import { CloseButton } from '@spectrum-web-components/button';
15-
import { expect, fixture, html } from '@open-wc/testing';
16-
import { testForLitDevWarnings } from '../../../test/testing-helpers';
15+
import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
16+
import { testForLitDevWarnings } from '../../../test/testing-helpers.js';
1717

1818
describe('Close Button', () => {
1919
testForLitDevWarnings(
@@ -41,4 +41,34 @@ describe('Close Button', () => {
4141
await expect(el).to.be.accessible();
4242
});
4343
});
44+
45+
describe('accessibility', () => {
46+
it('should have accessible name with label attribute', async () => {
47+
const el = await fixture<CloseButton>(html`
48+
<sp-close-button label="Close"></sp-close-button>
49+
`);
50+
51+
await elementUpdated(el);
52+
expect(el.getAttribute('aria-label')).to.equal('Close');
53+
await expect(el).to.be.accessible();
54+
});
55+
56+
it('should have accessible name with default slot content', async () => {
57+
const el = await fixture<CloseButton>(html`
58+
<sp-close-button>Close</sp-close-button>
59+
`);
60+
61+
await elementUpdated(el);
62+
await expect(el).to.be.accessible();
63+
});
64+
65+
it('should have accessible name when disabled', async () => {
66+
const el = await fixture<CloseButton>(html`
67+
<sp-close-button disabled>Close</sp-close-button>
68+
`);
69+
70+
await elementUpdated(el);
71+
await expect(el).to.be.accessible();
72+
});
73+
});
4474
});

1st-gen/packages/close-button/src/close-button-overrides.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,16 @@
2828
--spectrum-closebutton-static-background-color-down: var(--system-close-button-static-black-static-background-color-down);
2929
--spectrum-closebutton-static-background-color-focus: var(--system-close-button-static-black-static-background-color-focus);
3030
}
31+
32+
.visually-hidden {
33+
border: 0;
34+
clip: rect(0, 0, 0, 0);
35+
clip-path: inset(50%);
36+
height: 1px;
37+
margin: 0 -1px -1px 0;
38+
overflow: hidden;
39+
padding: 0;
40+
position: absolute;
41+
width: 1px;
42+
white-space: nowrap;
43+
}

0 commit comments

Comments
 (0)