ui icon indicating copy to clipboard operation
ui copied to clipboard

On mobile device can't click inside items of modal if multiple are open

Open CyberCowboy404 opened this issue 9 months ago • 3 comments

Environment

Version

2.15.2

Reproduction

https://stackblitz.com/edit/nuxt-ui-pqemsg?file=app.vue

Description

Weird behavior with modals on mobile devices(with tap event) When I have modal opened with prevent-close attr, I cannot click anything inside modal. In element inspection I notice that touch-action: auto; adds to clicked elements.

Initially I noticed this bug on my project. By default I have modal opened on the page with prevent close attr, and when I opened another modal, on mobile devices the actions inside second modal were blocked. But during creation of reproduction, I've noticed that button don't respond even in the first modal(on mobile device)

I was able to fix it(in my project), by closing the first modal. But it's weird because on desktops everything works fine

Additional context

No response

Logs

No response

CyberCowboy404 avatar May 04 '24 09:05 CyberCowboy404

I have similar issues on desktop, with a Slideover open which has prevent-close attr set to true, you cant interact with a modal

outlabsio avatar Jun 19 '24 13:06 outlabsio

In my opinion, this code is not functioning correctly.

@headlessui-vue/src/components/dialog/dialog.ts

    let outsideClickEnabled = computed(() => {
      if (!enabled.value) return false
      if (hasNestedDialogs.value) return false /* This condition is always evaluating to false */
      return true
    })

dalirnet avatar Jul 14 '24 05:07 dalirnet

having the same issue on mobile. it's does not focus on the new open modal

Sovai avatar Jul 24 '24 17:07 Sovai

Same, but causes problems in desktop too (ie. inputs not interactable).

soylomass avatar Aug 28 '24 19:08 soylomass

An, easy/quick fix to this problem until this is resolved at the framework level would be to nest the multiple dialogs instead of having them at root/same level

archit-credilio avatar Aug 29 '24 06:08 archit-credilio

I spent 5 hours and shot myself in the foot twice, but I came up with this:

Component.vue

<template>
    <Button
        v-text="click me"
        @click="action"
        @touch="action"
    />
</template>

<script setup lang="ts">
const action = () => {
    alert('OK')
}
</script>

Button.vue

<template>
    <button
        ref="button"
        v-bind="$attrs"
    />
</template>

<script setup lang="ts">
const button = ref()
const emit = defineEmits(['touch'])

const touchStart = () => {
    emit('touch')
}

onMounted(() => {
    button.value.addEventListener('touchstart', touchStart)
})

onBeforeUnmount(() => {
    button.value.removeEventListener('touchstart', touchStart)
})
</script>

This looks terrible, but it allows buttons to work on touch devices when multiple modals are open at once.

If you use this code in case when only 1 modal window will be opened, then @ click and @ touch will probably be triggered simultaneously (on touch devices).

ub1qq avatar Oct 15 '24 15:10 ub1qq