I am creating dynamics tabs using ReactJS and Material UI, but I wonder how to place a functional closing tab button directly on the tab.
I mean this:
And by the way, is there any way to place the icon side by side with the text?
Accepted answer worked great. To remove all warnings you can add component="span" to IconButton
<Tab key={key} label={
<span>
{tab.Name}
<IconButton size="small" component="span" onClick={() => { alert("Closing this tab..."); }}>
<CloseIcon />
</IconButton>
</span>
}
/>
I tried this and it worked for me:
<Tabs
value={value}
onChange={handleChange}
>
<Tab label={
<span>
{'Active'}
<IconButton size="small" onClick={() => { handle() }}>
<CloseIcon />
</IconButton>
</span>
} />
<Tab label="Disabled" disabled />
<Tab label="Active" />
</Tabs>
iconLabelWrapper: { flexDirection: "row", justifyContent: "flex-start" }to make the icon and text side by side