Skip to content

Commit

Permalink
deprecate left/right arrow key usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeyber committed Oct 16, 2024
1 parent 4318ab5 commit bd2552f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[attr.aria-labelledby]="tab.id ?? null"
[attr.id]="tab.id ? 'section-' + tab.id : null"
class="active"
[cxFocus]="{ focusOnEscape: true }"
[cxFocus]="{ focusOnEscape: !tab.disableBorderFocus }"
>
<ng-container [ngTemplateOutlet]="tab.content"></ng-container>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -237,32 +237,8 @@ describe('FacetComponent', () => {
);
});

it('should open facet on ArrowRight', () => {
Object.defineProperty(component, 'isExpanded', {
writable: true,
value: false,
});

component.onArrowRight(mockArrowRightEvent);

expect(component.toggleGroup).toHaveBeenCalled();
});

it('should close facet on ArrowLeft and facetHeader regains focus', () => {
spyOn(component.facetHeader.nativeElement, 'focus');

component.onArrowLeft(mockArrowLeftEvent);

expect(component.toggleGroup).toHaveBeenCalled();
expect(component.facetHeader.nativeElement.focus).toHaveBeenCalled();
});

it('should focus the first option on ArrowDown if triggered on facetHeader, else focus on next option', () => {
it('should focus the next option', () => {
const currentIndex = 0;

component.onArrowDown(mockArrowDownOnHeaderEvent, currentIndex);
expect(component.values.first.nativeElement.focus).toHaveBeenCalled();

component.onArrowDown(mockArrowDownOnOptionEvent, currentIndex);
expect(
component.values.get(currentIndex + 1)?.nativeElement.focus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export class FacetComponent implements AfterViewInit {
}

/**
* @deprecated: Header will no longer be used in favour of TabComponent headers.
*
* Handles clicking the heading of the facet group, which means toggling
* the visibility of the group (collapse / expand) and optionally focusing
* the group.
Expand Down Expand Up @@ -136,6 +138,8 @@ export class FacetComponent implements AfterViewInit {
const targetIndex = this.values.toArray().findIndex((el) => {
return el.nativeElement === event.target;
});
// TODO: Left and Right arrow keys are disabled when setting a11yTabComponent.
// We can remove these in the future.
switch (event.key) {
case 'ArrowLeft':
this.onArrowLeft(event);
Expand All @@ -152,6 +156,9 @@ export class FacetComponent implements AfterViewInit {
}
}

/**
* @deprecated: Arrow key functions will be removed in favour of using the TabComponent.
*/
onArrowRight(event: Event): void {
if (this.featureConfigService?.isEnabled('a11yTabComponent')) {
return;
Expand All @@ -162,14 +169,12 @@ export class FacetComponent implements AfterViewInit {
}
}

/**
* @deprecated: Arrow key functions will be removed in favour of using the TabComponent.
*/
onArrowLeft(event: Event): void {
// Navigate to tab buttons when tab component enabled
if (this.featureConfigService?.isEnabled('a11yTabComponent')) {
event.preventDefault();
const parent: any =
this.values.get(0)?.nativeElement.parentElement?.parentElement
?.parentElement?.parentElement?.previousElementSibling;
parent?.click();
return;
}

Expand Down

0 comments on commit bd2552f

Please sign in to comment.