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(Popover/Dropdown): prevent unintended closure on touchstart in mobile devices #1609

Merged
merged 2 commits into from
Apr 3, 2024

Conversation

vahid-bagheri
Copy link

@vahid-bagheri vahid-bagheri commented Apr 3, 2024

🔗 Linked issue

A previous PR #1520 changed the event listener from @touchstart.prevent to @touchstart.passive to improve performance on mobile devices. This change introduced an unintended side effect where popovers and dropdowns unintentionally close on touch interaction.

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This pull request addresses a bug where both popover and dropdown components would unintentionally close on touch interaction (specifically the @touchstart.passive event) on mobile devices. This behavior did not occur on desktops.

While a previous change aimed to improve mobile performance by switching to @touchstart.passive, it caused this unintended side effect.

The fix introduces a check for the event.cancelable property before closing the component. This ensures the component only closes on intentional touch interactions.

Benefits:
Maintains the performance improvement introduced by the previous change.
Improves user experience on touch devices by preventing accidental closure of popovers and dropdowns.

Resource:
Easy fix for: '[Intervention] Ignored attempt to cancel a touchmove event with cancelable=false'

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@benjamincanac benjamincanac changed the title fix(popover, dropdown): Prevent unintended closure on touchstart in mobile devices fix(Popover/Dropdown): prevent unintended closure on touchstart in mobile devices Apr 3, 2024
@benjamincanac benjamincanac merged commit 2392b4a into nuxt:dev Apr 3, 2024
2 checks passed
@benjamincanac
Copy link
Member

Thanks 😊

@mrclsnkpl
Copy link

Hi there,

seems like the problem still exists for me. Dropdowns and Popovers immediately close on touch devices. I'm on the latest release 2.15.1.
Can you reproduce this?

Thanks

Copy link
Member

@mrclsnkpl There was a regression introduced in #1520 and fixed again in #1609 which hasn't been released yet.

@mrclsnkpl
Copy link

Ah, I see. Sorry, thought the fix was in 2.15.1.

Thanks a lot.

@bitbytebit1
Copy link

I'm still experiencing this issue on 2.15.2

@ghost
Copy link

ghost commented Sep 16, 2024

"@nuxt/ui": "^2.18.4", dropdown на мобильных устройствах все еще не работает как надо
пока нашел такое решение

<script setup>
...
const handleTouchStart = (event: Event) => {
	if (event.cancelable) event.preventDefault()
}
</script>

<template>
	<UDropdown :items="options" :popper="{ placement: 'bottom-start' }">
	      <button type="button" @touchstart="handleTouchStart">   toggle   </button>
	                <template #item="{ item }">
				....
			</template>
	</UDropdown>
</template>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants