import * as React from 'react'; import Box from '@mui/material/Box'; import Tabs from '@mui/material/Tabs'; import Tab from '@mui/material/Tab'; function samePageLinkNavigation( event: React.MouseEvent, ) { if ( event.defaultPrevented || event.button !== 0 || // ignore everything but left-click event.metaKey || event.ctrlKey || event.altKey || event.shiftKey ) { return false; } return true; } interface LinkTabProps { label?: string; href?: string; selected?: boolean; } function LinkTab(props: LinkTabProps) { return ( ) => { // Routing libraries handle this, you can remove the onClick handle when using them. if (samePageLinkNavigation(event)) { event.preventDefault(); } }} aria-current={props.selected && 'page'} {...props} /> ); } export default function NavTabs() { const [value, setValue] = React.useState(0); const handleChange = (event: React.SyntheticEvent, newValue: number) => { // event.type can be equal to focus with selectionFollowsFocus. if ( event.type !== 'click' || (event.type === 'click' && samePageLinkNavigation( event as React.MouseEvent, )) ) { setValue(newValue); } }; return ( ); }