It would be great if tabs had a prop like isClosable: boolean
and corresponding events:
closing: (value) => boolean
or closing: (e:{preventDefault: () => void, value}) => void
closed: (value) => void
The value
refers to the value from controlled tabs.
This feature is great for applications that work with documents.
This cal be implemented leveraging the label
property on Tab
component since it can accept Element
now.
This issue may be resolved, but it would be great to have a working example.
@delineated Actually it would work before Tab started using button
it's not impossible to implement as it is, and since the specs don't talk about it I decided to solve it differently ( put close somewhere else ). What you can do though, is probably rewrite Tab
and have it contain a close button next to it's actual button.
Thank you for the reply. I was hoping to use the onChange event to somehow close the tab, but yeah definitely seems like rewriting Tab
will be the way to go.
Except, my team doesn't want to rewrite Tab
or any part of material-ui. Is there any component within material-ui that allows you to close it (apart from the appbar)?
No there isn't unfortunately. If your team is open to it, it might not be a bad idea to provide the functionality in the Tab
component with a prop to enable/disable it.
I'll pass that along, thank you.
I solved this problem this way:
<Tab component="div" label={
<span>
title
<IconButton onClick={...}>
<Close/>
</IconButton>
</span>
} />
Render tab component as div or other DOM element, so you can put button inside it.
I solved this problem this way:
<Tab component="div" label={ <div> title <IconButton onClick={...}> <Close/> </IconButton> </div> } />
Render tab component as div or other DOM element, so you can put button inside it.
But this does not work for Firefox
I am trying to close a tab and came across this post. I've been stuck and can't solve the problem. I posted it here https://stackoverflow.com/questions/54508683/how-to-target-child-covered-by-parent-overlay-in-material-ui
@chrisdel101
you have to use handler of onChange
function, and read e.target
. If e.target
from CloseIcon - e.preventDefault();
What I mean:
handleTabChange(e, tab) {
if (e.target.tagName !== 'DIV') { // Our label wrapped by div tag, so, if it isn't true - click made to specific buttons or icons and etc...
e.preventDefault();
return;
}
const { onTabChange } = this.props;
onTabChange(tab);
}
Hi @fsdevblog,
preventing div tag doesn't work in IE11.
IE11 doesn't identify/target nested tags, so it stops with first tag that is button so basically you can't switch tabs with this approach.
Most helpful comment
I solved this problem this way:
Render tab component as div or other DOM element, so you can put button inside it.