Skip to content

Commit 3998b1a

Browse files
docs: onClickOutside ignore by CSS Selectors (#4836)
1 parent 4d125f2 commit 3998b1a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/core/onClickOutside/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ useEventListener('pointermove', (e) => {
4444
})
4545
```
4646

47+
If you want to ignore certain elements, you can use the `ignore` option. Provide the elements to ignore as an array of Refs or CSS Selectors.
48+
49+
```ts
50+
const ignoreElRef = useTemplateRef<HTMLElement>('ignoreEl')
51+
const ignoreElSelector = '.ignore-el'
52+
53+
onClickOutside(
54+
target,
55+
event => console.log(event),
56+
{ ignore: [ignoreElRef, ignoreElSelector] },
57+
)
58+
```
59+
4760
## Component Usage
4861

4962
```vue

packages/core/onClickOutside/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { useEventListener } from '../useEventListener'
1010

1111
export interface OnClickOutsideOptions<Controls extends boolean = false> extends ConfigurableWindow {
1212
/**
13-
* List of elements that should not trigger the event.
13+
* List of elements that should not trigger the event,
14+
* provided as Refs or CSS Selectors.
1415
*/
1516
ignore?: MaybeRefOrGetter<(MaybeElementRef | string)[]>
1617
/**
@@ -84,8 +85,8 @@ export function onClickOutside(
8485
if (isIOS && !_iOSWorkaround) {
8586
_iOSWorkaround = true
8687
const listenerOptions = { passive: true }
87-
// Not using useEventListener because this event handlers must not be disposed.
88-
// See previusly linked references and https://github.com/vueuse/vueuse/issues/4724
88+
// Not using useEventListener because these event handlers must not be disposed.
89+
// See previously linked references and https://github.com/vueuse/vueuse/issues/4724
8990
Array.from(window.document.body.children)
9091
.forEach(el => el.addEventListener('click', noop, listenerOptions))
9192
window.document.documentElement.addEventListener('click', noop, listenerOptions)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy