Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #15830 - Accessibility: Tree inside an Accordion (arrow navigat… #15831

Merged
merged 2 commits into from
Jun 13, 2024
Merged
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
25 changes: 6 additions & 19 deletions src/app/components/accordion/accordion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,7 @@ export class AccordionTab implements AfterContentInit, OnDestroy {

accordion: Accordion;

constructor(
@Inject(forwardRef(() => Accordion)) accordion: Accordion,
public el: ElementRef,
public changeDetector: ChangeDetectorRef
) {
constructor(@Inject(forwardRef(() => Accordion)) accordion: Accordion, public el: ElementRef, public changeDetector: ChangeDetectorRef) {
this.accordion = accordion as Accordion;
this.id = UniqueComponentId();
}
Expand Down Expand Up @@ -441,10 +437,7 @@ export class Accordion implements BlockableUI, AfterContentInit, OnDestroy {

public tabs: AccordionTab[] = [];

constructor(
public el: ElementRef,
public changeDetector: ChangeDetectorRef
) {}
constructor(public el: ElementRef, public changeDetector: ChangeDetectorRef) {}

@HostListener('keydown', ['$event'])
onKeydown(event) {
Expand All @@ -471,18 +464,12 @@ export class Accordion implements BlockableUI, AfterContentInit, OnDestroy {
}
}

isInput(event): boolean {
const { tagName } = event.target;
return tagName?.toLowerCase() === 'input';
}

isTextArea(event): boolean {
const { tagName } = event.target;
return tagName?.toLowerCase() === 'textarea';
focusedElementIsAccordionHeader() {
return document.activeElement.tagName.toLowerCase() === 'a' && document.activeElement.classList.contains('p-accordion-header-link');
}

onTabArrowDownKey(event) {
if (!this.isInput(event) && !this.isTextArea(event)) {
if (this.focusedElementIsAccordionHeader()) {
const nextHeaderAction = this.findNextHeaderAction(event.target.parentElement.parentElement.parentElement);
nextHeaderAction ? this.changeFocusedTab(nextHeaderAction) : this.onTabHomeKey(event);

Expand All @@ -491,7 +478,7 @@ export class Accordion implements BlockableUI, AfterContentInit, OnDestroy {
}

onTabArrowUpKey(event) {
if (!this.isInput(event) && !this.isTextArea(event)) {
if (this.focusedElementIsAccordionHeader()) {
const prevHeaderAction = this.findPrevHeaderAction(event.target.parentElement.parentElement.parentElement);
prevHeaderAction ? this.changeFocusedTab(prevHeaderAction) : this.onTabEndKey(event);

Expand Down
Loading