feat(button): use DisabledWithTabIndexMixin
This commit is contained in:
parent
e5b174e7b9
commit
732411cab2
1 changed files with 4 additions and 28 deletions
|
|
@ -1,21 +1,15 @@
|
||||||
import { css, html, DelegateMixin, SlotMixin } from '@lion/core';
|
import { css, html, DelegateMixin, SlotMixin, DisabledWithTabIndexMixin } from '@lion/core';
|
||||||
import { LionLitElement } from '@lion/core/src/LionLitElement.js';
|
import { LionLitElement } from '@lion/core/src/LionLitElement.js';
|
||||||
|
|
||||||
export class LionButton extends DelegateMixin(SlotMixin(LionLitElement)) {
|
export class LionButton extends DisabledWithTabIndexMixin(
|
||||||
|
DelegateMixin(SlotMixin(LionLitElement)),
|
||||||
|
) {
|
||||||
static get properties() {
|
static get properties() {
|
||||||
return {
|
return {
|
||||||
disabled: {
|
|
||||||
type: Boolean,
|
|
||||||
reflect: true,
|
|
||||||
},
|
|
||||||
role: {
|
role: {
|
||||||
type: String,
|
type: String,
|
||||||
reflect: true,
|
reflect: true,
|
||||||
},
|
},
|
||||||
tabindex: {
|
|
||||||
type: Number,
|
|
||||||
reflect: true,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,13 +103,6 @@ export class LionButton extends DelegateMixin(SlotMixin(LionLitElement)) {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
_requestUpdate(name, oldValue) {
|
|
||||||
super._requestUpdate(name, oldValue);
|
|
||||||
if (name === 'disabled') {
|
|
||||||
this.__onDisabledChanged(oldValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get delegations() {
|
get delegations() {
|
||||||
return {
|
return {
|
||||||
...super.delegations,
|
...super.delegations,
|
||||||
|
|
@ -140,9 +127,7 @@ export class LionButton extends DelegateMixin(SlotMixin(LionLitElement)) {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.disabled = false;
|
|
||||||
this.role = 'button';
|
this.role = 'button';
|
||||||
this.tabindex = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
|
|
@ -206,13 +191,4 @@ export class LionButton extends DelegateMixin(SlotMixin(LionLitElement)) {
|
||||||
this.shadowRoot.querySelector('.click-area').click();
|
this.shadowRoot.querySelector('.click-area').click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__onDisabledChanged() {
|
|
||||||
if (this.disabled) {
|
|
||||||
this.__originalTabIndex = this.tabindex;
|
|
||||||
this.tabindex = -1;
|
|
||||||
} else {
|
|
||||||
this.tabindex = this.__originalTabIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue