Skip to content

Commit ff6a21b

Browse files
committed
fix(tab-button): apply correct focused background color in dark palette
1 parent 34effe8 commit ff6a21b

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { expect } from '@playwright/test';
2+
import { configs, test } from '@utils/test/playwright';
3+
4+
/**
5+
* Verifies that the focused state on tab buttons
6+
* uses a dark-appropriate background in the dark palette,
7+
* not the light-mode fallback (#e0e0e0)
8+
*/
9+
configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
10+
test.describe(title('tabs: focused state in dark palette'), () => {
11+
test.beforeEach(async ({ page }) => {
12+
await page.goto('/src/components/tabs/test/basic?ionic:palette=dark', config);
13+
14+
const tabButton = page.locator('.e2eTabOneButton');
15+
await tabButton.evaluate((el: HTMLElement) => {
16+
// focus-visible.ts only adds ion-focused in keyboard mode; trigger it first
17+
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', bubbles: true }));
18+
// the host has no tabindex; focus the actual <a> inside shadow DOM
19+
(el.shadowRoot?.querySelector('a') as HTMLElement)?.focus();
20+
});
21+
await page.waitForChanges();
22+
});
23+
24+
test('should not have visual regressions for focused tab button', async ({ page }) => {
25+
await expect(page.locator('.e2eTabOneButton')).toHaveClass(/ion-focused/);
26+
await expect(page.locator('ion-tab-bar')).toHaveScreenshot(screenshot('tab-bar-focused-dark'));
27+
});
28+
29+
test('focused tab button should not use light-mode fallback color', async ({ page }) => {
30+
const bgColor = await page.locator('.e2eTabOneButton').evaluate((el: HTMLElement) =>
31+
window.getComputedStyle(el, '::after').backgroundColor
32+
);
33+
// #e0e0e0 (rgb(224, 224, 224)) is the light-mode fallback from get-color-shade(#fff)
34+
expect(bgColor).not.toBe('rgb(224, 224, 224)');
35+
});
36+
});
37+
});

core/src/css/palettes/dark.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ $colors: (
126126
--ion-text-color-step-900: #1a1a1a;
127127
--ion-text-color-step-950: #0d0d0d;
128128
--ion-item-background: #000000;
129+
--ion-tab-bar-background-focused: #0b0b0b;
129130
--ion-card-background: #1c1c1d;
130131
}
131132

@@ -183,6 +184,7 @@ $colors: (
183184
--ion-item-background: #1e1e1e;
184185
--ion-toolbar-background: #1f1f1f;
185186
--ion-tab-bar-background: #1f1f1f;
187+
--ion-tab-bar-background-focused: #1b1b1b;
186188
--ion-card-background: #1e1e1e;
187189
}
188190
}

core/src/css/palettes/high-contrast-dark.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ $lightest-text-color: $text-color;
119119
--ion-text-color-rgb: #{color-to-rgb-list($text-color)};
120120
--ion-item-background: #000000;
121121
--ion-card-background: #1c1c1d;
122+
--ion-tab-bar-background-focused: #0b0b0b;
122123

123124
/// Only the item borders should increase in contrast
124125
/// Borders for elements like toolbars should remain the same
@@ -185,6 +186,7 @@ $lightest-text-color: $text-color;
185186
--ion-item-background: #1e1e1e;
186187
--ion-toolbar-background: #1f1f1f;
187188
--ion-tab-bar-background: #1f1f1f;
189+
--ion-tab-bar-background-focused: #0b0b0b;
188190
--ion-card-background: #1e1e1e;
189191

190192
/// Only the item borders should increase in contrast

0 commit comments

Comments
 (0)