components: Add `disable_tab` attribute.

This commit is contained in:
Yashashvi Dave 2019-05-08 12:56:27 +05:30 committed by Tim Abbott
parent ca48b4ec9f
commit 80ceb1a46d
2 changed files with 28 additions and 1 deletions

View File

@ -34,6 +34,11 @@ run_test('basics', () => {
self.class = _.without(tokens, c).join(' '); self.class = _.without(tokens, c).join(' ');
}; };
self.hasClass = function (c) {
var tokens = self.class.trim().split(/ +/);
return tokens.includes(c);
};
self.data = function (name) { self.data = function (name) {
assert.equal(name, 'tab-id'); assert.equal(name, 'tab-id');
return i; return i;
@ -197,4 +202,14 @@ run_test('basics', () => {
click_f.call(tabs[1]); click_f.call(tabs[1]);
assert.equal(widget.value(), 'translated: Message formatting'); assert.equal(widget.value(), 'translated: Message formatting');
callback_args = undefined;
widget.disable_tab("search-operators");
assert.equal(tabs[2].hasClass('disabled'), true);
assert.equal(tabs[2].class, "last disabled");
widget.goto('keyboard-shortcuts');
assert.equal(focused_tab, 0);
widget.goto("search-operators");
assert.equal(focused_tab, 0);
}); });

View File

@ -42,9 +42,12 @@ exports.toggle = function (opts) {
}; };
function select_tab(idx) { function select_tab(idx) {
var elem = meta.$ind_tab.eq(idx);
if (elem.hasClass('disabled')) {
return;
}
meta.$ind_tab.removeClass("selected"); meta.$ind_tab.removeClass("selected");
var elem = meta.$ind_tab.eq(idx);
elem.addClass("selected"); elem.addClass("selected");
meta.idx = idx; meta.idx = idx;
@ -98,6 +101,15 @@ exports.toggle = function (opts) {
maybe_go_left: maybe_go_left, maybe_go_left: maybe_go_left,
maybe_go_right: maybe_go_right, maybe_go_right: maybe_go_right,
disable_tab: function (name) {
var value = _.find(opts.values, function (o) {
return o.key === name;
});
var idx = opts.values.indexOf(value);
meta.$ind_tab.eq(idx).addClass('disabled');
},
value: function () { value: function () {
if (meta.idx >= 0) { if (meta.idx >= 0) {
return opts.values[meta.idx].label; return opts.values[meta.idx].label;