Skip to content
Advertisement

Dialog and overlay size with vuetify 3

This is my dialog code:

<template>
  <div class="text-center">
    <v-dialog v-model="dialog" width="500">
      <template v-slot:activator="{ on, attrs }">
        <v-btn
          color="red lighten-2"
          dark
          v-bind="attrs"
          @click.stop="dialog = true">
          Click Me
        </v-btn>
      </template>

      <v-card>
        <v-card-title class="text-h5 grey lighten-2">
          Privacy Policy
        </v-card-title>

        <v-card-text>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        </v-card-text>

        <v-divider></v-divider>

        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn
            color="primary"
            text
            @click="dialog = false"
          >
            I accept
          </v-btn>
        </v-card-actions>
      </v-card>
    </v-dialog>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        dialog: false,
      }
    },
  }
</script>

As you see the width of the dialog is 500 <v-dialog width="500">. And this is the result I get:

enter image description here

As you see grey overlay width is also 500px. Is this correct? I expected that grey overlay width will be 100%, but dialog with with=500px will be in the center of the screen. Is it possible to set their sizes with <v-dialog> attributes or I should modify css rules?

Advertisement

Answer

There are some difference in dialog layout between Vuetify 3 and Vuetify 2. The below images is taken from example in their docs.

Vuetify 2:

Vuetify 2

Vuetify 3:

Vuetify 3

As you can see, in Vuetify 2 the overlay is an independent element and width: 500px added to the dialog while in Vuetify 3, the overlay contains dialog content and width: 500px added to the overlay. That causes the result you get. I’m not sure it’s expected behavior or not because Vuetify 3 is still in alpha version but for now, you can get your expected result by moving width="500" from v-dialog to v-card in your code.

Codepen

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement