How can Popper.js be used to position a tooltip next to an element?

I have a question. How can I make the Poppers.js tooltip appear around an element (popcorn) that is passed through? I am using Vuejs, Nuxt, and typescript for my webpage.

Otherwise, it "sticks" around the div element and the tooltip displays incorrectly (check images below).

<template>
  <div>
    <div ref="popcorn" aria-describedby="tooltip">
        <slot name="action" :toggle="toggle" :close="close" />
    </div>
    <div ref="tooltip" role="tooltip">
      <div :class="[ci-popover, `ci-popover--background-color-${variant}`,`ci-popover--padding-${padding}`]">
        <slot name="default" />
      </div>
    </div>
  </div>

This is how it currently looks like: https://i.sstatic.net/7G1cK.png in the inspector: https://i.sstatic.net/U61XC.png

The second solution I tried was to add a parameter to the slot element with ref="popcorn"

<slot ref="popcorn" name="action" :toggle="toggle" :close="close" />

but this breaks Popper.js and only shows the tooltip vertically.

Popper: Invalid reference or popper argument provided. They must be either a DOM element or virtual element.

https://i.sstatic.net/8jhQl.png

Answer №1

I successfully resolved the issue by switching from using 'div' tags to using 'span' tags.

<template>
  <div>
    <span ref="popcorn">
      <slot name="action" :toggle="toggle" :close="close">Default Card title</slot>
    </span>
    <div ref="tooltip" role="tooltip">
      <div :class="[ci-popover, `ci-popover--background-color-${variant}`,`ci-popover--padding-${padding}`]">
        <slot name="default" />
      </div>
    </div>
  </div>
</template>

The outcome of this change can be viewed https://i.sstatic.net/nYn9g.png

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

Encountering errors in Visual Studio when trying to work with node_modules directories that have a tsconfig

In my current project, there is a tsconfig.json file located in the root directory. Strangely, Visual Studio keeps throwing errors related to other instances of tsconfig.json found in different packages, as shown below: https://i.sstatic.net/T7Co2.png Ev ...

There was an error during compilation: Module not detected - Unable to locate './xxxx'

Looking for help with importing a file from another folder into my Next.js project. I need assistance with the correct syntax and paths as I am encountering an error. Here is a link to the screenshot of the error: https://i.sstatic.net/jZ6kk.png Below are ...

Create an eye-catching hexagon shape in CSS/SCSS with rounded corners, a transparent backdrop, and a

I've been working on recreating a design using HTML, CSS/SCSS in Angular. The design can be viewed here: NFT Landing Page Design Here is a snippet of the code I have implemented so far (Typescript, SCSS, HTML): [Code here] [CSS styles here] [H ...

Exclude the extended type of generics in TypeScript

I'm encountering an issue with omit in typescript. Whenever I attempt to omit commandId from TMutationVariables, it triggers a TS error: TS2345: Argument of type 'Pick<TMutationVariables, Exclude<keyof TMutationVariables, "commandId">&g ...

Automatically compile files while performing an npm install or update

I am looking for a way to automatically compile my TypeScript code into JavaScript when another project requires it. For example, when a project runs npm install or updates with my project as a dependency, I want a specific command to be executed after all ...

Exploring the capabilities of Web MIDI in the context of Angular

I am a beginner with Typescript and I am currently working on using Angular2 to develop a Web Midi application. However, I am facing some difficulties in understanding certain errors that I encounter. I believe that I should be placing the Midi functions w ...

A TypeScript function that converts a value into an array if it is not already an array, ensuring the correct type is output

I'm attempting to develop a function that wraps a value in an array if it is not already an array. export function asArray<T extends Array<any>>(value: T): T export function asArray<T>(value: T): T[] export function asArray(value: a ...

Make sure to refresh the state of the store whenever there is a change detected in the input

I am experiencing an input delay problem when trying to update the state of a zustand variable in the onChange event. const BuildOrder = (props: { setOpen: Function }) => { const { almacenes, isLoadingAlmacenes } = useGetAlmacenes(); const { article ...

Guide to utilizing the PWA file manager in conjunction with Vue 3

I am trying to create a custom file extension (.vc2d) that will open in my Vue and Typescript progressive web app. I have set up file_handlers in my web manifest file and used window.launchQueue in my PWA. However, when I double click on the file in File E ...

Unveiling the secrets of the Google Region Lookup API

I am struggling to incorporate the Region Area Lookup feature from Google Maps into my project. Despite it being an experimental feature, I am having difficulty getting it to function correctly. Initially, I attempted to integrate this feature into a Reac ...

Tips for preventing my component from being duplicated during the development process

I found a helpful guide on creating a JavaScript calendar in React that I am currently following. After implementing the code, I successfully have a functional calendar UI as shown below: // https://medium.com/@nitinpatel_20236/challenge-of-building-a-cal ...

Ways to initialize a JSON configuration file for an Angular 2 module without relying on an http.get method

I have a single json file located at the root directory called config.json: { "base_url": "http://localhost:3000" } Within my service class, I am looking to utilize it in this manner: private productsUrl = config.base_url + 'products'; I have ...

What is the best way to ensure that all components can access and utilize the same instance of API

Is there a way to retrieve data from the database using an API when the application starts and then release it once the app is closed, ensuring that the same data instance is available for each component? ...

Guide to adding jquery with typings installation

Need assistance: typings install jquery --global typings ERR! message Unable to find "jquery" ("npm") in the registry. Did you want to try searching another source? Also, if you want contribute these typings, please help us: https://github.com/typings/re ...

Error Found: Unexpected Colon (:) in Vue TypeScript File

Important Update: After thorough investigation, it appears that the issue is directly related to the boilerplate being used. As a temporary solution, it is recommended not to extract the TypeScript file but keep it within the .vue file for now. In a sim ...

Guide on integrating external libraries with Angular CLI

I've been working on incorporating external libraries into my project, and I've been following the instructions provided here. While I know it's possible to use CDNs in my index.html, I'm interested in learning how to do it using TypeS ...

Angular utilizes ZoneAwarePromise rather than a plain String output

I expected the giver code to return a string, but it is returning ZoneAwarePromise. Within the service: getCoveredPeriod() { let loanDetails = this.getLoanDetails().toPromise(); loanDetails.then((res: any) => { const coveredPeriodStart ...

Completing a fetch promise and sending the outcome to a function that is not awaited

I have a function that retrieves data from a Postgresql database and returns it. The expected behavior is to fetch the data using the async function getCat(), process it in const Catalogue, and then return it to a ReactJS component. catalogue.tsx: import ...

The issue with Vuetify v-combobox validation functionality not functioning as expected

I am encountering an issue with my Vuetify(v. 1.9.0) v-combobox. The validation rule I have set requires at least one item to be selected from the menu, but strangely the validation is not being triggered and there are no visible errors in the console. &l ...

Issue when rendering <options> while looping through country object in the country list

To retrieve a list of all countries in my React project written in TypeScript, I am utilizing the countries-list library which can be found here. My intention is to create a <Form> that includes a <Select> dropdown menu populated with the coun ...