Skip to content

Commit a620a99

Browse files
committed
fix(tabbar): correctly handle pointercancel
fixes #4380 fixes #4381
1 parent 11ce150 commit a620a99

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/core/components/toolbar/tabbar-highlight.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ export const initTabbarHighlight = (el) => {
8383

8484
if (e.type === 'pointerdown') {
8585
data.linkEls = el.querySelectorAll('.tab-link');
86+
data.activeIndex = [...data.linkEls].findIndex((link) =>
87+
link.classList.contains('tab-link-active'),
88+
);
8689
data.rect = toolbarPaneEl.getBoundingClientRect();
8790
data.touched = true;
8891
setHighlightOnTouch(data, e);
@@ -100,6 +103,18 @@ export const initTabbarHighlight = (el) => {
100103
unsetHighlightOnTouch(data);
101104
stopAnimation(data);
102105
}
106+
if (e.type === 'pointercancel') {
107+
if (!data.touched) return;
108+
data.touched = false;
109+
data.moved = false;
110+
data.setTransform = null;
111+
stopAnimation(data);
112+
if (highlightEl) {
113+
highlightEl.classList.remove('tab-link-highlight-pressed');
114+
highlightEl.style.transform = `translateX(${data.activeIndex * 100}%)`;
115+
highlightEl.style.transitionTimingFunction = '';
116+
}
117+
}
103118
};
104119
el.addEventListener('touchstart', el.f7ToolbarOnPointer, { passive: false });
105120
el.addEventListener('pointerdown', el.f7ToolbarOnPointer, { passive: false });

0 commit comments

Comments
 (0)