From 84da3a9de3e53f069ad98d8aef41d05da0b2516b Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 1 Jun 2020 20:45:41 +0200 Subject: [PATCH] Update getCardSize docs (#566) Co-authored-by: Paulus Schoutsen --- docs/frontend/custom-ui/lovelace-custom-card.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/frontend/custom-ui/lovelace-custom-card.md b/docs/frontend/custom-ui/lovelace-custom-card.md index dd46a10a..46e1e1a7 100644 --- a/docs/frontend/custom-ui/lovelace-custom-card.md +++ b/docs/frontend/custom-ui/lovelace-custom-card.md @@ -28,7 +28,7 @@ Home Assistant will set the `hass` property when the state of Home Assistant cha element.hass = hass; ``` -Your card can define a `getCardSize` method that returns the size of your card as a number. A height of 1 is equivalent to 50 pixels. This will help Home Assistant distribute the cards evenly over the columns. A card size of `1` will be assumed if the method is not defined. +Your card can define a `getCardSize` method that returns the size of your card as a number or a promise that will resolve to a number. A height of 1 is equivalent to 50 pixels. This will help Home Assistant distribute the cards evenly over the columns. A card size of `1` will be assumed if the method is not defined. ```js if ('getCardSize' in element) { @@ -38,6 +38,14 @@ if ('getCardSize' in element) { } ``` +Since some element can be lazy loaded, if you want to get the card size of another element, you should first check it is defined. + +```js + return customElements + .whenDefined(element.localName) + .then(() => element.getCardSize()); +``` + Your card can define a `getConfigElement` method that returns a custom element for editing the user configuration. Home Assistant will display this element in the card editor in Lovelace. ## Defining your card