Skip to content

Commit ef73476

Browse files
feat(list-header): add inner part (#30930)
Issue number: N/A --------- ## What is the current behavior? The inner structural element of list-header is not exposed as a shadow part, preventing users from being able to customize its styles directly. ## What is the new behavior? - Exposes `inner` shadow part - Adds e2e test coverage for customizing the shadow part ## Does this introduce a breaking change? - [ ] Yes - [x] No --------- Co-authored-by: Brandy Smith <6577830+brandyscarney@users.noreply.github.com>
1 parent f8f7ffd commit ef73476

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

core/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ ion-list-header,css-prop,--color,ios
10331033
ion-list-header,css-prop,--color,md
10341034
ion-list-header,css-prop,--inner-border-width,ios
10351035
ion-list-header,css-prop,--inner-border-width,md
1036+
ion-list-header,part,inner
10361037

10371038
ion-loading,scoped
10381039
ion-loading,prop,animated,boolean,true,false,false

core/src/components/list-header/list-header.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import type { Color } from '../../interface';
77

88
/**
99
* @virtualProp {"ios" | "md"} mode - The mode determines which platform styles to use.
10+
*
11+
* @part inner - The inner wrapper element that arranges the list header content.
1012
*/
1113
@Component({
1214
tag: 'ion-list-header',
@@ -40,7 +42,7 @@ export class ListHeader implements ComponentInterface {
4042
[`list-header-lines-${lines}`]: lines !== undefined,
4143
})}
4244
>
43-
<div class="list-header-inner">
45+
<div class="list-header-inner" part="inner">
4446
<slot></slot>
4547
</div>
4648
</Host>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { expect } from '@playwright/test';
2+
import { configs, test } from '@utils/test/playwright';
3+
4+
/**
5+
* This behavior does not vary across modes/directions
6+
*/
7+
configs({ directions: ['ltr'], modes: ['md'] }).forEach(({ title, config }) => {
8+
test.describe(title('list-header: custom'), () => {
9+
test.describe('CSS shadow parts', () => {
10+
test('should be able to customize inner part', async ({ page }) => {
11+
await page.setContent(
12+
`
13+
<style>
14+
ion-list-header::part(inner) {
15+
background-color: red;
16+
}
17+
</style>
18+
19+
<ion-list-header>Header</ion-list-header>
20+
`,
21+
config
22+
);
23+
24+
const header = page.locator('ion-list-header');
25+
const backgroundColor = await header.evaluate((el) => {
26+
const shadowRoot = el.shadowRoot;
27+
const inner = shadowRoot?.querySelector('.list-header-inner');
28+
return inner ? window.getComputedStyle(inner).backgroundColor : '';
29+
});
30+
expect(backgroundColor).toBe('rgb(255, 0, 0)');
31+
});
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)