Having trouble with the Tailwind transition in my Next.js component

I'm facing an issue with the ease out transition not working as expected. I need the side to slide in from left to right with a duration of 500ms. Despite trying various solutions, I can't seem to figure out why it's not functioning properly. Upon inspecting in the dev tool, the transition class is being applied correctly but the effect doesn't display. Here is my code:

    "use client"
import Image from "next/image"
import React, { useState } from 'react'
import profile from '../../assets/images/profile.png'
import { buttonprops } from "@/data/Data";
import NavLinks from "./NavLinks/NavLinks";
import { ButtonType } from "@/types/button";
import { faBars } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

const Navbar = () => {
    const [isVisible, setIsVisible] = useState(false);
    const toggleVisibility = () => {
        console.log("item is being clicked and vlaue of visibie is " + isVisible)
        setIsVisible(!isVisible);
    };

    const handleMouseClick = () => {
        if (isVisible) {
            setIsVisible(!isVisible);
        }
    }

    return (
        <div className="flex flex-row">
            <div className={`flex border border-black `}>
                <div className="flex row border border-black md:hidden">
                    <div className="flex w-44 h-14 border items-center border-black pl-4">
                        <FontAwesomeIcon className="text-3xl" onClick={toggleVisibility} icon={faBars} />
                    </div>
                </div>

                <div className={`md:block w-44 h-screen border border-black text-white ${isVisible ? 'absolute transition w-80 duration-300 ease-in-out' : 'hidden'} `}>
                    <div className="flex flex-col items-center pt-5 pb-10 border bg-slate-200">
                        <Image src={profile} width={500} height={500} className="rounded-full w-32 h-32 border-4  border-blue-500" alt="Picture of the author" />
                    </div>

                    <div style={{ backgroundColor: '#222e50' }} className="flex flex-col h-full ">
                        {buttonprops.map((data, i) => {
                            return <NavLinks key={i} name={data.name} icon={data.icon} />;
                        })}
                    </div>
                </div>

            </div>

            <div onClick={handleMouseClick} className="border border-black w-full h-screen">
                <div className="flex border h-14 w-full border-black items-center justify-center md:hidden">
                    <div className="hi"> Data </div>
                </div>
                <div className="w-full">
                    Content
                </div>
            </div>
        </div>
    )
}

export default Navbar

Answer №1

Avoid conditionally adding the transition class, as it will not activate at the same time as the style changes.

<div className={`md:block w-44 h-screen border border-black text-white transition ${isVisible ? 'absolute w-80 duration-300 ease-in-out' : 'hidden'} `}>
...
</div>

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 is the best approach to incorporating two distinct grid layouts within a single section?

I am attempting to replicate the header-graphic navigation found on this website: It appears that they are not using a grid for the header-graphic area, but rather keeping them separated as 2 divs within their Hero block container. I am interested in recr ...

Looking for straightforward tips on parsing CSS code

Seeking advice on how to extract rules and property/values from a .css file or <style></style>. I am not in need of an elaborate parser, as the validity of selector text, property name, or value is not important. My main focus is ensuring that ...

In Chrome, a horizontally floating item is pushed down, whereas in Firefox it remains in place

What is causing the last item in the submenu to be lower than the rest in Chrome, but aligned in Firefox? Check out this JSFIDDLE with font turned red for visibility View the ACTUAL SITE here I've experimented with padding, margin, vertical align, ...

What is the best way to incorporate media queries in order to reduce the padding around my image?

Currently, I am working on a small gallery and have successfully implemented Salvattore (similar to Masonry). However, a challenge has arisen when resizing the web page - the padding remains at 10px instead of reducing to 5px as desired. The goal is to e ...

What is the process for assigning a value to the body in a div element?

Within a div, there is a body element structured like this: <div id = "TextBox1"> <iframe id = "TextBox1_1"> #document <html> <head></head> <body></body> </html> </iframe> </div> I have attempte ...

My React component seems to be unable to locate and process my CSS file

I am encountering an issue where my React Component is not recognizing my CSS file. Here is the code snippet from my React component: import React, { Component } from 'react'; import './Jumbotron.css'; class Jumbotron extends Compone ...

Setting the flex-direction for <td> elements: A helpful guide

This is a snippet from the render function of one of my components, showcasing a table: return ( ... <td> <div style={{ width: '100%' }}>50</div> {' '} <span clas ...

Tips on solving the Navigation bar burger problem with HTML and CSS

## I am having trouble making my navigation bar responsive using HTML and CSS as the navigation burger does not appear in mobile view ## To take a look at my code on jsfiddle, click here: [jsfiddle] (https://jsfiddle.net/abhishekpakhare/nxcdso7k/1/ ...

What is the best way to ensure that two divs have aligned bottom edges?

I have a set of div containers positioned in different columns within a grid layout. I am looking for a way to identify the containers where the bottom edge is less than 50px higher than any other container, and adjust their heights so they align perfectly ...

Flexbox mystery: How come the entire div isn't displayed when the element below it is hidden?

I am in need of a versatile column layout where multiple widgets are stacked vertically, adjusting their size dynamically. Each widget consists of a title and scrollable content. The last widget should have the ability to collapse when its title is clicked ...

Customizing individual routes with unique background shades using Next.js and Tailwind CSS

Currently, I am in the process of creating a portfolio website using Next.js 13 and Tailwind CSS. My project involves app routing, with a Sidebar component that remains visible on every route. While most pages share a common background color, I need to imp ...

Hooks embedded within utility components

Currently, I am following Ben Awad's lireddit tutorial and trying to implement a utility file for displaying authentication errors throughout the application. Due to potential changes in next/router since the tutorial was created, I am facing challen ...

What is the most dependable method for referencing a CSS class through programming?

Within my Sharepoint project, I am dynamically generating controls in the overridden CreateChildControls() method. I am uncertain which approach is more preferable when it comes to referencing the .css file: protected override void CreateChildControls() { ...

Angular's Motion Module

Incorporating Angular-5 into my project has introduced a plethora of animations on various pages. While the utilization of jQuery provides a straightforward approach for adding and removing classes to DOM elements, it is frequently advised against using jQ ...

The project is experiencing difficulties in loading the Module CSS

Currently, I am working on a React module and have set up a React project to demonstrate the functionality of this module. Initially, everything was working smoothly until I encountered an issue with the webpack configuration related to the CSS loader. { ...

Creating a balanced height for child elements using CSS

If you are looking to display a list of colors with each color occupying an equal fraction of the height, here is how you can achieve it. Imagine presenting four colors in a list with a fixed height and a thick border around it: The example shown above is ...

Having Trouble with jQuery toggleClass

I'm currently working on a project where I have implemented a button that displays a menu when clicked. I am attempting to change the color of the button when it is active, however, the toggleClass function is not behaving as expected. Below is the co ...

The visit log on Firebase for Google Analytics is not showing up

After deploying my Next.js app to Vercel with Google analytics for Firebase integrated, I noticed that the visit log in my Firebase console only appears after refreshing the site, not during the first visit. app.tsx import type { AppProps } from "nex ...

What is preventing me from applying styles to the first word in my Angular ngFor iteration?

I'm currently attempting to customize the initial word of a string within my Angular ngFor loop. Strangely, the class gets applied but the style defined in my CSS file is not. Inline styling also does not seem to work - any ideas why? This is the CSS ...

Jest in combination with Next/Dynamic is causing an error that is not supported

While working on testing for my component, I encountered an error involving the use of: ... const Rating = dynamic(import('components/Rating')); ... In addition, I am utilizing jest-next-dynamic: beforeAll(async () => { await preloadAll() ...