Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CrastyCrap's avatar

Close model on click on overlay

greeting, i have modal with overlay i want when i click on overlay the modal close but if i click on modal nothing happend

0 likes
7 replies
Sinnbeck's avatar

I usually add a div that is positioned behind the modal but with a lower z-index. I then give it a click event

1 like
CrastyCrap's avatar

@Sinnbeck i want to know the modifier that i can use to prevent close event from take place when i click on modal which is the child of overlay

Sinnbeck's avatar

@CrastyCrap I make 3 divs

<div class="container">
  <div class="overlay"></div>
  <div class="content"></div>
</div>

The overlay and content are both children. It should just work

1 like
rodrigo.pedra's avatar

@crastycrap I think you referring to the self modifier?

https://vuejs.org/guide/essentials/event-handling.html#event-modifiers

But I think you would still need a separated overlay <div> behind the modals' content, as you would apply @onclick.self="myHandler" to that element.

Which in practice is unneeded as the modal content is a sibling to the overlay and the click event won't bubble up to it.

the self modifier is useful when you want to make sure a click happened on the target element itself and not in one of its children Which is not the case on @sinnbeck 's suggestion that is also the most common model/overlay implementation.

1 like
Sinnbeck's avatar

@rodrigo.pedra Well said. And actually I dont think z-index matters as they are siblings and content is last :)

1 like

Please or to participate in this conversation.