Skip to content

Commit 28fb72c

Browse files
committed
fix(badge): improve language around screen reader text usage
1 parent deb4a0f commit 28fb72c

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

elements/pf-v6-badge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ A badge is used to annotate other information like a label or an object name.
2828

2929
| React prop | Notes |
3030
| --- | --- |
31-
| `screenReaderText` | No built-in screen reader text span. Authors should provide their own visually-hidden text adjacent to the badge. |
31+
| `screenReaderText` | Authors slot visually-hidden text alongside the badge content for screen reader context, e.g. `<pf-v6-badge>3 <span class="pf-v6-screen-reader">unread messages</span></pf-v6-badge>`. |
3232

3333
### Changed API
3434

elements/pf-v6-badge/pf-v6-badge.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export type BadgeState = 'unread' | 'read';
99
/**
1010
* A **badge** is used to annotate other information like a label or an object name.
1111
* @summary Displays a numeric value as an annotation
12+
* @slot - Badge content, typically a number or short text. Include a visually-hidden
13+
* `<span>` for screen reader context when the number alone is not descriptive.
1214
*/
1315
@customElement('pf-v6-badge')
1416
export class PfV6Badge extends LitElement {
@@ -42,7 +44,7 @@ export class PfV6Badge extends LitElement {
4244
(threshold && number && (threshold <= number)) ? `${threshold.toString()}+`
4345
: (number != null) ? number.toString()
4446
: '';
45-
return html`${!displayText ? html`<!-- Badge content, typically a number or short text --><slot></slot>` : displayText}`;
47+
return html`${!displayText ? html`<!-- Badge content, typically a number or short text with visually-hidden screen reader support text --><slot></slot>` : displayText}`;
4648
}
4749
}
4850

elements/pf-v6-badge/test/pf-v6-badge.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ describe('<pf-v6-badge>', function() {
3333

3434
it('should be visible in the accessibility tree', async function() {
3535
const snapshot = await a11ySnapshot();
36-
expect(snapshot.children?.length).to.be.greaterThan(0);
3736
const badgeNode = snapshot.children?.find(
3837
(child: { name?: string }) => child.name?.includes('100')
3938
);
@@ -155,12 +154,22 @@ describe('<pf-v6-badge>', function() {
155154
});
156155

157156
describe('accessibility', function() {
157+
it('should be accessible', async function() {
158+
const element = await createFixture<PfV6Badge>(html`
159+
<pf-v6-badge state="read" number="10">10</pf-v6-badge>
160+
`);
161+
await expect(element).to.be.accessible();
162+
});
163+
158164
it('should contain text in the accessibility tree', async function() {
159165
await createFixture<PfV6Badge>(html`
160166
<pf-v6-badge state="read" number="10">10</pf-v6-badge>
161167
`);
162168
const snapshot = await a11ySnapshot();
163-
expect(snapshot.children?.length).to.be.greaterThan(0);
169+
const badgeNode = snapshot.children?.find(
170+
(child: { name?: string }) => child.name?.includes('10')
171+
);
172+
expect(badgeNode).to.exist;
164173
});
165174
});
166175

0 commit comments

Comments
 (0)