Skip to content

Commit b66ccf0

Browse files
Garden Care Botclaude
andcommitted
v2.0.5: Fix multi-column grid via ResizeObserver β€” bypasses shadow DOM auto-fill issue
CSS auto-fill/minmax can silently fail inside shadow DOM and HA card wrappers because the browser doesn't propagate the container width to the grid algorithm. Replace with a ResizeObserver that measures the real pixel width and sets an explicit repeat(N, 1fr) column count. Also adds width:100% and min-width:0 to prevent overflow edge cases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 47a02e2 commit b66ccf0

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

β€Žcustom_components/notion_garden_care/frontend/garden-care-strategy.jsβ€Ž

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ class GardenAreaCard extends HTMLElement {
121121
class GardenCareRootCard extends HTMLElement {
122122
constructor() {
123123
super();
124-
this._hass = null;
125-
this._layoutKey = null;
126-
this._childCards = [];
127-
this._buildId = 0;
124+
this._hass = null;
125+
this._layoutKey = null;
126+
this._childCards = [];
127+
this._buildId = 0;
128+
this._resizeObserver = null;
128129
this.attachShadow({ mode: 'open' });
129130
this.shadowRoot.innerHTML = '<style>:host{display:block}</style>';
130131
}
@@ -173,18 +174,21 @@ class GardenCareRootCard extends HTMLElement {
173174

174175
root.innerHTML = `
175176
<style>
176-
:host { display: block; padding: 8px; box-sizing: border-box; }
177+
:host { display: block; width: 100%; padding: 8px; box-sizing: border-box; }
177178
.add-plant-wrapper { margin-bottom: 16px; }
178179
.grid {
179180
display: grid;
181+
/* Fallback β€” ResizeObserver overrides this with an explicit repeat() */
180182
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
181183
gap: 12px;
182184
align-items: start;
185+
width: 100%;
183186
}
184187
.area-column {
185188
display: flex;
186189
flex-direction: column;
187190
gap: 6px;
191+
min-width: 0;
188192
}
189193
.empty-msg {
190194
padding: 20px;
@@ -197,6 +201,12 @@ class GardenCareRootCard extends HTMLElement {
197201
<div class="grid" id="grid"></div>
198202
`;
199203

204+
// Disconnect any previous observer before re-attaching
205+
if (this._resizeObserver) {
206+
this._resizeObserver.disconnect();
207+
this._resizeObserver = null;
208+
}
209+
200210
this._childCards = [];
201211

202212
// ── Add Plant card (full width above the grid) ─────────────────────────
@@ -281,6 +291,19 @@ class GardenCareRootCard extends HTMLElement {
281291
for (const p of noArea) col.appendChild(_mkPlantCard(p.entityId));
282292
grid.appendChild(col);
283293
}
294+
295+
// ── Responsive columns via ResizeObserver ──────────────────────────────
296+
// CSS auto-fill can misreport available width inside shadow DOM / HA card
297+
// wrappers. Measuring the real pixel width and setting an explicit repeat()
298+
// is the most reliable cross-browser solution.
299+
this._resizeObserver = new ResizeObserver(entries => {
300+
for (const entry of entries) {
301+
const w = entry.contentBoxSize?.[0]?.inlineSize ?? entry.contentRect.width;
302+
const cols = Math.max(1, Math.floor(w / 320));
303+
entry.target.style.gridTemplateColumns = `repeat(${cols}, 1fr)`;
304+
}
305+
});
306+
this._resizeObserver.observe(grid);
284307
}
285308
}
286309

β€Žcustom_components/notion_garden_care/manifest.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"notion-client>=2.2.1",
1313
"httpx>=0.27.0"
1414
],
15-
"version": "2.0.4"
15+
"version": "2.0.5"
1616
}

0 commit comments

Comments
Β (0)