Fixes and modifications

This commit is contained in:
pk
2023-07-27 16:40:07 +02:00
parent b30c9b4e2d
commit 12a8cbeba8
3 changed files with 35 additions and 8 deletions

View File

@ -4,7 +4,7 @@ Copyright (c) 2022 trading_peter
This program is available under Apache License Version 2.0
*/
export const ControlState = function(superClass) {
export const ControlState = function (superClass) {
return class extends superClass {
static get properties() {
return {
@ -20,10 +20,21 @@ export const ControlState = function(superClass) {
firstUpdated() {
super.firstUpdated();
if (!this.hasAttribute('tabindex')) {
this.setAttribute('tabindex', '0');
}
this.addEventListener('focus', this._boundFocus, true);
this.addEventListener('blur', this._boundFocus, true);
}
shouldUpdate(changes) {
if (changes.has('disabled')) {
this._disabledChanged(this.disabled);
}
return super.shouldUpdate(changes);
}
_focusHandler(e) {
this.focused = e.type === 'focus';
}
@ -38,7 +49,7 @@ export const ControlState = function(superClass) {
// leaving `-1` hides shadow root children from the tab order.
this._prevTabIndex = this.getAttribute('tabindex');
this.focused = false;
this.tabIndex = -1;
this.setAttribute('tabIndex', '-1');
this.blur();
} else if (this._prevTabIndex !== undefined) {
if (this._prevTabIndex === null) {
@ -49,4 +60,4 @@ export const ControlState = function(superClass) {
}
}
};
}
}