Skip to content

Commit 13e3a6c

Browse files
fix(tour): calculate arrow position correctly on size change
1 parent 9d5d640 commit 13e3a6c

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

playwright/e2e/element-examples/si-tour.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ test.describe('si-tour', () => {
1111
const nextClick = (): Promise<any> =>
1212
page.locator('si-tour button', { hasText: 'Next' }).click();
1313

14-
const waitForTourStep = async (hasArrow = true): Promise<void> => {
14+
const waitForTourStep = async (): Promise<void> => {
1515
await expect(page.locator('si-tour .tour-content.show')).toBeVisible();
16-
if (hasArrow) {
17-
await expect(page.locator('si-tour .popover-arrow')).toBeVisible();
18-
}
1916
};
2017

2118
await si.visitExample(example);
@@ -33,7 +30,7 @@ test.describe('si-tour', () => {
3330
await waitForTourStep();
3431
await si.runVisualAndA11yTests('open-menu');
3532
await nextClick();
36-
await waitForTourStep(false);
33+
await waitForTourStep();
3734
await si.runVisualAndA11yTests('last-step');
3835
});
3936
});

projects/element-ng/tour/si-tour.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export class SiTourComponent implements OnDestroy {
5454
private elementRef: ElementRef<HTMLElement> = inject(ElementRef);
5555
private subscription?: Subscription;
5656
private prevFocus: Element | null = null;
57+
private lastPositionChange: PositionChange | undefined;
5758

5859
private readonly focusTrap = viewChild<CdkTrapFocus>('focusTrap');
5960
private document = inject(DOCUMENT);
@@ -71,6 +72,9 @@ export class SiTourComponent implements OnDestroy {
7172
this.subscription.add(
7273
this.tourToken.positionChange.subscribe(update => this.updatePosition(update))
7374
);
75+
this.subscription.add(
76+
this.tourToken.sizeChange.subscribe(() => this.updatePosition(this.lastPositionChange))
77+
);
7478
}
7579

7680
ngOnDestroy(): void {
@@ -110,6 +114,7 @@ export class SiTourComponent implements OnDestroy {
110114
}
111115

112116
private updatePosition(update: PositionChange | undefined): void {
117+
this.lastPositionChange = update;
113118
if (!update) {
114119
this.positionClass.set('');
115120
this.arrowPos.set(undefined);

projects/element-ng/tour/si-tour.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ export class SiTourService {
224224
{ originX: 'start', overlayX: 'end', originY: 'center', overlayY: 'center' },
225225
{ originX: 'end', overlayX: 'start', originY: 'center', overlayY: 'center' }
226226
]);
227-
this.overlayRef!.updatePositionStrategy(positionStrategy);
228227
this.positionChangeSub = positionStrategy.positionChanges
229228
.pipe(map(change => ({ change, anchor })))
230229
// We only want to forward the next channel, as the positionChanges completes when setting a new origin.
231230
.subscribe(value => this.tourToken.positionChange.next(value));
231+
this.overlayRef!.updatePositionStrategy(positionStrategy);
232232
}
233233

234234
private createOrUpdateOverlays(): void {

0 commit comments

Comments
 (0)