Skip to content

Commit

Permalink
[cherry-pick] two tab navigation fixes (#6793)
Browse files Browse the repository at this point in the history
* [cherry-pick] fix(tabs): home and end navigation (#6298)

* fix(tabs): home and end navigation

* Change files

* Update packages/web-components/fast-foundation/src/tabs/stories/tabs.stories.ts

Co-authored-by: John Kreitlow <863023+radium-v@users.noreply.github.com>

* apply pr comments

* Revert "apply pr comments"

This reverts commit 09a6523.

* apply pr comment

* Update change/@microsoft-fast-foundation-dc08ca7b-be41-4f42-a66c-c0874376b4a2.json

Co-authored-by: John Kreitlow <863023+radium-v@users.noreply.github.com>

Co-authored-by: John Kreitlow <863023+radium-v@users.noreply.github.com>
Co-authored-by: Chris Holt <chhol@microsoft.com>

* [cherry-pick] Prevent keyboard navigation to hidden tab (#6789)

* Prevent keyboard navigation to hidden tab

* Change files

* Fix issue with Home/End

* use hasAttribute

* Update change/@microsoft-fast-foundation-7d8d0430-523b-473a-af77-e2bcf0bc6e38.json

* Update change/@microsoft-fast-foundation-7d8d0430-523b-473a-af77-e2bcf0bc6e38.json

---------

Co-authored-by: Nicholas Rice <3213292+nicholasrice@users.noreply.github.com>

* Update change files

---------

Co-authored-by: Mathieu Lavoie <44816587+m4thieulavoie@users.noreply.github.com>
Co-authored-by: John Kreitlow <863023+radium-v@users.noreply.github.com>
Co-authored-by: Chris Holt <chhol@microsoft.com>
Co-authored-by: Nicholas Rice <3213292+nicholasrice@users.noreply.github.com>
  • Loading branch information
5 people authored Aug 10, 2023
1 parent 8c80dfc commit b8b4b20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Prevent keyboard navigation to hidden or disabled tabs",
"packageName": "@microsoft/fast-foundation",
"email": "7282195+m-akinc@users.noreply.github.com",
"dependentChangeType": "patch"
}
25 changes: 19 additions & 6 deletions packages/web-components/fast-foundation/src/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
keyArrowUp,
keyEnd,
keyHome,
limit,
uniqueId,
wrapInBounds,
} from "@microsoft/fast-web-utilities";
Expand Down Expand Up @@ -183,8 +184,12 @@ export class Tabs extends FoundationElement {
return el.getAttribute("aria-disabled") === "true";
};

private isHiddenElement = (el: Element): el is HTMLElement => {
return el.hasAttribute("hidden");
};

private isFocusableElement = (el: Element): el is HTMLElement => {
return !this.isDisabledElement(el);
return !this.isDisabledElement(el) && !this.isHiddenElement(el);
};

private getActiveIndex(): number {
Expand Down Expand Up @@ -365,13 +370,21 @@ export class Tabs extends FoundationElement {
* This method allows the active index to be adjusted by numerical increments
*/
public adjust(adjustment: number): void {
this.prevActiveTabIndex = this.activeTabIndex;
this.activeTabIndex = wrapInBounds(
const focusableTabs = this.tabs.filter(t => this.isFocusableElement(t));
const currentActiveTabIndex = focusableTabs.indexOf(this.activetab);

const nextTabIndex = limit(
0,
this.tabs.length - 1,
this.activeTabIndex + adjustment
focusableTabs.length - 1,
currentActiveTabIndex + adjustment
);
this.setComponent();

// the index of the next focusable tab within the context of all available tabs
const nextIndex = this.tabs.indexOf(focusableTabs[nextTabIndex]);

if (nextIndex > -1) {
this.moveToTabByIndex(this.tabs, nextIndex);
}
}

private adjustForward = (e: KeyboardEvent): void => {
Expand Down

0 comments on commit b8b4b20

Please sign in to comment.