Skip to content

Commit

Permalink
fix(tabs): roles in sr (#2731)
Browse files Browse the repository at this point in the history
* fix(tabs): roles in sr

* fix(tabs): only expand tabs the tabset owns

---------

Co-authored-by: Steven Spriggs <steven.spriggs@gmail.com>
  • Loading branch information
bennypowers and zeroedin committed Mar 28, 2024
1 parent 5371c5b commit bdb2b39
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .changeset/nice-moments-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/elements": patch
---
`<pf-tabs>`: improved screen-reader accessibility
2 changes: 2 additions & 0 deletions core/pfe-core/controllers/tabs-aria-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ export class TabsAriaController<
for (const child of this.#element.children) {
if (this.#options.isTab(child)) {
tabs.push(child);
child.role ??= 'tab';
} else if (this.#options.isPanel(child)) {
panels.push(child);
child.role ??= 'tabpanel';
}
}
if (tabs.length > panels.length) {
Expand Down
4 changes: 1 addition & 3 deletions elements/pf-tabs/pf-tab-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { state } from 'lit/decorators/state.js';
import { consume } from '@lit/context';

import { getRandomId } from '@patternfly/pfe-core/functions/random.js';

import { type PfTabsContext, context } from './context.js';

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

#internals = this.attachInternals();

@consume({ context, subscribe: true })
@state() private ctx?: PfTabsContext;

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

/*
To make it easy for screen reader users to navigate from a tab
Expand Down
3 changes: 2 additions & 1 deletion elements/pf-tabs/pf-tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ export class PfTabs extends LitElement {
}

#onExpand(event: Event) {
if (event instanceof TabExpandEvent && !event.defaultPrevented) {
if (event instanceof TabExpandEvent &&
!event.defaultPrevented && this.tabs.includes(event.tab)) {
this.select(event.tab);
}
}
Expand Down

0 comments on commit bdb2b39

Please sign in to comment.