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(onClickOutside): add bubble modifier to directive #2183

Merged
merged 4 commits into from Sep 16, 2022

Conversation

sibbng
Copy link
Member

@sibbng sibbng commented Sep 8, 2022

Description

Related #2181, #1405, #1405 (comment)
Solves #1366 in a better way to make it work with this feature.

How to use:

  <button @click.stop="modal = !modal">
    Toggle Modal
  </button>
  
  <div v-if="modal" v-on-click-outside.bubble="() => modal = false">
    Hello World
  </div>

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.

@sibbng
Copy link
Member Author

sibbng commented Sep 8, 2022

I just realized it doesn't work as expected on elements without v-if. Turning it into ObjectDirective.

@sibbng sibbng marked this pull request as draft September 8, 2022 22:29
return
export const vOnClickOutside: ObjectDirective<
HTMLElement,
OnClickOutsideHandler | [(evt: any) => void, OnClickOutsideOptions]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I haven't been able to conditionally switch between PointerEvent | FocusEvent and PointerEvent based on detectIframe value like I did in index.ts:38.

@sibbng sibbng marked this pull request as ready for review September 9, 2022 01:03
@antfu antfu merged commit 5a9768e into vueuse:main Sep 16, 2022
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.

None yet

2 participants