Skip to content

Commit 71033b9

Browse files
committed
improve logic around button title and name
1 parent 3dd0c15 commit 71033b9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/components/modebar/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ proto.createButton = function (config) {
122122
button.className = 'modebar-btn';
123123

124124
var title = config.title;
125-
if(title !== null && title !== false && title !== '') {
126-
button.setAttribute('data-title', title || config.name);
127-
}
125+
if(title === undefined) title = config.name;
126+
if(title || title === 0) button.setAttribute('data-title', title);
128127

129128
if(config.attr !== undefined) button.setAttribute('data-attr', config.attr);
130129

test/jasmine/tests/modebar_test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('ModeBar', function() {
101101
expect(checkBtnAttr(modeBar, 0, 'data-title')).toEqual('the title too');
102102
});
103103

104-
it('hides title to when title is set to null or \'\' or false', function() {
104+
it('hides title to when title is falsy but not 0', function() {
105105
var modeBar;
106106

107107
modeBar = createModeBar(getMockGraphInfo(), [[
@@ -118,6 +118,11 @@ describe('ModeBar', function() {
118118
{ name: 'button', title: false, click: noop }
119119
]]);
120120
expect(checkBtnAttr(modeBar, 0, 'data-title')).toBe(null);
121+
122+
modeBar = createModeBar(getMockGraphInfo(), [[
123+
{ name: 'button', title: 0, click: noop }
124+
]]);
125+
expect(checkBtnAttr(modeBar, 0, 'data-title')).toEqual('0');
121126
});
122127
});
123128

0 commit comments

Comments
 (0)