There is a Tab component with multiple tabs, it is needed that when one of those tabs is clicked to open a link in a new tab in browser.
This is the code:
import { LocationDescriptor } from 'history';
import React, { AnchorHTMLAttributes } from 'react';
import { NavLink } from 'react-router-dom';
export interface ITabLinkItem extends AnchorHTMLAttributes<HTMLAnchorElement> {
link: LocationDescriptor;
name: string;
disabled?: boolean;
}
export interface TabLinkProps {
tabs: Array<ITabLinkItem>;
}
export function TabsLink({ tabs }: TabLinkProps) {
const preventClick = (event: React.MouseEvent, disabled = false) => {
disabled && event.preventDefault();
};
const clickTab = (event: React.MouseEvent, tab: ITabLinkItem) => {
preventClick(event, tab.disabled);
const { link } = tab;
if (link === '/test') {
// OPEN IN NEW TAB
}
};
return (
<div>
{tabs.map((tab: ITabLinkItem, index: number) =>
<NavLink
key={index}
to={tab.link}
onClick={(event: React.MouseEvent) => clickTab(event, tab)}
>
{tab.name}
</NavLink>
)}
</div>
);
}
export default TabsLink;
Is it a way to trigger that tab opening when the condition is true?