From 92b32458ad2bd4016bb9ba73d8c73bf26561c90e Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 30 Apr 2021 09:57:20 -0700 Subject: [PATCH] Fix grid card size when square (#9056) --- gallery/src/demos/demo-hui-grid-and-stack-card.ts | 9 +++++++++ src/panels/lovelace/cards/hui-grid-card.ts | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gallery/src/demos/demo-hui-grid-and-stack-card.ts b/gallery/src/demos/demo-hui-grid-and-stack-card.ts index e22b5c20d4..4891d6626e 100644 --- a/gallery/src/demos/demo-hui-grid-and-stack-card.ts +++ b/gallery/src/demos/demo-hui-grid-and-stack-card.ts @@ -143,6 +143,15 @@ const CONFIGS = [ entity: light.kitchen_lights `, }, + { + heading: "Size for single card", + config: ` +- type: grid + cards: + - type: entity + entity: light.kitchen_lights + `, + }, { heading: "Vertical Stack", diff --git a/src/panels/lovelace/cards/hui-grid-card.ts b/src/panels/lovelace/cards/hui-grid-card.ts index 256d889a12..b7880b2f6d 100644 --- a/src/panels/lovelace/cards/hui-grid-card.ts +++ b/src/panels/lovelace/cards/hui-grid-card.ts @@ -25,7 +25,9 @@ class HuiGridCard extends HuiStackCard { if (this.square) { const rowHeight = SQUARE_ROW_HEIGHTS_BY_COLUMNS[this.columns] || 1; return ( - (this._cards.length / this.columns) * rowHeight + + (this._cards.length < this.columns + ? rowHeight + : (this._cards.length / this.columns) * rowHeight) + (this._config.title ? 1 : 0) ); }