Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Avoids rewriting Tab label & panel content. Fixes #2530253. #404

Merged
merged 6 commits into from

2 participants

@msweeney

The content setter now compares the panelNode's existing HTML with the new content, and avoids updating if they are a match. Ditto for label.

Additionally, the label parsing now preserves existing markup, and includes it in the label value.

@msweeney msweeney was assigned
@dpobel

This patch fixes the issue for me, thanks :-) (I guess #402 can be closed since this one incorporates the same fix on the duplicated test label)

@msweeney

I've updated this pull request to include the removal of the label text parsing, which prevents the overwriting of existing label content from markup.

@msweeney msweeney merged commit 3485559 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
18 src/tabview/js/tab.js
@@ -107,18 +107,28 @@ Y.Tab = Y.Base.create('tab', Y.Widget, [Y.WidgetChild], {
});
},
+ _defLabelGetter: function() {
+ return this.get('contentBox').getHTML();
+ },
+
_defLabelSetter: function(label) {
- this.get('contentBox').setContent(label);
+ var labelNode = this.get('contentBox');
+ if (labelNode.getHTML() !== label) { // Avoid rewriting existing label.
+ labelNode.setHTML(label);
+ }
return label;
},
_defContentSetter: function(content) {
- this.get('panelNode').setContent(content);
+ var panel = this.get('panelNode');
+ if (panel.getHTML() !== content) { // Avoid rewriting existing content.
+ panel.setHTML(content);
+ }
return content;
},
_defContentGetter: function() {
- return this.get('panelNode').getContent();
+ return this.get('panelNode').getHTML();
},
// find panel by ID mapping from label href
@@ -165,7 +175,7 @@ Y.Tab = Y.Base.create('tab', Y.Widget, [Y.WidgetChild], {
*/
label: {
setter: '_defLabelSetter',
- validator: Lang.isString
+ getter: '_defLabelGetter'
},
/**
View
1  src/tabview/js/tabview.js
@@ -128,7 +128,6 @@ var _queries = Y.TabviewBase._queries,
tabview.add({
boundingBox: node,
contentBox: node.one(DOT + _classNames.tabLabel),
- label: node.one(DOT + _classNames.tabLabel).get('text'),
panelNode: panelNode
});
});
View
84 src/tabview/tests/unit/assets/tabview-test.js
@@ -65,20 +65,102 @@ YUI.add('tabview-test', function(Y) {
},
+ 'should return the label from existing HTML': function() {
+ var tabview = new Y.TabView({
+ srcNode: '#demo-base'
+ });
+
+ tabview.render();
+ Y.Assert.areEqual(Y.one('#demo-base li a').getHTML(), tabview.item(0).get('label'));
+ },
+
+ 'should return the label from dynamic tabview': function() {
+ var tabview = new Y.TabView({
+ children: [{
+ label: 'foo',
+ content: 'foo content'
+ }]
+ });
+
+ tabview.render();
+ Y.Assert.areEqual('foo', tabview.item(0).get('label'));
+ tabview.destroy();
+ },
+
'should set the label': function() {
var tab = new Y.Tab();
tab.set('label', 'new label');
Y.Assert.areEqual('new label', tab.get('label'));
Y.Assert.areEqual('new label', tab.get('contentBox').get('text'));
+ },
+
+ 'should set the label via Y.Node instance': function() {
+ var tab = new Y.Tab(),
+ html = '<em>new label</em>',
+ node = Y.Node.create(html);
+ tab.set('label', node);
+ Y.Assert.areEqual(html, tab.get('label'));
},
- 'should set the label': function() {
+ 'should return the content from existing HTML': function() {
+ var tabview = new Y.TabView({
+ srcNode: '#demo-base'
+ });
+
+ tabview.render();
+ Y.Assert.areEqual('foo content', tabview.item(0).get('content'));
+ },
+
+ 'should return the content from dynamic tabview': function() {
+ var tabview = new Y.TabView({
+ children: [{
+ label: 'foo',
+ content: 'foo content'
+ }]
+ });
+
+ tabview.render();
+ Y.Assert.areEqual('foo content', tabview.item(0).get('content'));
+ tabview.destroy();
+ },
+
+ 'should set the content': function() {
var tab = new Y.Tab();
tab.set('content', 'new content');
Y.Assert.areEqual('new content', tab.get('content'));
Y.Assert.areEqual('new content', tab.get('panelNode').get('text'));
+ },
+
+ 'should set the content via Y.Node instance': function() {
+ var tab = new Y.Tab(),
+ html = '<div>new content</div>',
+ node = Y.Node.create(html);
+
+ tab.set('content', node);
+ Y.Assert.areEqual(html, tab.get('content'));
+ },
+
+ 'should preserve existing content events post render()': function() {
+ var html = '<div><a href="#">new content</a></div>',
+ node = Y.Node.create(html),
+ clicked = false,
+ tabview = new Y.TabView({
+ children: [{
+ label: 'new label',
+ panelNode: node
+ }]
+ });
+
+ node.one('a').on('click', function(e) {
+ e.preventDefault();
+ clicked = true;
+ });
+ tabview.render();
+ node.one('a').simulate('click');
+ Y.Assert.isTrue(clicked);
+ tabview.destroy();
}
}));
}, '@VERSION@' ,{requires:['tabview', 'test']});
Something went wrong with that request. Please try again.