PDA

View Full Version : Removing the last tab



mohaqa
29 Sep 2006, 2:06 PM
I've used TabPanel in one project. Each tab has a close button on it. I close each tab by calling the removeTab method. It works but the last panel does not close. Browsers do not show any error but last tab refuses to close.
When I add another tab then former last tab will close but the same story for the new last one.
Do you have the same thing?

mohaqa
29 Sep 2006, 2:19 PM
I got it. It's beacause of this
if(tab && this.active != tab){ in removeTab function. So this method won't remove the active tab.

jack.slocum
29 Sep 2006, 8:00 PM
If you remove the active tab, the TabPanel could become unstable so there is protection against that. You are welcome to modify the code though and remove that restriction.

Jack

Animal
29 Sep 2006, 11:02 PM
Most tabsets are like that aren't they? Try closing the last tab in your Firefox tabset. It won't go away. Try updating its innerHTML to "", and clearing its title to make it "blank".

mohaqa
30 Sep 2006, 3:16 AM
I solved the problem by changing the active tab. Like firefox if you close the active tab another one will get the focus but here it must be done before removing the current tab.

ojintoad
12 Oct 2006, 7:59 AM
Hey Jack, if it isn't too much, could you speak a little bit about how the TabsPanel becomes unstable?

The most obvious thing is removing the activeTab requires the TabPanel.active to be set to null so the getActiveTab function doesn't return a non existant tab. This is easily fixed at remove time. I overloaded your function like so:


YAHOO.ext.TabPanel.prototype.removeTab =
function(id)
{
var tab = this.items[id];
if(tab){
if(this.active == tab)
this.active = null;
/*...the rest of the original code here... */
}
}


Do the events start becoming an issue or something? I feel like it shouldn't become an issue since no events should be fired if there aren't any tabs anyways.

Animal: I understand what you're saying, but I've used many programs (particularly text editors) that allow you to close the last tab and automatically open a new tab. Just because Firefox, a popular tab implementation, does it one way, doesn't mean that's how all tabs do or should work.

jack.slocum
12 Oct 2006, 8:07 AM
By unstable I mean untested with unknown results. I'm not sure what it would break. You can try it and find out though. :D

If it does work and/or you find something that needs minor correction, please let me know.

ojintoad
12 Oct 2006, 10:33 AM
AHHhhh. Okay, well, I will be sure to let you know the results. So far seems okay but pretty preliminary.

ojintoad
14 Oct 2006, 6:50 AM
I stumbled upon this page while looking at some tech news, just thought it was funny how the discussion of the issue was so lengthy, was coincidentally relevant, and might help application designers understand the pros and cons of closing the last tab from their users perspective.

http://wiki.mozilla.org./Ctrl_W_not_close_app

jack.slocum
14 Oct 2006, 9:57 AM
Nice article, thanks for sharing.