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: Tabs fn should be overrideable #6880

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "tabs fn cleanup",
scomea marked this conversation as resolved.
Show resolved Hide resolved
"packageName": "@microsoft/fast-foundation",
"email": "[email protected]",
"dependentChangeType": "prerelease"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1965,8 +1965,7 @@ export class FASTTabs extends FASTElement {
orientation: TabsOrientation;
// @internal (undocumented)
orientationChanged(): void;
// (undocumented)
protected setTabs: () => void;
protected setTabs(): void;
// @internal (undocumented)
tabpanels: HTMLElement[];
// @internal (undocumented)
Expand Down
18 changes: 9 additions & 9 deletions packages/web-components/fast-foundation/src/tabs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ export const myTabs = Tabs.compose({

#### Fields

| Name | Privacy | Type | Default | Description | Inherited From |
| ------------- | --------- | ----------------- | ------- | ----------------------------- | -------------- |
| `orientation` | public | `TabsOrientation` | | The orientation | |
| `activeid` | public | `string` | | The id of the active tab | |
| `activetab` | public | `HTMLElement` | | A reference to the active tab | |
| `setTabs` | protected | | | | |
| Name | Privacy | Type | Default | Description | Inherited From |
| ------------- | ------- | ----------------- | ------- | ----------------------------- | -------------- |
| `orientation` | public | `TabsOrientation` | | The orientation | |
| `activeid` | public | `string` | | The id of the active tab | |
| `activetab` | public | `HTMLElement` | | A reference to the active tab | |

#### Methods

| Name | Privacy | Description | Parameters | Return | Inherited From |
| -------- | ------- | ------------------------------ | -------------------- | ------ | -------------- |
| `adjust` | public | The adjust method for FASTTabs | `adjustment: number` | `void` | |
| Name | Privacy | Description | Parameters | Return | Inherited From |
| --------- | --------- | --------------------------------------------------------------------------------- | -------------------- | ------ | -------------- |
| `setTabs` | protected | Function that is invoked whenever the selected tab or the tab collection changes. | | `void` | |
| `adjust` | public | The adjust method for FASTTabs | `adjustment: number` | `void` | |

#### Events

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementViewTemplate, html, ref, slotted, when } from "@microsoft/fast-element";
import { ElementViewTemplate, html, slotted } from "@microsoft/fast-element";
import { endSlotTemplate, startSlotTemplate } from "../patterns/index.js";
import type { FASTTabs } from "./tabs.js";
import type { TabsOptions } from "./tabs.options.js";
Expand Down
30 changes: 16 additions & 14 deletions packages/web-components/fast-foundation/src/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class FASTTabs extends FASTElement {
public orientationChanged(): void {
if (this.$fastController.isConnected) {
this.setTabs();
this.setTabPanels();
}
}
/**
Expand All @@ -65,7 +64,6 @@ export class FASTTabs extends FASTElement {
(item: HTMLElement) => item.id === oldValue
);
this.setTabs();
this.setTabPanels();
}
}

Expand All @@ -86,7 +84,6 @@ export class FASTTabs extends FASTElement {
this.tabpanelIds = this.getTabPanelIds();

this.setTabs();
this.setTabPanels();
}
}

Expand All @@ -107,7 +104,6 @@ export class FASTTabs extends FASTElement {
this.tabpanelIds = this.getTabPanelIds();

this.setTabs();
this.setTabPanels();
}
}

Expand Down Expand Up @@ -149,7 +145,12 @@ export class FASTTabs extends FASTElement {
}
}

protected setTabs = (): void => {
/**
* Function that is invoked whenever the selected tab or the tab collection changes.
*
* @protected
scomea marked this conversation as resolved.
Show resolved Hide resolved
*/
protected setTabs(): void {
const gridHorizontalProperty: string = "gridColumn";
const gridVerticalProperty: string = "gridRow";
const gridProperty: string = this.isHorizontal()
Expand Down Expand Up @@ -186,9 +187,10 @@ export class FASTTabs extends FASTElement {
? tab.classList.add("vertical")
: tab.classList.remove("vertical");
});
};
this.setTabPanels();
}

private setTabPanels = (): void => {
private setTabPanels(): void {
this.tabpanels.forEach((tabpanel: HTMLElement, index: number) => {
const tabId: string = this.tabIds[index];
const tabpanelId: string = this.tabpanelIds[index];
Expand All @@ -198,7 +200,7 @@ export class FASTTabs extends FASTElement {
? tabpanel.setAttribute("hidden", "")
: tabpanel.removeAttribute("hidden");
});
};
}

private getTabIds(): Array<string> {
return this.tabs.map((tab: HTMLElement) => {
Expand Down Expand Up @@ -293,7 +295,7 @@ export class FASTTabs extends FASTElement {
}
}

private adjustForward = (e: KeyboardEvent): void => {
private adjustForward(e: KeyboardEvent): void {
const group: HTMLElement[] = this.tabs;
let index: number = 0;

Expand All @@ -314,9 +316,9 @@ export class FASTTabs extends FASTElement {
index += 1;
}
}
};
}

private adjustBackward = (e: KeyboardEvent): void => {
private adjustBackward(e: KeyboardEvent): void {
const group: HTMLElement[] = this.tabs;
let index: number = 0;

Expand All @@ -333,16 +335,16 @@ export class FASTTabs extends FASTElement {
index -= 1;
}
}
};
}

private moveToTabByIndex = (group: HTMLElement[], index: number) => {
private moveToTabByIndex(group: HTMLElement[], index: number) {
const tab: HTMLElement = group[index] as HTMLElement;
this.activetab = tab;
this.prevActiveTabIndex = this.activeTabIndex;
this.activeTabIndex = index;
tab.focus();
this.setComponent();
};
}

private focusTab(): void {
this.tabs[this.activeTabIndex].focus();
Expand Down
Loading