mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Close dialog when clicked on link (#16690)
This commit is contained in:
parent
046475e7ac
commit
585db6ab3f
@ -1,4 +1,4 @@
|
|||||||
export const isNavigationClick = (e: MouseEvent) => {
|
export const isNavigationClick = (e: MouseEvent, preventDefault = true) => {
|
||||||
// Taken from polymer/pwa-helpers. BSD-3 licensed
|
// Taken from polymer/pwa-helpers. BSD-3 licensed
|
||||||
if (
|
if (
|
||||||
e.defaultPrevented ||
|
e.defaultPrevented ||
|
||||||
@ -40,6 +40,8 @@ export const isNavigationClick = (e: MouseEvent) => {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
if (preventDefault) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
return href;
|
return href;
|
||||||
};
|
};
|
||||||
|
@ -21,6 +21,7 @@ import type { DataEntryFlowStepForm } from "../../data/data_entry_flow";
|
|||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import type { FlowConfig } from "./show-dialog-data-entry-flow";
|
import type { FlowConfig } from "./show-dialog-data-entry-flow";
|
||||||
import { configFlowContentStyles } from "./styles";
|
import { configFlowContentStyles } from "./styles";
|
||||||
|
import { isNavigationClick } from "../../common/dom/is-navigation-click";
|
||||||
|
|
||||||
@customElement("step-flow-form")
|
@customElement("step-flow-form")
|
||||||
class StepFlowForm extends LitElement {
|
class StepFlowForm extends LitElement {
|
||||||
@ -47,7 +48,7 @@ class StepFlowForm extends LitElement {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<h2>${this.flowConfig.renderShowFormStepHeader(this.hass, this.step)}</h2>
|
<h2>${this.flowConfig.renderShowFormStepHeader(this.hass, this.step)}</h2>
|
||||||
<div class="content">
|
<div class="content" @click=${this._clickHandler}>
|
||||||
${this.flowConfig.renderShowFormStepDescription(this.hass, this.step)}
|
${this.flowConfig.renderShowFormStepDescription(this.hass, this.step)}
|
||||||
${this._errorMsg
|
${this._errorMsg
|
||||||
? html`<ha-alert alert-type="error">${this._errorMsg}</ha-alert>`
|
? html`<ha-alert alert-type="error">${this._errorMsg}</ha-alert>`
|
||||||
@ -92,6 +93,14 @@ class StepFlowForm extends LitElement {
|
|||||||
this.addEventListener("keydown", this._handleKeyDown);
|
this.addEventListener("keydown", this._handleKeyDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _clickHandler(ev: MouseEvent) {
|
||||||
|
if (isNavigationClick(ev, false)) {
|
||||||
|
fireEvent(this, "flow-update", {
|
||||||
|
step: undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _handleKeyDown = (ev: KeyboardEvent) => {
|
private _handleKeyDown = (ev: KeyboardEvent) => {
|
||||||
if (ev.key === "Enter") {
|
if (ev.key === "Enter") {
|
||||||
this._submitStep();
|
this._submitStep();
|
||||||
|
@ -3,6 +3,7 @@ import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { formatDateNumeric } from "../../../common/datetime/format_date";
|
import { formatDateNumeric } from "../../../common/datetime/format_date";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
|
import { isNavigationClick } from "../../../common/dom/is-navigation-click";
|
||||||
import { createCloseHeading } from "../../../components/ha-dialog";
|
import { createCloseHeading } from "../../../components/ha-dialog";
|
||||||
import "../../../components/ha-markdown";
|
import "../../../components/ha-markdown";
|
||||||
import { ignoreRepairsIssue, RepairsIssue } from "../../../data/repairs";
|
import { ignoreRepairsIssue, RepairsIssue } from "../../../data/repairs";
|
||||||
@ -71,6 +72,7 @@ class DialogRepairsIssue extends LitElement {
|
|||||||
<ha-markdown
|
<ha-markdown
|
||||||
allowsvg
|
allowsvg
|
||||||
breaks
|
breaks
|
||||||
|
@click=${this._clickHandler}
|
||||||
.content=${this.hass.localize(
|
.content=${this.hass.localize(
|
||||||
`component.${this._issue.domain}.issues.${
|
`component.${this._issue.domain}.issues.${
|
||||||
this._issue.translation_key || this._issue.issue_id
|
this._issue.translation_key || this._issue.issue_id
|
||||||
@ -110,13 +112,13 @@ class DialogRepairsIssue extends LitElement {
|
|||||||
? this._issue.learn_more_url.replace("homeassistant://", "/")
|
? this._issue.learn_more_url.replace("homeassistant://", "/")
|
||||||
: this._issue.learn_more_url}
|
: this._issue.learn_more_url}
|
||||||
.target=${learnMoreUrlIsHomeAssistant ? "" : "_blank"}
|
.target=${learnMoreUrlIsHomeAssistant ? "" : "_blank"}
|
||||||
|
@click=${learnMoreUrlIsHomeAssistant
|
||||||
|
? this.closeDialog
|
||||||
|
: undefined}
|
||||||
slot="primaryAction"
|
slot="primaryAction"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
>
|
>
|
||||||
<mwc-button
|
<mwc-button
|
||||||
@click=${learnMoreUrlIsHomeAssistant
|
|
||||||
? this.closeDialog
|
|
||||||
: undefined}
|
|
||||||
.label=${this.hass!.localize(
|
.label=${this.hass!.localize(
|
||||||
"ui.panel.config.repairs.dialog.learn"
|
"ui.panel.config.repairs.dialog.learn"
|
||||||
)}
|
)}
|
||||||
@ -140,6 +142,12 @@ class DialogRepairsIssue extends LitElement {
|
|||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _clickHandler(ev: MouseEvent) {
|
||||||
|
if (isNavigationClick(ev, false)) {
|
||||||
|
this.closeDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static styles: CSSResultGroup = [
|
static styles: CSSResultGroup = [
|
||||||
haStyleDialog,
|
haStyleDialog,
|
||||||
css`
|
css`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user