Skip to content

Commit b129cfc

Browse files
committed
Merge branch 'fix/bmi-badge-colors' into main
2 parents 8a0ffa7 + aee4138 commit b129cfc

2 files changed

Lines changed: 33 additions & 33 deletions

File tree

src/pages/bmi.astro

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ const sharedValues = {
139139
<div class="scale-segment obese">
140140
<span>Obese</span>
141141
</div>
142+
<!-- scale indicator removed - controlled indicator caused layout issues -->
142143
</div>
143-
<div class="scale-indicator" id="scale-indicator"></div>
144144
</div>
145145

146146
<ResultCard title="Understanding Your BMI">
@@ -224,8 +224,10 @@ const sharedValues = {
224224
display: flex;
225225
height: 60px;
226226
border-radius: var(--border-radius);
227-
overflow: hidden;
227+
/* allow the pointer triangle to render outside the bar */
228+
overflow: visible;
228229
margin-bottom: 1.5rem;
230+
position: relative;
229231
}
230232

231233
.scale-segment {
@@ -253,17 +255,9 @@ const sharedValues = {
253255
background: var(--color-danger);
254256
}
255257

256-
.scale-indicator {
257-
position: absolute;
258-
bottom: 1rem;
259-
width: 0;
260-
height: 0;
261-
border-left: 10px solid transparent;
262-
border-right: 10px solid transparent;
263-
border-bottom: 12px solid var(--color-text);
264-
transform: translateX(-50%);
265-
transition: left 0.3s ease;
266-
}
258+
/* scale indicator removed - kept for historical context
259+
.scale-indicator { ... }
260+
*/
267261

268262
.bmi-info {
269263
background: var(--color-background);
@@ -385,6 +379,7 @@ const sharedValues = {
385379
private bmiNumber: HTMLElement | null = null;
386380
private bmiCategory: HTMLElement | null = null;
387381
private bmiExplanation: HTMLElement | null = null;
382+
// scaleIndicator removed from DOM; keep property for compatibility
388383
private scaleIndicator: HTMLElement | null = null;
389384
private asianScale: HTMLInputElement | null = null;
390385

@@ -401,7 +396,7 @@ const sharedValues = {
401396
this.bmiNumber = document.getElementById("bmi-number");
402397
this.bmiCategory = document.getElementById("bmi-category");
403398
this.bmiExplanation = document.getElementById("bmi-explanation");
404-
this.scaleIndicator = document.getElementById("scale-indicator");
399+
// scaleIndicator intentionally not queried - removed from markup
405400
this.asianScale = document.getElementById("asian-scale") as HTMLInputElement;
406401
}
407402

@@ -611,8 +606,9 @@ const sharedValues = {
611606
this.bmiCategory.textContent = categoryData.name;
612607
// Update the CSS class for the category badge
613608
this.bmiCategory.className = `category-badge category-badge--md category-badge--solid ${category}`;
609+
// Set the badge color to match the chart legend colors exactly
610+
this.bmiCategory.style.setProperty("--badge-color", categoryData.color);
614611
}
615-
616612
if (this.bmiExplanation) {
617613
this.bmiExplanation.textContent = categoryData.explanation;
618614
}
@@ -669,24 +665,8 @@ const sharedValues = {
669665
}
670666

671667
private updateScaleIndicator(bmi: number, useAsianScale: boolean): void {
672-
if (!this.scaleIndicator) return;
673-
674-
let position;
675-
if (useAsianScale) {
676-
// Asian scale thresholds
677-
if (bmi < 18.5) position = (bmi / 18.5) * 25;
678-
else if (bmi < 23) position = 25 + ((bmi - 18.5) / 4.5) * 25;
679-
else if (bmi < 27.5) position = 50 + ((bmi - 23) / 4.5) * 25;
680-
else position = 75 + Math.min(((bmi - 27.5) / 7.5) * 25, 25);
681-
} else {
682-
// Standard scale thresholds
683-
if (bmi < 18.5) position = (bmi / 18.5) * 25;
684-
else if (bmi < 25) position = 25 + ((bmi - 18.5) / 6.5) * 25;
685-
else if (bmi < 30) position = 50 + ((bmi - 25) / 5) * 25;
686-
else position = 75 + Math.min(((bmi - 30) / 10) * 25, 25);
687-
}
688-
689-
this.scaleIndicator.style.left = `${Math.min(position, 100)}%`;
668+
// scale-indicator removed - no-op
669+
return;
690670
}
691671
}
692672

tests/calculators/bmi.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,24 @@ test.describe("BMI Calculator", () => {
105105
// Check that the scale indicator exists
106106
await expect(page.locator("#scale-indicator")).toBeVisible();
107107
});
108+
109+
test("should update badge color to match scale legend colors", async ({ page }) => {
110+
const categoryBadge = page.locator("#bmi-category");
111+
112+
// Test normal weight - should have green color matching the legend
113+
await page.locator("#height-total-inches").fill("68");
114+
await page.locator("#weight-lbs").fill("150"); // BMI ≈ 22.8 (normal)
115+
await page.waitForTimeout(500);
116+
117+
await expect(categoryBadge).toContainText(/Normal/i);
118+
119+
// Test overweight - should have warning color matching the legend
120+
await page.locator("#weight-lbs").fill("185"); // BMI ≈ 28.1 (overweight)
121+
await page.waitForTimeout(500);
122+
123+
await expect(categoryBadge).toContainText(/Overweight/i);
124+
125+
// Verify the badge element has the correct CSS class for styling
126+
await expect(categoryBadge).toHaveClass(/overweight/);
127+
});
108128
});

0 commit comments

Comments
 (0)