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

fix(components/tabs): vertical tabs keyboard operable in mobile view #3150

Merged
merged 5 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
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
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 @@ -194,15 +194,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
Loading