Refactoring focus for checkbox/radiobox

This commit is contained in:
Julia Radzhabova 2021-04-14 19:37:20 +03:00
parent cbab777f48
commit 703f0f7532
3 changed files with 23 additions and 11 deletions

View file

@ -146,11 +146,9 @@ define([
if (disabled !== this.disabled) { if (disabled !== this.disabled) {
this.$label.toggleClass('disabled', disabled); this.$label.toggleClass('disabled', disabled);
(disabled) ? this.$chk.attr({disabled: disabled}) : this.$chk.removeAttr('disabled'); (disabled) ? this.$chk.attr({disabled: disabled}) : this.$chk.removeAttr('disabled');
if (disabled) { if (this.tabindex!==undefined) {
this.tabindex = this.$label.attr('tabindex'); disabled && (this.tabindex = this.$label.attr('tabindex'));
this.$label.attr('tabindex', -1); this.$label.attr('tabindex', disabled ? "-1" : this.tabindex);
} else if (this.tabindex) {
this.$label.attr('tabindex', this.tabindex);
} }
} }
@ -216,6 +214,14 @@ define([
focus: function() { focus: function() {
this.$label && this.$label.focus(); this.$label && this.$label.focus();
},
setTabIndex: function(tabindex) {
if (!this.rendered)
return;
this.tabindex = tabindex.toString();
!this.disabled && this.$label.attr('tabindex', this.tabindex);
} }
}); });
}); });

View file

@ -75,7 +75,7 @@ Common.UI.FocusManager = new(function() {
item.selector = '.form-control'; item.selector = '.form-control';
} }
item.el = (item.cmp.$el || $(item.cmp.el || item.cmp)).find(item.selector).addBack().filter(item.selector); item.el = (item.cmp.$el || $(item.cmp.el || item.cmp)).find(item.selector).addBack().filter(item.selector);
item.el && item.el.attr && item.el.attr('tabindex', _tabindex.toString()); item.el && item.el.attr && (item.cmp.setTabIndex ? item.cmp.setTabIndex(_tabindex) : item.el.attr('tabindex', _tabindex.toString()));
arr.push(item); arr.push(item);
} }
}); });

View file

@ -120,11 +120,9 @@ define([
this.$label.toggleClass('disabled', disabled); this.$label.toggleClass('disabled', disabled);
this.$radio.toggleClass('disabled', disabled); this.$radio.toggleClass('disabled', disabled);
(disabled) ? this.$radio.attr({disabled: disabled}) : this.$radio.removeAttr('disabled'); (disabled) ? this.$radio.attr({disabled: disabled}) : this.$radio.removeAttr('disabled');
if (disabled) { if (this.tabindex!==undefined) {
this.tabindex = this.$label.attr('tabindex'); disabled && (this.tabindex = this.$label.attr('tabindex'));
this.$label.attr('tabindex', -1); this.$label.attr('tabindex', disabled ? "-1" : this.tabindex);
} else if (this.tabindex) {
this.$label.attr('tabindex', this.tabindex);
} }
} }
@ -176,6 +174,14 @@ define([
focus: function() { focus: function() {
this.$label && this.$label.focus(); this.$label && this.$label.focus();
},
setTabIndex: function(tabindex) {
if (!this.rendered)
return;
this.tabindex = tabindex.toString();
!this.disabled && this.$label.attr('tabindex', this.tabindex);
} }
}); });
}); });