Vuetify: Modal is not closing on clicking outside

Created on 22 Feb 2017  路  10Comments  路  Source: vuetifyjs/vuetify

The below error throws when I use modal,v0.8.10
Uncaught TypeError: Cannot read property 'addEventListener' of null
at HTMLDocument.eval (eval at (app.js:956), :1619:43)
In the code
document.querySelector('[data-app]').addEventListener('click', click, false)

document.querySelector('[data-app]') returns null.

Most helpful comment

You must wrap your app in a v-app component.

All 10 comments

You must wrap your app in a v-app component.

Did this solve your issue?

I have the same problem when use v-modal inside Nuxt application. There is no App component in Nuxt.

You must use v-app to wrap your application. Vuetify uses this to hook in for its click-outside directive.

@johnleider You'd think that should be mentioned at https://vuetifyjs.com/quick-start.

Sure thing boss, right on it.

@johnleider I wrapped up my code in <v-app> and got rid of "addEventListener" errors, but now the modals stopped working :( I open and close the modals programmatically using v-model variable set either to true or false.

I have a button in my component:

<v-btn v-on:click.native="openCategoryModal('main')">...</v-btn>

That calls the component's method:

openCategoryModal: function (categoryType, item) {
        // some preparation code

        this.categoryModal = true // this statement does not open the modal anymore
}

Modal markup:

<v-modal v-model="categoryModal">
      <v-card>
        <div class="modal-body">
          <!-- modal body goes here -->
          <v-card-row actions>
            <v-spacer></v-spacer>
            <v-btn flat v-on:click.native="categoryModal = false" class="primary--text">Cancel</v-btn>
            <v-btn flat v-on:click.native="submitCategory" class="primary--text">OK</v-btn>
          </v-card-row>
        </div>
      </v-card>
    </v-modal>

Everything is stored inside single .vue file. What am I doing wrong? I'm using v.0.9.4

When you do not use the activator slot, you must stop propagation of your clicks in order to prevent the modal from immediately closing.

Thank you @johnleider, it worked like a charm! :)

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please direct any non-bug questions to our Discord

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cawa-93 picture cawa-93  路  3Comments

dohomi picture dohomi  路  3Comments

ricardovanlaarhoven picture ricardovanlaarhoven  路  3Comments

Webifi picture Webifi  路  3Comments

dschreij picture dschreij  路  3Comments