mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-28 13:21:42 +00:00
* [accessibility-2280341]:[Keyboard Navigation - Azure Cosmos DB - Graph]: Keyboard focus order is not logical after selecting any tab control. * updated module structure. --------- Co-authored-by: Satyapriya Bai <v-satybai@microsoft.com>
72 lines
2.0 KiB
TypeScript
72 lines
2.0 KiB
TypeScript
import * as React from "react";
|
|
import { Pivot, PivotItem } from "@fluentui/react";
|
|
import "./TabComponent.less";
|
|
|
|
export interface TabContent {
|
|
render: () => JSX.Element;
|
|
className?: string;
|
|
}
|
|
|
|
export interface Tab {
|
|
title: string;
|
|
content: TabContent;
|
|
isVisible: () => boolean;
|
|
}
|
|
|
|
interface TabComponentProps {
|
|
tabs: Tab[];
|
|
currentTabIndex: number;
|
|
onTabIndexChange: (newIndex: number) => void;
|
|
hideHeader: boolean;
|
|
}
|
|
|
|
/**
|
|
* We assume there's at least one tab
|
|
*/
|
|
export class TabComponent extends React.Component<TabComponentProps> {
|
|
public constructor(props: TabComponentProps) {
|
|
super(props);
|
|
|
|
if (this.props.tabs.length < 1) {
|
|
const msg = "TabComponent must have at least one tab";
|
|
console.error(msg);
|
|
throw new Error(msg);
|
|
}
|
|
}
|
|
|
|
private setActiveTab(index: number): void {
|
|
this.props.onTabIndexChange(index);
|
|
}
|
|
|
|
public render(): JSX.Element {
|
|
const { tabs, currentTabIndex, hideHeader } = this.props;
|
|
const currentTabContent = tabs[currentTabIndex].content;
|
|
let className = "tabComponentContent";
|
|
if (currentTabContent.className) {
|
|
className += ` ${currentTabContent.className}`;
|
|
}
|
|
return (
|
|
<div className="tabComponentContainer">
|
|
<div className="tabs tabSwitch">
|
|
{!hideHeader && (
|
|
<Pivot
|
|
aria-label="Tab navigation"
|
|
selectedKey={currentTabIndex.toString()}
|
|
linkSize="normal"
|
|
onLinkClick={(item) => this.setActiveTab(parseInt(item?.props.itemKey || ""))}
|
|
>
|
|
{tabs.map((tab: Tab, index: number) => {
|
|
if (!tab.isVisible()) {
|
|
return null; // Skip rendering invisible tabs
|
|
}
|
|
return <PivotItem key={index} headerText={tab.title} itemKey={index.toString()} />;
|
|
})}
|
|
</Pivot>
|
|
)}
|
|
</div>
|
|
<div className={className}>{tabs[currentTabIndex].content.render()}</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|