Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a ui component be an activator for two items? (Trying to use a v-tooltip with a v-dialog)

I have a button that is the activator for a dialog in my template. But I also want to use a tooltiop with the button. (Said otherwise, when I hover over the button I'd like to see the v-tooltip and when I click the button I'd like to open the dialog.)

I've tried to use the "append" slot on the tooltip but no success. When I add the append slot, the button completely vanishes from the rendered page.

Is it even possible to use a v-tooltip with a v-dialog in veutify?

This is what I have that does not work.

<script src="https://cdn.jsdelivr.net/npm/vuetify/dist/vuetify.js"></script>
<link href="https://cdn.jsdelivr.net/npm/vuetify/dist/vuetify.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<v-app>
  <v-dialog v-model="showAddPopup" persistent max-width="600px">
    <v-tooltip slot="append" bottom>

      <v-btn slot="activator" absolute fab dark left color="primary" @click="showPopup=true">
        <v-icon dark>add</v-icon>
      </v-btn>

      <span>Tooltip</span>
    </v-tooltip>

    <app-add-new-evaluator-modal @closePopup="closePopup($event)" @submit="addNewEvaluator" />
  </v-dialog>
</v-app>
like image 334
akaHeimdall Avatar asked Dec 10 '18 05:12

akaHeimdall


People also ask

What is V slot activator?

Details on the activator slotVMenu allows users to specify a slotted template named activator , containing component(s) that activate/open the menu upon certain events (e.g., click ).

What is v tooltip?

The v-tooltip component is useful for conveying information when a user hovers over an element. You can also programmatically control the display of tooltips through a v-model . When activated, tooltips display a text label identifying an element, such as a description of its function.


2 Answers

The Vuetify docs explain how to do this, but you'll find it in the Menu Component: https://vuetifyjs.com/en/components/menus#menu-with-activator-and-tooltip

Here's a simple example which opens a dialog with a button that has a tooltip:

<v-dialog>
  <template #activator="{ on: dialog }">
    <v-tooltip>
      <template #activator="{ on: tooltip }">
        <v-btn v-on="{ ...tooltip, ...dialog }">Button</v-btn>
      </template>
      <span>Tooltip text</span>
    </v-tooltip>
  </template>
  <v-card>
    Dialog content
  </v-card>
</v-dialog>
like image 171
vHarmonix Avatar answered Sep 19 '22 13:09

vHarmonix


Thanks @Traxo. All I had to do was add the slot="activator"to both components for it to work.

like image 24
akaHeimdall Avatar answered Sep 20 '22 13:09

akaHeimdall