Skip to content

Commit 521063b

Browse files
authoredMar 28, 2023
fix(item-sliding): open method works with items added async (#27035)
resolves #26991
1 parent c9e4cd0 commit 521063b

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed
 

‎core/src/components/item-sliding/item-sliding.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,16 @@ export class ItemSliding implements ComponentInterface {
127127
*/
128128
@Method()
129129
async open(side: Side | undefined) {
130-
if (this.item === null) {
130+
/**
131+
* It is possible for the item to be added to the DOM
132+
* after the item-sliding component was created. As a result,
133+
* if this.item is null, then we should attempt to
134+
* query for the ion-item again.
135+
* However, if the item is already defined then
136+
* we do not query for it again.
137+
*/
138+
const item = (this.item = this.item ?? this.el.querySelector('ion-item'));
139+
if (item === null) {
131140
return;
132141
}
133142

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="ltr">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Item Sliding - Async</title>
6+
<meta
7+
name="viewport"
8+
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
9+
/>
10+
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
11+
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
12+
<script src="../../../../../scripts/testing/scripts.js"></script>
13+
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
14+
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
15+
</head>
16+
17+
<body>
18+
<ion-app>
19+
<ion-header>
20+
<ion-toolbar>
21+
<ion-title>Item Sliding - Basic</ion-title>
22+
</ion-toolbar>
23+
</ion-header>
24+
25+
<ion-content>
26+
<ion-list>
27+
<ion-item-sliding>
28+
<ion-item-options side="end">
29+
<ion-item-option>Option</ion-item-option>
30+
</ion-item-options>
31+
</ion-item-sliding>
32+
</ion-list>
33+
34+
<script>
35+
const itemSliding = document.querySelector('ion-item-sliding');
36+
setTimeout(() => {
37+
const item = document.createElement('ion-item');
38+
item.innerText = 'Item Sliding Option';
39+
itemSliding.appendChild(item);
40+
41+
item.onclick = () => {
42+
itemSliding.open('end');
43+
};
44+
}, 250);
45+
</script>
46+
</ion-content>
47+
</ion-app>
48+
</body>
49+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect } from '@playwright/test';
2+
import { test } from '@utils/test/playwright';
3+
4+
test.describe('item-sliding: async', () => {
5+
test('should open even when item is added async', async ({ page, skip }) => {
6+
skip.rtl();
7+
skip.mode('md');
8+
9+
await page.goto(`/src/components/item-sliding/test/async`);
10+
11+
const itemEl = page.locator('ion-item');
12+
const itemSlidingEl = page.locator('ion-item-sliding');
13+
14+
// Wait for item to be added to DOM
15+
await page.waitForSelector('ion-item');
16+
17+
// Click item to open ion-item-sliding
18+
await itemEl.click();
19+
20+
// This class is added when the item sliding component is fully open
21+
await expect(itemSlidingEl).toHaveClass(/item-sliding-active-slide/);
22+
});
23+
});

0 commit comments

Comments
 (0)
Please sign in to comment.