Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/odd-times-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@spectrum-web-components/close-button': minor
---

Added visually hidden default slot rendering to sp-close-button so text content is accessible to screen readers while remaining invisible to sighted users.
9 changes: 8 additions & 1 deletion 1st-gen/packages/button/src/CloseButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ export class CloseButton extends SizedMixin(StyledButton, {
public staticColor?: 'black' | 'white';

protected override get buttonContent(): TemplateResult[] {
return [crossIcon[this.size]()];
return [
crossIcon[this.size](),
html`
<span id="label" class="visually-hidden">
<slot @slotchange=${this.manageTextObservedSlot}></slot>
</span>
`,
];
}
}
34 changes: 32 additions & 2 deletions 1st-gen/packages/button/test/close-button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

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

describe('Close Button', () => {
testForLitDevWarnings(
Expand Down Expand Up @@ -41,4 +41,34 @@ describe('Close Button', () => {
await expect(el).to.be.accessible();
});
});

describe('accessibility', () => {
it('should have accessible name with label attribute', async () => {
const el = await fixture<CloseButton>(html`
<sp-close-button label="Close"></sp-close-button>
`);

await elementUpdated(el);
expect(el.getAttribute('aria-label')).to.equal('Close');
await expect(el).to.be.accessible();
});

it('should have accessible name with default slot content', async () => {
const el = await fixture<CloseButton>(html`
<sp-close-button>Close</sp-close-button>
`);

await elementUpdated(el);
await expect(el).to.be.accessible();
});

it('should have accessible name when disabled', async () => {
const el = await fixture<CloseButton>(html`
<sp-close-button disabled>Close</sp-close-button>
`);

await elementUpdated(el);
await expect(el).to.be.accessible();
});
});
});
13 changes: 13 additions & 0 deletions 1st-gen/packages/close-button/src/close-button-overrides.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,16 @@
--spectrum-closebutton-static-background-color-down: var(--system-close-button-static-black-static-background-color-down);
--spectrum-closebutton-static-background-color-focus: var(--system-close-button-static-black-static-background-color-focus);
}

.visually-hidden {
border: 0;
clip: rect(0, 0, 0, 0);
clip-path: inset(50%);
height: 1px;
margin: 0 -1px -1px 0;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
white-space: nowrap;
}
Loading