Skip to content

Commit 5cdeb7f

Browse files
feat(item-divider): add inner and container parts (#30928)
Issue number: N/A --------- ## What is the current behavior? The inner structural elements of item-divider are not exposed as shadow parts, preventing users from being able to customize their styles directly. ## What is the new behavior? - Exposes `inner` and `container` shadow parts - Adds e2e test coverage for customizing the shadow parts ## Does this introduce a breaking change? - [ ] Yes - [x] No --------- Co-authored-by: Brandy Smith <[email protected]>
1 parent a2c6559 commit 5cdeb7f

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

core/api.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,8 @@ ion-item-divider,css-prop,--padding-start,ios
968968
ion-item-divider,css-prop,--padding-start,md
969969
ion-item-divider,css-prop,--padding-top,ios
970970
ion-item-divider,css-prop,--padding-top,md
971+
ion-item-divider,part,container
972+
ion-item-divider,part,inner
971973

972974
ion-item-group,none
973975

core/src/components/item-divider/item-divider.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import type { Color } from '../../interface';
1111
* @slot - Content is placed between the named slots if provided without a slot.
1212
* @slot start - Content is placed to the left of the divider text in LTR, and to the right in RTL.
1313
* @slot end - Content is placed to the right of the divider text in LTR, and to the left in RTL.
14+
*
15+
* @part inner - The inner wrapper element that arranges the divider content.
16+
* @part container - The wrapper element that contains the default slot.
1417
*/
1518
@Component({
1619
tag: 'ion-item-divider',
@@ -50,8 +53,8 @@ export class ItemDivider implements ComponentInterface {
5053
})}
5154
>
5255
<slot name="start"></slot>
53-
<div class="item-divider-inner">
54-
<div class="item-divider-wrapper">
56+
<div class="item-divider-inner" part="inner">
57+
<div class="item-divider-wrapper" part="container">
5558
<slot></slot>
5659
</div>
5760
<slot name="end"></slot>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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('item-divider: 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-item-divider::part(inner) {
15+
background-color: red;
16+
}
17+
</style>
18+
19+
<ion-item-divider>Divider</ion-item-divider>
20+
`,
21+
config
22+
);
23+
24+
const divider = page.locator('ion-item-divider');
25+
const backgroundColor = await divider.evaluate((el) => {
26+
const shadowRoot = el.shadowRoot;
27+
const inner = shadowRoot?.querySelector('.item-divider-inner');
28+
return inner ? window.getComputedStyle(inner).backgroundColor : '';
29+
});
30+
expect(backgroundColor).toBe('rgb(255, 0, 0)');
31+
});
32+
33+
test('should be able to customize container part', async ({ page }) => {
34+
await page.setContent(
35+
`
36+
<style>
37+
ion-item-divider::part(container) {
38+
background-color: green;
39+
}
40+
</style>
41+
42+
<ion-item-divider>Divider</ion-item-divider>
43+
`,
44+
config
45+
);
46+
47+
const divider = page.locator('ion-item-divider');
48+
const backgroundColor = await divider.evaluate((el) => {
49+
const shadowRoot = el.shadowRoot;
50+
const container = shadowRoot?.querySelector('.item-divider-wrapper');
51+
return container ? window.getComputedStyle(container).backgroundColor : '';
52+
});
53+
expect(backgroundColor).toBe('rgb(0, 128, 0)');
54+
});
55+
});
56+
});
57+
});

0 commit comments

Comments
 (0)