Opened 14 years ago

Closed 13 years ago

#4233 closed bug (fixed)

Required markup structure not documented

Reported by: wichert Owned by:
Priority: minor Milestone: 1.8.5
Component: ui.tabs Version: 1.6rc6
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by Jörn Zaefferer)

Looking at the UI Tabs documentation the required markup for AJAX-based tabs is documented, but there is no hint what the markup for non-AJAX tabs should be like. This can only be extracted by looking at the source for the example at the bottom of the page.

A summary of the required markup and an example should be easy to add, and will help a lot.

Change History (5)

comment:1 Changed 14 years ago by Jörn Zaefferer

Component: [meta] ui.docsui.tabs
Description: modified (diff)
Milestone: TBD1.7.2
Type: enhancementbug

Missing tabs docs.

comment:2 Changed 14 years ago by Jörn Zaefferer

Milestone: 1.7.21.8

comment:3 Changed 13 years ago by sigmasquirrel

I'd like to patch this bug but I'm unsure of what the correct behavior should be.

The issue occurs when using a markup structure that doesn't match the default. If you add a new tab to the end of the list (which is the default behavior if you don't specify an index) specifying the id of a content div that is already in the DOM, it will be inserted after the UL containing the tabs. If you do the same, but specify an index that's not the end of the list, it will be inserted after an existing content element, which may or may not match the behavior of the first case.

Example: http://bryanrsmith.com/tabs.html

Note that when you insert a new tab anywhere other than the end of the list, it's added to #content-container, however, if you insert a new tab at the end of the list, it's appended to the ul's parent, which is not the correct location.

The offending code (from line 468 of jquery.ui.tabs.js)

try to find an existing element before creating a new one var $panel = $('#' + id); if (!$panel.length) {

$panel = $(o.panelTemplate).attr('id', id).data('destroy.tabs', true);

} $panel.addClass('ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide');

if (index >= this.lis.length) {

$li.appendTo(this.list); $panel.appendTo(this.list[0].parentNode); Bad: maybe this.list[0].parentNode is not where we're keeping our content elements

} else {

$li.insertBefore(this.lis[index]); $panel.insertBefore(this.panels[index]); Correct, as long as there is at least 1 existing tab

}

It seems to me that the correct behavior is to not try to re-insert the content div if it already exists in the DOM-- just leave it where it is. An alternative may be to add a parameter for a DOM element for the content div to be appended to. This would also allow the plugin to work consistently when adding a remote tab to an instance of tabs that currently has 0 tabs, in which case we have no way to know where the new tab should be inserted.

This is the only place in the tabs plugin I've found that causes problems when using a non-standard markup structure. Any thoughts on how to handle it?

comment:4 in reply to:  3 Changed 13 years ago by sigmasquirrel

Sorry, this comment was meant for http://dev.jqueryui.com/ticket/4578. Please delete.

comment:5 Changed 13 years ago by Scott González

Milestone: 1.91.8.5
Resolution: fixed
Status: newclosed

This is now documented in the theming section (not sure when the change was made).

Note: See TracTickets for help on using tickets.