Im having a swiper and loader. Scenario its very easy
Whenever some calculations are performed its initialized the loader and after we get the sucess result turn off the loader and swip to second slide.
<swiper-container #slides [allowTouchMove]="false" pagination="false">
<swiper-slide
>Slide 1
<ion-button (click)="changeSlide()" mode="md">Change slide 1</ion-button>
</swiper-slide>
<swiper-slide
>Slide 2
<ion-button (click)="changeSlide()" mode="md"
>Change slide 2</ion-button
></swiper-slide
>
<swiper-slide
>Slide 3
<ion-button (click)="changeSlide()" mode="md"
>Change slide 3</ion-button
></swiper-slide
>
</swiper-container>
Whenever dismised the loader the swipper is just swipping to the next page and coming back again.
async presentLoading() {
const loading = await this.loadingController.create({
message: 'Loading...',
});
return await loading.present();
}
public async changeSlide(): Promise<void> {
this.presentLoadingOverlay()
.then((data: any) => {
data.present();
this.slideNext(),
setTimeout(() => {
data.dismiss();
}, 3000);
data.onDidDismiss().then(() => {
console.log('Loading dismissed! after 3 Seconds');
});
})
}
Even putting this.slideNext(), after the timeout will not change nothing. The dismis call will turn back to the current page
setTimeout(() => {
data.dismiss();
}, 3000);
This is replied here:
opened 09:15PM - 24 Aug 23 UTC
closed 12:33PM - 25 Aug 23 UTC
triage
### Prerequisites
- [X] I have read the [Contributing Guidelines](https://git… hub.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#creating-an-issue).
- [X] I agree to follow the [Code of Conduct](https://ionicframework.com/code-of-conduct).
- [X] I have searched for [existing issues](https://github.com/ionic-team/ionic-framework/issues) that already report this problem, without success.
### Ionic Framework Version
v7.x
### Current Behavior
Having a basic swiper that change on a button click.
Before the change of slide some loader is initialized , than the slide is changed and than the loader is dismissed.
**After the loader getting dismissed its returning the slide where its initialized******
### Expected Behavior
Is expected that the loader to be created, the slide to change and after that the loader to be dismissed without turning to previous page.
### Steps to Reproduce
`
const loading = await this.loadingController
.create({
cssClass: 'loading-overlay',
duration: 2000,
})
.then((res) => {
res.present();
res.onDidDismiss().then(() => {
this.slideNext(); // not working
// setTimeout(() => { //this is working
// this.slideNext();
// }, 0);
});
});
`
### Code Reproduction URL
https://github.com/StefaniToto/ionic7-angular16-bug-loader-swiper/
### Ionic Info
Ionic:
Ionic CLI : 7.1.1
Ionic Framework : @ionic/angular 7.3.1
@angular-devkit/build-angular : 16.2.0
@angular-devkit/schematics : 16.2.0
@angular/cli : 16.2.0
@ionic/angular-toolkit : 9.0.0
Capacitor:
Capacitor CLI : 5.2.3
@capacitor/android : not installed
@capacitor/core : 5.2.3
@capacitor/ios : not installed
Utility:
cordova-res : not installed globally
native-run : 1.7.2
System:
NodeJS : v16.14.2
npm : 8.5.0
OS : Windows 10
### Additional Information
1. When adding settimeout its working as should.
` setTimeout(() => { //this is working
this.slideNext();
}, 0);`
2. If remove the button outside of swiper-slide its working as should.
3. If the this.slideNext() its forced to start after the loader dismissed its also working.
This doesnt work
```
res.present()
this.slideNext()
res.dismiss()
```
This work
```
res.present();
setTimeout(() => {
this.slideNext();
}, 1000);
setTimeout(() => {
res.dismiss();
}, 500)
```
4. None of change detection startegies (markForCheck, detectChange) are not triggering something

The problem here is when ion-loading
is dismissed, focus is returned to the element that presented it. In this case, the ion-button
in slide 0 gets focused. Swiper has logic in https://github.com/nolimits4web/swiper/blob/1cc359e45d637c209ce97ebffb917ae8587fdcf2/src/modules/a11y/a11y.mjs#L220 to show to the slide when an element inside of it is focused. Since the button in slide 0 is being focused, this effectively cancels out or undoes your manual slideNext
call.
Both of these behaviors are intentional accessibility features. According to Dialog (Modal) Pattern | APG | WAI | W3C , dialogs should return focus to the element that invoked the dialog.
You can avoid this collision by moving the ion-button
that presents the loading outside of the swiper container.