It appears that clicking on a disabled element, as well as its children, is not possible; one way to work around this issue is by disregarding the target tab when setting an active tab.
By utilizing the newValue
parameter in the handleChange
function, we can determine if the event originated from the tab we wish to remain inactive upon being clicked.
const handleChange = (event, newValue) => {
if (newValue === "4") return; // value is 4? ignore
setValue(newValue);
};
Now, when clicking on the specified tab below, it will not be selected. Additionally, we can prevent the ripple effect from displaying when clicked by passing true
to the disableRipple
prop.
<Tab
value="4"
disableRipple={true}
component="span"
label={
<Switch
checked={isSwitchOn}
onChange={(e) => setSwitch(!isSwitchOn)}
name="toggleType"
/>
}
/>
https://codesandbox.io/s/epic-smoke-viejy?fontsize=14&hidenavigation=1&theme=dark