Steps for universally integrating a Vue tooltip component into all elements with a classic tooltip attribute

Switching my application from Handlebars + Semantic UI to Vue3 + Vuetify has presented a challenge as I encounter differences in implementation.

Previously, I utilized the data-tooltip attributes extensively in Semantic UI which seamlessly upgraded them to elegant tooltips without any additional markup.

In order to cater to both regular and pro users, I incorporated a feature to "disable tooltips" by introducing a data-app-tooltip attribute which controlled the display based on user preferences. This transformation was achieved through a simple JQuery function that modified the app-specific tooltip attributes to standard ones upon page load.

However, with the Vuetify tooltip component requiring additional markup associated with triggering components, I am faced with the task of replicating my previous transformation process for seamless integration.

Previously, in Semantic UI, this transformation took place within the page-load template:

    $(document).ready(function () {
        // Disable tooltips based on user configuration.
        if(confTooltips){
            // Convert placeholders to actual tooltips
            $("[data-app-tooltip]").each(function(i,el){
                var $el = $(el);
                $el.attr('data-tooltip', $el.attr('data-app-tooltip'));
            });
        }
    })

An example interface with an optional tooltip looked like:

    <a href="/app/mode/full"
       class="ui mini basic icon item"
       data-app-tooltip="Show the full navigation controls"
    >
        <i class="icon angle right"></i>
    </a>

Now, my goal is to have a global Vue transform that converts elements with the data-app-tooltip attribute into components with proper structure according to Vuetify's tooltip component.

For instance, transforming an item like this:

    <span v-bind="props" data-app-tooltip="The number of items imported from this file">
       {{ item.count }} 
    </span>

To something similar to:

    <v-tooltip text="The number of items imported from this file">
       <template v-slot:activator="{ props }">
            <span v-bind="props">
                 {{ item.count }} 
           </span>
         </template>
    </v-tooltip>

The exact implementation details might vary depending on the simplicity of the preferred Vuetify tooltip, considering the complexity of the documentation available.

This also raises a more general question: how can Vue templates be transformed into a different format before being instantiated by the framework?

Answer №1

One option is to create a custom directive for that purpose.

To see an example of how it would appear, you can visit

<InputText v-tooltip="'Enter your username'" type="text" placeholder="Right" />
<InputText v-tooltip.top="'Enter your username'" type="text" placeholder="Top" />
<InputText v-tooltip.bottom="'Enter your username'" type="text" placeholder="Bottom" />
<InputText v-tooltip.left="'Enter your username'" type="text" placeholder="Left" />

You can refer to the code snippets in https://github.com/vuetifyjs/vuetify/issues/9610#issuecomment-1613601337 or utilize the useDirectiveComponent from https://github.com/vuetifyjs/vuetify/pull/17395/files for implementation

For related discussions, check out: https://github.com/vuetifyjs/vuetify/issues/9610 , https://github.com/vuetifyjs/vuetify/pull/17395

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are the benefits of using a synchronous XMLHttpRequest?

Many developers opt for asynchronous XMLHttpRequest requests, but the existence of synchronous requests suggests that there could be valid reasons for using them. What might those reasons be? ...

Issue with CodeIgniter not loading a JavaScript file

When working with CodeIgniter, I have a setup where my view file is located in the root folder, and I also have some Javascript files within a "js" sub-folder of the view. I attempted to include the Javascript file like this: <script src="js/jquery-bli ...

Having difficulty accessing a PHP ajax post request

I've scoured every resource but can't seem to find a solution to this issue. I'm in the process of writing an ajax script, however, I am struggling to retrieve the correct value from the POST request. Here is the code I have so far: <t ...

Is Softbody possible in WebGL using Three.js?

Are there ways to combine softbody physics with WebGL or threejs? Could I possibly incorporate the PhysX engine into the mix? I am looking to animate a 3d rigid body inside a 3d soft body and have the soft body react to the movement. Ideally, the soft bod ...

"Keep the ajax requests flowing, don't forget about the previous

Utilizing the Bootstrap framework version 3.3.7, I am faced with the following code: $('#field_submit').click(function() { //omitted irrelevant parts if (counter == 0) { //no errors encountered, form can be submitted ...

I have a project where I'm tasked with assembling a collection of images sourced from an Array populated with JSON

For a homework assignment, I am tasked with creating a basic gallery that showcases 4 images. My goal is to store all the images in an array, with each photo represented as a JSON object, and then load these images from the array. Here is my progress so fa ...

Maintaining an object's position steady in relation to the camera in Three.js

I am trying to figure out how to maintain an object's position relative to the camera. Specifically, I want one object to be viewable from all angles using a trackball camera, while another object should always stay in the same position relative to th ...

Conceal the Action and/or Status Bar in Android Studio APK using Vue+Capacitor

As a web developer looking to transition into app development, I am currently working on a project with a specific pipeline: Develop Vue SPA and run npm build Install capacitor on the project following the instructions at , where the capacitor www folder ...

Utilizing Vue to Customize Chart Settings with Data

I'm currently working on hitting a rest api to retrieve a dataset for a specific piece of equipment. However, I'm struggling to extract the first column of data as an array. I've attempted using computed and methods in vue, but I constantly ...

How can I execute code once the webpage has finished loading properly?

On my webpage, referred to as X, I inserted a script tag within the head section. This script is designed to scan the body after it has finished rendering. I attempted using jQuery.ready() but unfortunately it did not trigger! Is it possible that the DOM ...

What could be the reason behind the malfunctioning of my date validation?

I have successfully implemented a JavaScript pattern for validating my name, email, and checkboxes. However, I am encountering issues with the birthday field not validating properly. To validate the birthday, I first remove any white space to ensure it i ...

Tips for passing a usestate via props using interfaces in TypeScript and react?

I am currently working on implementing a light/dark theme and I have 2 components involved in the process. The first component code snippet is shown below, where I have successfully implemented a boolean to toggle between styles: export interface Props ...

Transferring PHP session variables from jQuery and Ajax to the PHP gratitude page

I've been mulling over this puzzle for quite some time now. My approach involves utilizing jQuery AJAX POST method to transmit form data using session variables from home.php to thankyou.php. Subsequently, the user is redirected (window.location.href ...

What is the best approach for making a drawer resizable?

I am interested in making the material ui drawer resizable width using a draggable handle. Currently, I have implemented a solution that involves adding a mouse event listener to the entire application and updating the width based on the position of the ...

Combine text in vue.js within a form

I'm looking to merge the texts I've created in vue into a single text Example: text field 1 = Code text field 2 = Area text field 3 = NumberCode Then I have one text field UniqueNumber, which is the value of this text field a combination of ...

Display the worth in a pop-up box

I am looking to display the form value in a pop-up window that opens after clicking the submit button. How can I achieve this? Here is my form: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> &l ...

Mining Data from JSON documents

I am dealing with a webservice that returns JSON data in the following format: {"d":"{\"RES\":[],\"STAT\":\"FAIL\",\"SID\":\"0\"}"} So, my question is how can I extract the STAT=FAIL value from this JSON ...

What is the best way to confirm that the checkbox is selected in Cypress?

I am currently attempting to verify an element to determine whether the checkbox is checked or not. Please refer to the image provided below: https://i.sstatic.net/bACOS.png Here is the DOM structure required to target this specific element: <pds-radi ...

What is the most effective way to transfer content from the clipboard?

I need to transfer content from one div to another by copy/pasting When I click the paste button in the example below, the expected result in the target div is - <p>lorem ipsum</p> but unfortunately, nothing happens $('.btncopy&apos ...

Ways to substitute the v-model pattern with react hooks

Transitioning my application from Vue to React. In Vue 2, using v-model on a component was similar to passing a value prop and emitting an input event. To change the prop or event names to something different in Vue, a model option needed to be added to t ...