Skip to content

Commit

Permalink
fix(components/tabs): vertical tabs keyboard operable in mobile view (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbaud-sky-build-user authored Feb 14, 2025
1 parent 184c9f6 commit ec7abbb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
[ngClass]="{ 'sky-vertical-tabset-hidden': !tabService.tabsVisible() }"
(keydown.arrowdown)="tabGroupsArrowDown(); $event.preventDefault()"
(keydown.arrowup)="tabGroupsArrowUp(); $event.preventDefault()"
(focusin)="tabGroupsFocusIn()"
(focusout)="tabGroupsFocusOut()"
(focusin)="trapFocusInTablist()"
(focusout)="resetTabIndex()"
>
<ng-content />
</div>
Expand All @@ -44,6 +44,7 @@
'sky-vertical-tabset-content-hidden': !tabService.contentVisible()
}"
[@contentEnter]="tabService.animationContentVisibleState"
(focusin)="resetTabIndex()"
>
<div #skySideContent></div>
@if (!tabService.tabsVisible()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,44 @@ describe('Vertical tabset component', () => {
expect(elementHasFocus(tabButtons[0])).toBeTrue();
});

it('should reset tab index when leaving tab list view in mobile view', () => {
mediaQueryController.setBreakpoint('xs');
const fixture = createTestComponent();
const el = fixture.nativeElement;
const tabset = getTabset(fixture);
fixture.detectChanges();

expect(tabset.tabIndex).toBe(0);

// click show tabs button
const showTabsButton = el.querySelector(
'.sky-vertical-tabset-show-tabs-btn',
);
showTabsButton.click();
fixture.detectChanges();

// focus into tablist
const tabsContainer = getTabsContainer(fixture);
SkyAppTestUtility.fireDomEvent(tabsContainer, 'focusin');
fixture.detectChanges();

expect(tabset.tabIndex).toBe(-1);

// click the second tab
const allTabs = el.querySelectorAll('.sky-vertical-tab');
allTabs[1].click();
fixture.detectChanges();

// focus the tabset content container
const verticalTabsetContent = el.querySelector(
'.sky-vertical-tabset-content',
);
SkyAppTestUtility.fireDomEvent(verticalTabsetContent, 'focusin');
fixture.detectChanges();

expect(tabset.tabIndex).toBe(0);
});

it('should set a tab active=false when set to undefined', () => {
const fixture = createTestComponent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ export class SkyVerticalTabsetComponent
this.tabService.focusActiveTab(this.tabGroups);
}

protected tabGroupsFocusIn(): void {
protected trapFocusInTablist(): void {
// This will set the tab index of the the vertical tabset element to -1
// while focus is inside the tab list, allowing Shift+Tab to move
// to the next element above the tab list element. Otherwise focus would
// be trapped on the currently focused tab.
this.tablistHasFocus = true;
}

protected tabGroupsFocusOut(): void {
protected resetTabIndex(): void {
this.tablistHasFocus = false;
}

Expand Down

0 comments on commit ec7abbb

Please sign in to comment.