Skip to content

Commit

Permalink
fix(Popover): improve hover mode on touch devices
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Mar 4, 2024
1 parent b74bf9f commit b50fbcf
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/runtime/components/overlays/Popover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
:disabled="disabled"
:class="ui.trigger"
role="button"
@mouseover="onMouseOver"
@mouseenter="onMouseEnter"
@touchstart.prevent="onTouchStart"
>
<slot :open="open" :close="close">
<button :disabled="disabled">
Expand All @@ -20,7 +21,7 @@
<div v-if="open" :class="[ui.overlay.base, ui.overlay.background]" />
</Transition>

<div v-if="open" ref="container" :class="[ui.container, ui.width]" :style="containerStyle" @mouseover="onMouseOver">
<div v-if="open" ref="container" :class="[ui.container, ui.width]" :style="containerStyle">
<Transition appear v-bind="ui.transition">
<div>
<div v-if="popper.arrow" data-popper-arrow :class="Object.values(ui.arrow)" />
Expand Down Expand Up @@ -153,7 +154,19 @@ export default defineComponent({
}
})
function onMouseOver () {
function onTouchStart () {
if (!popoverApi.value) {
return
}
if (popoverApi.value.popoverState === 0) {
popoverApi.value.closePopover()
} else {
popoverApi.value.togglePopover()
}
}
function onMouseEnter () {
if (props.mode !== 'hover' || !popoverApi.value) {
return
}
Expand Down Expand Up @@ -223,7 +236,8 @@ export default defineComponent({
trigger,
container,
containerStyle,
onMouseOver,
onTouchStart,
onMouseEnter,
onMouseLeave
}
}
Expand Down

0 comments on commit b50fbcf

Please sign in to comment.