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:
Paulus Schoutsen 2019-03-29 16:40:28 -07:00 committed by GitHub
parent c134464f6a
commit f4319d9b13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 9 deletions

View File

@ -87,7 +87,8 @@ class HassioMain extends EventsMixin(NavigateMixin(PolymerElement)) {
// open and close events. These events are a no-op in newer versions of
// Home Assistant.
this.addEventListener("hass-toggle-menu", () => {
window.parent.customPanel.fire(
fireEvent(
window.parent.customPanel,
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") {
this.navigate("/hassio/dashboard", true);
}
this.fire("iron-resize");
fireEvent(this, "iron-resize");
}
equalsAddon(page) {

View File

@ -72,13 +72,14 @@ function initialize(panel: Panel, properties: {}) {
}
};
panelEl!.addEventListener("hass-toggle-menu", forwardEvent);
window.addEventListener("location-changed", (ev: any) =>
navigate(
window.parent.customPanel,
window.addEventListener("location-changed", (ev: any) => {
if (window.parent.customPanel) {
window.parent.customPanel.navigate(
window.location.pathname,
ev.detail ? ev.detail.replace : false
)
);
}
});
setProperties({ panel, ...properties });
document.body.appendChild(panelEl!);
},

View File

@ -4,6 +4,7 @@ import { createCustomPanelElement } from "../../util/custom-panel/create-custom-
import { setCustomPanelProperties } from "../../util/custom-panel/set-custom-panel-properties";
import { HomeAssistant, Route, Panel } from "../../types";
import { CustomPanelConfig } from "../../data/panel_custom";
import { navigate } from "../../common/navigate";
declare global {
interface Window {
@ -18,6 +19,12 @@ export class HaPanelCustom extends UpdatingElement {
@property() public panel!: Panel;
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) {
initialize(this.panel, {
hass: this.hass,