Skip to content

Commit bdb2b39

Browse files
fix(tabs): roles in sr (#2731)
* fix(tabs): roles in sr * fix(tabs): only expand tabs the tabset owns --------- Co-authored-by: Steven Spriggs <[email protected]>
1 parent 5371c5b commit bdb2b39

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

.changeset/nice-moments-doubt.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
"@patternfly/elements": patch
3+
---
4+
`<pf-tabs>`: improved screen-reader accessibility

core/pfe-core/controllers/tabs-aria-controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ export class TabsAriaController<
9292
for (const child of this.#element.children) {
9393
if (this.#options.isTab(child)) {
9494
tabs.push(child);
95+
child.role ??= 'tab';
9596
} else if (this.#options.isPanel(child)) {
9697
panels.push(child);
98+
child.role ??= 'tabpanel';
9799
}
98100
}
99101
if (tabs.length > panels.length) {

elements/pf-tabs/pf-tab-panel.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { state } from 'lit/decorators/state.js';
44
import { consume } from '@lit/context';
55

66
import { getRandomId } from '@patternfly/pfe-core/functions/random.js';
7+
78
import { type PfTabsContext, context } from './context.js';
89

910
import styles from './pf-tab-panel.css';
@@ -19,8 +20,6 @@ import styles from './pf-tab-panel.css';
1920
export class PfTabPanel extends LitElement {
2021
static readonly styles = [styles];
2122

22-
#internals = this.attachInternals();
23-
2423
@consume({ context, subscribe: true })
2524
@state() private ctx?: PfTabsContext;
2625

@@ -34,7 +33,6 @@ export class PfTabPanel extends LitElement {
3433
super.connectedCallback();
3534
this.id ||= getRandomId('pf-tab-panel');
3635
this.hidden ??= true;
37-
this.#internals.role = 'tabpanel';
3836

3937
/*
4038
To make it easy for screen reader users to navigate from a tab

elements/pf-tabs/pf-tabs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ export class PfTabs extends LitElement {
234234
}
235235

236236
#onExpand(event: Event) {
237-
if (event instanceof TabExpandEvent && !event.defaultPrevented) {
237+
if (event instanceof TabExpandEvent &&
238+
!event.defaultPrevented && this.tabs.includes(event.tab)) {
238239
this.select(event.tab);
239240
}
240241
}

0 commit comments

Comments
 (0)