Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop touchstart event propagation if coming from cancel button in detached mode #924

Merged
merged 12 commits into from
Mar 31, 2022
24 changes: 23 additions & 1 deletion packages/autocomplete-js/src/__tests__/detached.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,32 @@ describe('detached', () => {
'.aa-DetachedCancelButton'
);

// Prevent `onTouchStart` event from closing detached overlay
const windowTouchStartListener = jest.fn();
window.addEventListener('TouchStart', windowTouchStartListener);
Haroenv marked this conversation as resolved.
Show resolved Hide resolved

fireEvent(
cancelButton,
new TouchEvent('TouchStart', {
bubbles: true,
cancelable: true,
composed: true,
})
);

expect(windowTouchStartListener).toHaveBeenCalledTimes(0);

window.removeEventListener('TouchStart', windowTouchStartListener);

await waitFor(() => {
expect(document.querySelector('.aa-DetachedOverlay')).toBeInTheDocument();
expect(document.body).toHaveClass('aa-Detached');
});

// Close detached overlay
const bodyClickListener = jest.fn();
document.querySelector('body').addEventListener('click', bodyClickListener);

// Close detached overlay
cancelButton.click();

expect(bodyClickListener).toHaveBeenCalledTimes(0);
Expand Down