mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 00:06:35 +00:00
Fix custom panel/hass.io navigation (#3034)
* Hass.io: use correct function for firing evenet * Fix navigation from custom panel
This commit is contained in:
parent
c134464f6a
commit
f4319d9b13
@ -87,7 +87,8 @@ class HassioMain extends EventsMixin(NavigateMixin(PolymerElement)) {
|
|||||||
// open and close events. These events are a no-op in newer versions of
|
// open and close events. These events are a no-op in newer versions of
|
||||||
// Home Assistant.
|
// Home Assistant.
|
||||||
this.addEventListener("hass-toggle-menu", () => {
|
this.addEventListener("hass-toggle-menu", () => {
|
||||||
window.parent.customPanel.fire(
|
fireEvent(
|
||||||
|
window.parent.customPanel,
|
||||||
this.hass.dockedSidebar ? "hass-close-menu" : "hass-open-menu"
|
this.hass.dockedSidebar ? "hass-close-menu" : "hass-open-menu"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -130,7 +131,7 @@ class HassioMain extends EventsMixin(NavigateMixin(PolymerElement)) {
|
|||||||
if (route.path === "" && route.prefix === "/hassio") {
|
if (route.path === "" && route.prefix === "/hassio") {
|
||||||
this.navigate("/hassio/dashboard", true);
|
this.navigate("/hassio/dashboard", true);
|
||||||
}
|
}
|
||||||
this.fire("iron-resize");
|
fireEvent(this, "iron-resize");
|
||||||
}
|
}
|
||||||
|
|
||||||
equalsAddon(page) {
|
equalsAddon(page) {
|
||||||
|
@ -72,13 +72,14 @@ function initialize(panel: Panel, properties: {}) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
panelEl!.addEventListener("hass-toggle-menu", forwardEvent);
|
panelEl!.addEventListener("hass-toggle-menu", forwardEvent);
|
||||||
window.addEventListener("location-changed", (ev: any) =>
|
window.addEventListener("location-changed", (ev: any) => {
|
||||||
navigate(
|
if (window.parent.customPanel) {
|
||||||
window.parent.customPanel,
|
window.parent.customPanel.navigate(
|
||||||
window.location.pathname,
|
window.location.pathname,
|
||||||
ev.detail ? ev.detail.replace : false
|
ev.detail ? ev.detail.replace : false
|
||||||
)
|
);
|
||||||
);
|
}
|
||||||
|
});
|
||||||
setProperties({ panel, ...properties });
|
setProperties({ panel, ...properties });
|
||||||
document.body.appendChild(panelEl!);
|
document.body.appendChild(panelEl!);
|
||||||
},
|
},
|
||||||
|
@ -4,6 +4,7 @@ import { createCustomPanelElement } from "../../util/custom-panel/create-custom-
|
|||||||
import { setCustomPanelProperties } from "../../util/custom-panel/set-custom-panel-properties";
|
import { setCustomPanelProperties } from "../../util/custom-panel/set-custom-panel-properties";
|
||||||
import { HomeAssistant, Route, Panel } from "../../types";
|
import { HomeAssistant, Route, Panel } from "../../types";
|
||||||
import { CustomPanelConfig } from "../../data/panel_custom";
|
import { CustomPanelConfig } from "../../data/panel_custom";
|
||||||
|
import { navigate } from "../../common/navigate";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@ -18,6 +19,12 @@ export class HaPanelCustom extends UpdatingElement {
|
|||||||
@property() public panel!: Panel;
|
@property() public panel!: Panel;
|
||||||
private _setProperties?: (props: {}) => void | undefined;
|
private _setProperties?: (props: {}) => void | undefined;
|
||||||
|
|
||||||
|
// Since navigate fires events on `window`, we need to expose this as a function
|
||||||
|
// to allow custom panels to forward their location changes to the main window
|
||||||
|
// instead of their iframe window.
|
||||||
|
public navigate = (path: string, replace?: boolean) =>
|
||||||
|
navigate(this, path, replace);
|
||||||
|
|
||||||
public registerIframe(initialize, setProperties) {
|
public registerIframe(initialize, setProperties) {
|
||||||
initialize(this.panel, {
|
initialize(this.panel, {
|
||||||
hass: this.hass,
|
hass: this.hass,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user