Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
Vue/JavaScript - Stop 'preventDefault' from affecting child components

I am trying to create a modal dialog in Vue. When the dialog is open, I want the page scrolling to be disabled but the user should still be able to scroll the dialog, and I was trying to achieve this with preventDefault. My component looks like this:

<!--Modal.vue-->
<template>
  <div v-show="open" class="modal" @scroll.stop.prevent @wheel.stop.prevent>
    <div class="mask"></div>
    <div class="overlay">
      <div class="dialog">
        <button @click="$emit('close')">CLOSE</button>
        <Paragraphs />
      </div>
    </div>
  </div>
</template>

<script>
import Paragraphs from "./Paragraphs";
export default {
  components: {
    Paragraphs,
  },

  props: {
    open: Boolean,
  },
};
</script>

<!--some scoped CSS here-->

Full working example on the sandbox https://codesandbox.io/s/optimistic-pond-3zrxsf

The problem is that while this arrangement is preventing page scrolling, it is also freezing scrolling on the dialog itself, which I don't want. And apparently stopPropagation only prevents bubbling up, but not down the DOM tree, so that isn't helping either. What can I do to achieve this?

Note: I do not want to set the overflow-y property of the body tag as that takes away the scrollbars completely and has a jittery effect of everything shifting to the side by a few pixels when the dialog is opened or closed.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!