mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-26 06:17:20 +00:00
Simplify enter handling
This commit is contained in:
parent
1a0bf861ee
commit
a27428ebcd
@ -18,13 +18,6 @@ import "./ha-svg-icon";
|
||||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
|
||||
declare global {
|
||||
// for fire event
|
||||
interface HASSDomEvents {
|
||||
activated: undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@customElement("ha-tab")
|
||||
export class HaTab extends LitElement {
|
||||
@property({ type: Boolean, reflect: true }) public active = false;
|
||||
@ -54,11 +47,10 @@ export class HaTab extends LitElement {
|
||||
@touchend=${this.handleRippleDeactivate}
|
||||
@touchcancel=${this.handleRippleDeactivate}
|
||||
@keydown=${this._handleKeyDown}
|
||||
@click=${this._handleClick}
|
||||
>
|
||||
${this.narrow ? html`<slot name="icon"></slot>` : ""}
|
||||
${!this.narrow || this.active
|
||||
? html` <span class="name">${this.name}</span> `
|
||||
? html`<span class="name">${this.name}</span>`
|
||||
: ""}
|
||||
${this._shouldRenderRipple ? html`<mwc-ripple></mwc-ripple>` : ""}
|
||||
</div>
|
||||
@ -72,14 +64,10 @@ export class HaTab extends LitElement {
|
||||
|
||||
private _handleKeyDown(ev: KeyboardEvent): void {
|
||||
if (ev.keyCode === 13) {
|
||||
fireEvent(this, "activated");
|
||||
(ev.target as HTMLElement).click();
|
||||
}
|
||||
}
|
||||
|
||||
private _handleClick(): void {
|
||||
fireEvent(this, "activated");
|
||||
}
|
||||
|
||||
@eventOptions({ passive: true })
|
||||
private handleRippleActivate(evt?: Event) {
|
||||
this._rippleHandlers.startPress(evt);
|
||||
|
@ -74,7 +74,7 @@ class HassTabsSubpage extends LitElement {
|
||||
html`
|
||||
<ha-tab
|
||||
.hass=${this.hass}
|
||||
@activated=${this._tabTapped}
|
||||
@click=${this._tabTapped}
|
||||
.path=${page.path}
|
||||
.active=${page === activeTab}
|
||||
.narrow=${this.narrow}
|
||||
|
Loading…
x
Reference in New Issue
Block a user