mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(item-sliding): open method works with items added async (#27035)
resolves #26991
This commit is contained in:
@@ -127,7 +127,16 @@ export class ItemSliding implements ComponentInterface {
|
||||
*/
|
||||
@Method()
|
||||
async open(side: Side | undefined) {
|
||||
if (this.item === null) {
|
||||
/**
|
||||
* It is possible for the item to be added to the DOM
|
||||
* after the item-sliding component was created. As a result,
|
||||
* if this.item is null, then we should attempt to
|
||||
* query for the ion-item again.
|
||||
* However, if the item is already defined then
|
||||
* we do not query for it again.
|
||||
*/
|
||||
const item = (this.item = this.item ?? this.el.querySelector('ion-item'));
|
||||
if (item === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
49
core/src/components/item-sliding/test/async/index.html
Normal file
49
core/src/components/item-sliding/test/async/index.html
Normal file
@@ -0,0 +1,49 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Item Sliding - Async</title>
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
|
||||
/>
|
||||
<link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
|
||||
<link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
|
||||
<script src="../../../../../scripts/testing/scripts.js"></script>
|
||||
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
|
||||
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<ion-app>
|
||||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-title>Item Sliding - Basic</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
|
||||
<ion-content>
|
||||
<ion-list>
|
||||
<ion-item-sliding>
|
||||
<ion-item-options side="end">
|
||||
<ion-item-option>Option</ion-item-option>
|
||||
</ion-item-options>
|
||||
</ion-item-sliding>
|
||||
</ion-list>
|
||||
|
||||
<script>
|
||||
const itemSliding = document.querySelector('ion-item-sliding');
|
||||
setTimeout(() => {
|
||||
const item = document.createElement('ion-item');
|
||||
item.innerText = 'Item Sliding Option';
|
||||
itemSliding.appendChild(item);
|
||||
|
||||
item.onclick = () => {
|
||||
itemSliding.open('end');
|
||||
};
|
||||
}, 250);
|
||||
</script>
|
||||
</ion-content>
|
||||
</ion-app>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,23 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import { test } from '@utils/test/playwright';
|
||||
|
||||
test.describe('item-sliding: async', () => {
|
||||
test('should open even when item is added async', async ({ page, skip }) => {
|
||||
skip.rtl();
|
||||
skip.mode('md');
|
||||
|
||||
await page.goto(`/src/components/item-sliding/test/async`);
|
||||
|
||||
const itemEl = page.locator('ion-item');
|
||||
const itemSlidingEl = page.locator('ion-item-sliding');
|
||||
|
||||
// Wait for item to be added to DOM
|
||||
await page.waitForSelector('ion-item');
|
||||
|
||||
// Click item to open ion-item-sliding
|
||||
await itemEl.click();
|
||||
|
||||
// This class is added when the item sliding component is fully open
|
||||
await expect(itemSlidingEl).toHaveClass(/item-sliding-active-slide/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user