Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3208040
fix(accordion): adding RTI to accordion, adding headers, removing old…
brianferry May 4, 2023
e91538d
fix(accordion): adding RTI index after initialized
brianferry May 8, 2023
b0dd478
Merge branch 'main' of github.com:patternfly/patternfly-elements into…
brianferry May 8, 2023
c203b47
fix(accordion): removing older code for rti fix
brianferry May 8, 2023
ec290df
chore: adding changeset
brianferry May 8, 2023
370b80a
Merge branch `fix/accordion-rovingtabindex-controller` into `fix/acco…
May 8, 2023
6f492cd
fix(core): ensured rti arrow key listeners only apply to focusable items
May 8, 2023
5a78363
fix(core): ensured rti error key listeners only apply to focusable items
May 8, 2023
f0ab662
Merge branch 'fix/accordion-rovingtabindex-controller' of github.com:…
May 8, 2023
c8ddafb
fix(accordion): adding init items on mutation observer for RTI, remov…
brianferry May 9, 2023
f38d2a7
fix(tabs): reverting code change made locally
brianferry May 9, 2023
7572482
Merge branch 'main' of github.com:patternfly/patternfly-elements into…
brianferry May 11, 2023
93fce18
docs: update changeset
bennypowers May 17, 2023
23ddd2d
perf: defer computing composedPath()
bennypowers May 17, 2023
a6ab38d
test(accordion): adding test cases for rti navigation in nested, mult…
brianferry May 19, 2023
b339a94
fix(accordion): activeHeader a private accessor
brianferry May 22, 2023
bc9d830
Merge branch 'main' into fix/accordion-rovingtabindex-controller
bennypowers May 28, 2023
130cb5c
docs: update .changeset/empty-trainers-tickle.md
bennypowers May 28, 2023
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/brown-shirts-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@patternfly/pfe-core": patch
---

**roving-tabindex-controller**: fixes arrow keydown event listeners
4 changes: 4 additions & 0 deletions .changeset/empty-trainers-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@patternfly/elements": patch
---
`<pf-accordion>`: fixed keyboard navigation inside of nested accordions
8 changes: 6 additions & 2 deletions core/pfe-core/controllers/roving-tabindex-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ export class RovingTabindexController<
* handles keyboard navigation
*/
#onKeydown = (event: KeyboardEvent) => {
if (event.ctrlKey || event.altKey || event.metaKey || this.#focusableItems.length < 1) {
if (event.ctrlKey ||
event.altKey ||
event.metaKey ||
!this.#focusableItems.length ||
!event.composedPath().some(x =>
this.#focusableItems.includes(x as ItemType))) {
return;
}

const item = this.activeItem;
let shouldPreventDefault = false;
const horizontalOnly =
Expand Down
20 changes: 19 additions & 1 deletion elements/pf-accordion/BaseAccordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { Logger } from '@patternfly/pfe-core/controllers/logger.js';
import { AccordionHeaderChangeEvent, BaseAccordionHeader } from './BaseAccordionHeader.js';
import { BaseAccordionPanel } from './BaseAccordionPanel.js';

import { RovingTabindexController } from '@patternfly/pfe-core/controllers/roving-tabindex-controller.js';

import style from './BaseAccordion.css';

const CSS_TIMING_UNITS_RE = /^[0-9.]+(?<unit>[a-zA-Z]+)/g;
Expand Down Expand Up @@ -48,6 +50,8 @@ export abstract class BaseAccordion extends LitElement {
return target instanceof BaseAccordionPanel;
}

#headerIndex = new RovingTabindexController<BaseAccordionHeader>(this);

/**
* Sets and reflects the currently expanded accordion 0-based indexes.
* Use commas to separate multiple indexes.
Expand Down Expand Up @@ -78,6 +82,12 @@ export abstract class BaseAccordion extends LitElement {
return this.#allPanels();
}

get #activeHeader() {
const { headers } = this;
const index = headers.findIndex(header => header.matches(':focus,:focus-within'));
return headers.at(index);
}

protected expandedSets = new Set<number>();

#logger = new Logger(this);
Expand All @@ -103,7 +113,6 @@ export abstract class BaseAccordion extends LitElement {
connectedCallback() {
super.connectedCallback();
this.addEventListener('change', this.#onChange as EventListener);
this.addEventListener('keydown', this.#onKeydown);
this.#mo.observe(this, { childList: true });
this.#init();
}
Expand Down Expand Up @@ -135,9 +144,18 @@ export abstract class BaseAccordion extends LitElement {
*/
async #init() {
this.#initialized ||= !!await this.updateComplete;
this.#headerIndex.initItems(this.headers);
// Event listener to the accordion header after the accordion has been initialized to add the roving tabindex
this.addEventListener('focusin', this.#updateActiveHeader as EventListener);
this.updateAccessibility();
}

#updateActiveHeader() {
if (this.#activeHeader) {
this.#headerIndex.updateActiveItem(this.#activeHeader);
}
}

#panelForHeader(header: BaseAccordionHeader) {
const next = header.nextElementSibling;
if (!BaseAccordion.isPanel(next)) {
Expand Down
Loading