Creating tooltips using React and Tailwind CSS

I'm currently working on creating tooltips for icons in my header. I have created a component that combines the icon and tooltip into one div, with Tailwind CSS styles applied.

JSX Component:

const HeaderIcon = ({ icon, redirect = window.location.pathname.replace('/', ""), text = ""}:IconProps) => (
        <div className="group relative flex items-center justify-center h-12 w-12 mt-2 mb-2 mx-5 cursor-pointer">
            <button onClick={() => goto(redirect)} className="items-center inline-flex">{icon}</button>
            <span className="group-hover:visible absolute rounded-md shadow-md text-white bg-gray-900 text-xs font-bold transition-all duration-100 p-2 text-center min-w-max invisible">
                {text}
            </span>
        </div>
    )

The 'goto' function is used for redirection, the 'icon' variable contains a JSX element from react-feather (an icon library), 'redirect' is a string specifying the redirection path, and 'text' represents the tooltip text. Which Tailwind classes should be applied to position the tooltips centered under the icons?

If you have any additional requirements or questions, please feel free to ask and I will make the necessary edits to the code.

Answer №1

To enhance the functionality of the plugin visibility in Tailwind, you should define a new variant called group-hover in the configuration file:

// tailwind.config.js
module.exports = {
  // ...
  variants: {
    extend: {
      visibility: ['group-hover'],
    }
  },
}

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

Align labels on top and inputs at the bottom using Bootstrap

I'm facing an issue with alignment in my form using Bootstrap 4.4. Whenever a select element is included, it disrupts the layout by breaking the alignment of labels and inputs on the same row. Is there a way to always keep the labels at the top and t ...

What is the best way to remove an S3 object from a bucket within a Next.js application?

This marks my first experience with AWS S3. I am currently in the process of saving images (jpg/png etc.) on S3 and storing the URL in a database. The application is designed to track the user's session along with the S3 URL when they submit a picture ...

Tips for showcasing a non-editable list with material-ui

Is there a way to create a summary page with multiple items, including a list that resembles a select element but is not selectable? I attempted using a select element with various properties set, such as multiple, native, readOnly, and rows={8}, but the ...

"Exploring the World of Mobile Development and Screen Size

Currently, I am in the process of creating a basic mobile website that can be accessed through a QR code leading to the page linked below. However, I have encountered an issue where viewing it on my Android or Apple phone results in excess width. Any advic ...

Conflicting styles between Bootstrap and Formstack are causing radio buttons to appear only partially visible

Encountering a conflict between Bootstrap (4.1.3) and Formstack CSS when trying to embed a form in a website. The radio buttons are not fully visible, with the issue located in the "label" class ("fsOptionLabel"). Adjusting the line height provides a parti ...

My custom CSS being overridden by Bootstrap styles

I'm currently working with Twitter Bootstrap's CSS, but it seems to be overriding some of my custom classes. Initially, I placed it before my own CSS in the HTML header (I am using jade and stylus template engines): doctype html html head ...

How can I show the real width of an image on a mobile device?

I have integrated the infinite slide plugin from jQueryscript.net into my website. While it works perfectly on desktop with background images, I am facing an issue on mobile devices where the image width needs to be displayed in full. I attempted to adjust ...

What is the best approach to ensure I wait for the next-auth session before utilizing useQuery()?

My NextJS project utilizes NextAuth for session management and React Query for data retrieval on the front-end. However, currently, the useSession() function returns undefined while checking if the session is authenticated. This undefined value is then us ...

What is the process of incorporating a video into a react.js project through the use of the HTML

I'm experiencing an issue where my video player loads, but the video itself does not. Can anyone shed light on why this might be happening? class App extends Component { render() { return ( <div className="App& ...

Is there a way to modify the style when a different rarity is selected in Next.JS?

Is there a way to change the style depending on the rarity selected? I am currently developing a game that assigns a random rarity upon website loading, and I am looking to customize the color of each rarity. Here is how it appears at the moment: https:/ ...

Prevent tooltips from displaying outside of an HTML table by using the overflow hidden property for horizontal scrolling

TL;DR: Struggling to position and display tooltips in a table due to the constraints of overflow: hidden. An example has been created to demonstrate the issue with tooltips not displaying correctly within a table. The problem arises because the table nece ...

Error: Unable to use map function on users .. cannot perform mapping on functions

Initially, the map function in my code was working fine. However, suddenly an error started appearing when I included the users.map line. Surprisingly, if I comment out that line, the code works perfectly again. Even more strangely, if I uncomment it, ev ...

Having trouble establishing a connection with mapDispatchToProps

How can I correctly pass an action to the reducer from my component? Here is my code snippet: import React, { Component } from 'react'; import { Text, View, Button} from 'react-native'; import { connect } from 'react-redux'; ...

Is it possible for me to override the redirect feature of Google Optimize manually and bypass the need for

I am currently conducting A/B redirect experiments using Google Optimize on a platform built with React and Redux. One challenge I am facing is the need to avoid full page reloads when redirecting to new pages. Instead, I would prefer a manual approach th ...

The typography text exceeds the boundaries of the Material-UI CardContent

In the React Material-UI framework, I am working with a CardContent component that looks like this: <CardContent className={classes.cardContent}> <Typography component="p" className={classes.title} variant="title"> {this.props.post.title ...

Struggling to make the height attribute work in Bootstrap 4 alpha

I'm currently in the process of learning Bootstrap, and I've encountered an issue with the height attribute in version 4 (for example: "row h-25") not functioning properly. I attempted to add another CSS rule that sets the height of "container-f ...

Making the height of two divs equal within the same parent element using CSS

Looking for a way to make two adjacent divs, #innerwrapper .sidebar and #innerwrapper > .content, from the same parent container, #innerwrapper, have equal heights due to them being floated left. I initially used jQuery in a separate file to resolve th ...

Problem encountered when attempting to dynamically add an Option element to a Select element using ReactJS

My project is nearly complete, but I am facing a small bug in my dynamic dropdown box. Whenever a new expense is added to the list, the corresponding year is supposed to be added to the options tag within the select tag in the FilterExpense.jsx file. Howev ...

SASS causing conflicts with CSS breakpoints selector overrides

I am working with a partial file named _display.scss. It includes various @mixin and styling classes related to the display CSS property. _display.scss @mixin d-block{ display: block; } @mixin d-none{ display: none; } .d-block{ @include d- ...

Is it possible to use a full-width material-ui Button inside a Badge component?

Within a grid, I had initially used fullWidth on a Button to make it expand and fill the container. Everything was functioning correctly until I enclosed the Button in a Badge element. Now, the fullWidth property is not being applied, and the button rever ...