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

feat(useDraggable): add stopPropagation option #1391

Merged
merged 3 commits into from
Mar 11, 2022

Conversation

webfansplz
Copy link
Member

Description

Close #1386

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@antfu antfu merged commit 7445f0a into vueuse:main Mar 11, 2022
@canyonwan
Copy link

canyonwan commented May 18, 2022

DOM:
<div class="fixed z-50 cursor-move bg-e-tools-box-icon bg-no-repeat bg-full h-20 w-20" ref="toolsBoxRef" :style="style" @click="openModal()">tools box</div>

Method:

    const { width, height } = useWindowSize()

    const { style } = useDraggable(toolsBoxRef, {
      initialValue: { x: width.value - 120, y: height.value - 120 },
      stopPropagation: true
    })`

ENV:
"vite": "^2.9.8",
"vue": "^3.2.33",
"@vueuse/core": "^8.4.2",

Problem :
When I move him, when I release the mouse, triggered the click method, but i already set stopPropagation: true
option.

@Xdy1579883916
Copy link

<component
    :is="draggable ? UseDraggable : 'div'"
    class="logo"
    :initialValue="{ top: '50%', right: 0 }"
    :preventDefault="true"
    :stopPropagation="true"
  >
    <img
      width="120"
      draggable="false"
      src="xxxx.png"
      @click.stop.prevent="$emit('open')"
    />
  </component>

我使用usedraggable组件,当我释放鼠标时,也触发了click方法,但我已经设置了: :stopPropagation=“true”
我读了源代码,可能是以下问题造成的:

I use the usedraggable component, when I release the mouse, triggered the click method too, but i already set :
:stopPropagation="true"; I read the source code, which may be caused by the following problems:

image

@canyonwan
Copy link

<component
    :is="draggable ? UseDraggable : 'div'"
    class="logo"
    :initialValue="{ top: '50%', right: 0 }"
    :preventDefault="true"
    :stopPropagation="true"
  >
    <img
      width="120"
      draggable="false"
      src="xxxx.png"
      @click.stop.prevent="$emit('open')"
    />
  </component>

我使用usedraggable组件,当我释放鼠标时,也触发了click方法,但我已经设置了: :stopPropagation=“true”; 我读了源代码,可能是以下问题造成的:

I use the usedraggable component, when I release the mouse, triggered the click method too, but i already set : :stopPropagation="true"; I read the source code, which may be caused by the following problems:

image
所以现在还要等他们修复是吗

@webfansplz
Copy link
Member Author

<component
    :is="draggable ? UseDraggable : 'div'"
    class="logo"
    :initialValue="{ top: '50%', right: 0 }"
    :preventDefault="true"
    :stopPropagation="true"
  >
    <img
      width="120"
      draggable="false"
      src="xxxx.png"
      @click.stop.prevent="$emit('open')"
    />
  </component>

我使用usedraggable组件,当我释放鼠标时,也触发了click方法,但我已经设置了: :stopPropagation=“true”; 我读了源代码,可能是以下问题造成的:
I use the usedraggable component, when I release the mouse, triggered the click method too, but i already set : :stopPropagation="true"; I read the source code, which may be caused by the following problems:
image
所以现在还要等他们修复是吗

PR已经合并,等发版哈

@webfansplz webfansplz deleted the chore-useDraggable branch May 26, 2022 10:55
@canyonwan
Copy link

<component
    :is="draggable ? UseDraggable : 'div'"
    class="logo"
    :initialValue="{ top: '50%', right: 0 }"
    :preventDefault="true"
    :stopPropagation="true"
  >
    <img
      width="120"
      draggable="false"
      src="xxxx.png"
      @click.stop.prevent="$emit('open')"
    />
  </component>

我使用usedraggable组件,当我释放鼠标时,也触发了click方法,但我已经设置了: :stopPropagation=“true”; 我读了源代码,可能是以下问题造成的:
I use the usedraggable component, when I release the mouse, triggered the click method too, but i already set : :stopPropagation="true"; I read the source code, which may be caused by the following problems:
image
所以现在还要等他们修复是吗

PR已经合并,等发版哈

我已经将vueuse升级到了8.6.0 但是我这个还是不行 不过我用的不是组件的形式 而是像这样#1391 (comment)

@canyonwan
Copy link

@webfansplz

DOM: <div class="fixed z-50 cursor-move bg-e-tools-box-icon bg-no-repeat bg-full h-20 w-20" ref="toolsBoxRef" :style="style" @click="openModal()">tools box</div>

Method:

    const { width, height } = useWindowSize()

    const { style } = useDraggable(toolsBoxRef, {
      initialValue: { x: width.value - 120, y: height.value - 120 },
      stopPropagation: true
    })`

ENV: "vite": "^2.9.8", "vue": "^3.2.33", "@vueuse/core": "^8.4.2",

Problem : When I move him, when I release the mouse, triggered the click method, but i already set stopPropagation: true option.

@webfansplz 像我这样还是不行

@canyonwan
Copy link

<component
    :is="draggable ? UseDraggable : 'div'"
    class="logo"
    :initialValue="{ top: '50%', right: 0 }"
    :preventDefault="true"
    :stopPropagation="true"
  >
    <img
      width="120"
      draggable="false"
      src="xxxx.png"
      @click.stop.prevent="$emit('open')"
    />
  </component>

我使用usedraggable组件,当我释放鼠标时,也触发了click方法,但我已经设置了: :stopPropagation=“true”; 我读了源代码,可能是以下问题造成的:

I use the usedraggable component, when I release the mouse, triggered the click method too, but i already set : :stopPropagation="true"; I read the source code, which may be caused by the following problems:

image

请问你是怎么引入的 Draggable组件的 我这样引入不对
WeChat6f20e7ccf8c5289bde7c7bdf5b9ed8c4

@DamonCais
Copy link

@Kuohao-wu
Copy link

@DamonCais Because the stopProgation is resolve the draggable target element event bubbling. You can try this way to trigger custom click event instead of the native click.

demo

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.

useDraggable 没有阻止元素冒泡 在某些情况下会造成bug
6 participants