Dialog component from HeadlessUI doesn't support the Transition feature

Currently working with Next.JS version 14.1.3

I recently integrated the <Dialog> component from HeadlessUI and configured TailwindCSS. However, I encountered an issue where the Modal window doesn't have any transition effects even though I followed all the steps outlined in the example

CODE

Modal.tsx:

type TProps = {
   isOpened: boolean;
   onClose: VoidFunction;
   children?: ReactNode;
};

export const Modal = ({ isOpened, onClose, children }: TProps) => {
   return (
      <Transition show={isOpened} as={Fragment}>
         <Dialog as="div" className={s.modalWrapper} open={isOpened} onClose={onClose}>
            <Transition.Child
               as={Fragment}
               enter="ease-out duration-300"
               enterFrom="opacity-0"
               enterTo="opacity-100"
               leave="ease-in duration-200"
               leaveFrom="opacity-100"
               leaveTo="opacity-0"
            >
               <Dialog.Overlay className={s.backdrop} />
            </Transition.Child>

            <Transition.Child
               as={Fragment}
               enter="ease-out duration-300"
               enterFrom="opacity-0 scale-95"
               enterTo="opacity-100 scale-100"
               leave="ease-in duration-200"
               leaveFrom="opacity-100 scale-100"
               leaveTo="opacity-0 scale-95"
            >
               <Dialog.Panel className={s.modal}>{children}</Dialog.Panel>
            </Transition.Child>
         </Dialog>
      </Transition>
   );
};

and this is how it is implemented (if relevant):

AddProduct.tsx:

'use client';

import { useState } from 'react';

import { PlusIcon } from '@/icons';

import s from './AddProduct.module.scss';

import { AddProductModal } from './AddProductModal';

export const AddProductCard = () => {
   const [modalOpened, setModalOpened] = useState<boolean>(false);

   return (
      <>
         <div className={s.addProductCard} onClick={() => setModalOpened(true)}>
            <PlusIcon className={s.plusIcon} />
         </div>

         <AddProductModal
            modalOpened={modalOpened}
            onClose={() => setModalOpened(false)}
         />
      </>
   );
};

Notably, the usage of <Transition> and <Transition.Child> components was included

Additionally, here are details from tailwind.config.js:

/** @type {import('tailwindcss').Config} */
module.exports = {
   purge: ['./src/**/*.{js,ts,jsx,tsx}'],
   content: ['./src/**/*.{js,ts,jsx,tsx}'],
   theme: {
      extend: {},
   },
   variants: {
      extend: {},
   },
   plugins: [],
};

Moreover, postcss, tailwindcss, and autoprefixer have been properly installed on the system

Answer №1

After some investigation, I discovered that <Transition> can be successfully implemented by adding the following lines to your CSS file:

@tailwind base;
@tailwind components;
@tailwind utilities;

Since I am working with SCSS, all I had to do was change from using .module.scss to .scss. This not only maintained my CSS file structure, but also preserved my mixins and allowed the transition effect to work flawlessly.

Furthermore, when attempting to utilize these @tailwind directives within module.scss, an error is thrown stating that @tailwind is not pure selector. Therefore, it is imperative to make the switch from .module.scss to .scss.

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

Characteristics of JSON data containing quotation marks within the property values

Is it possible to include JavaScript functions in JSON like the example below? My JSON library is struggling to process this structure because of the quotations. How can I address this issue? I specifically need to store JavaScript functions within my JSON ...

Chrome on IOS: Experiencing screen freezing while scrolling

1) I'm working with Material UI in React JS. I have added a simple scrollable code, but when I reach the bottom of the screen/scroll, it freezes. 2) I also tried it with a simple HTML page and it worked correctly. <div style={{ ...

What is the best way to retrieve a value from an object using a promise after a certain period of time

During an event, I receive a user object. When I try to access the user._properties.uid value before using setTimeout, it returns as undefined. However, when I implement setTimeout, the value is successfully fetched after a few seconds. Is there a way to ...

When choosing the child option, it starts acting abnormally if the parent option is already selected in Angular

I am encountering an issue while trying to select the parent and its children in the select option. The concept is to have one select option for the parent and another for the child. I have parent objects and nested objects as children, which are subCatego ...

Converting CSS code into JavaScript

I am currently working with the following code: .mr15 > * margin-right: 15px &:last-child margin-right: 0 I need help translating this code to Javascript. Should I use JQuery or pure Javascript for this scenario? Thank you. ...

Combining strings with objects in Javascript: A step-by-step guide

In the code snippet provided, I am combining variables to create a path to another existing object and its attribute. The issue is that I always receive a string, but I would like to somehow convert it into an object. // SET CUSTOM CONTENT FOR COLUMN IF ...

Make a request to the local API in a React Native mobile app by sending a GET request

Currently, I am working on a mobile application using React Native and utilizing SQL Server and NodeJS. The API for this project is located in my localhost. Upon running the application on an emulator, I encountered an issue when attempting to make a reque ...

JavaScript Subscribe / Unsubscribe Button

I am trying to create a simple JavaScript program that allows users to like and dislike content. However, I am new to JavaScript and finding it a bit challenging. Basically, when the user clicks on the Follow button, the "countF" variable should increase ...

Setting a variable in a v-tab using Vuetify now only takes 2 easy clicks!

I'm currently utilizing Vuetify and vuejs to develop a tab system with 3 tabs. The tabs are being switched dynamically by binding to the href of a v-tab. Each time I click on a tab, the value of the speed variable is modified. However, I'm encoun ...

Inform the Angular2 Component regarding the creation of DOM elements that are placed outside of the

The Challenge In my Angular2 project, I am using Swiper carousel and building it with Webpack. However, Angular2 adds random attributes like _ngcontent-pmm-6 to all elements in a component. Swiper generates pagination elements dynamically, outside of Ang ...

Enhance Your Webpage with jQuery Drag and Drop Feature Across Multiple Lists

I've been successfully using "jQuery UI Sortable connectwith" for drag & drop functionality, as shown in the example here: . However, I now need to implement drag & drop with multiple UI elements and it's not functioning correctly. Example: < ...

Displaying a hand cursor on a bar chart when hovered over in c3.js

When using pie charts in c3js, a hand cursor (pointer) is displayed by default when hovering over a pie slice. I am looking to achieve the same behavior for each bar in a bar chart. How can this be done? I attempted the CSS below, but it resulted in the h ...

Is there an rxjs operator that includes both on-next and on-error callbacks?

Is there a similar function to promise.then(onNextCallback,onErrorCallback) in rxjs that I can use? I've already tried alternatives like pipe(concatMap(),catchError) but they are not what I am looking for. ...

Properly handling curves in THREE.JS to ensure efficient disposal

I am facing a challenge with managing memory in my project. I have a dynamic sphere with moving points on it, and I am creating curves to connect these points. Here is an illustration of the process: https://i.sstatic.net/PGWuU.jpg As the points are cons ...

Utilize switchMap to sequence calls

My goal is to execute rest requests sequentially using switchMap(...) from RxJs. Here is the object: export class Transaction { constructor( public id: string, public unique_id: string, public name: string, public status: string, pu ...

Combining Nested Objects in MongoDB

I have searched extensively for a solution but I am struggling to find a resolution to my issue. I have two MongoDB (Node.JS) collections: user & statistics. My goal is to merge the results using aggregate. Below are the structures of the collection ...

The collision function is currently not functioning properly, causing a hindrance in movement. There are no other codes restricting movement

const rightPressed = false; const leftPressed = false; const upPressed = false; const downPressed = false; const players = []; players[0] = new victim(1234); const arrayw = 50; const arrayh = 50; const canvas = document.getElementById("myCanvas"); const ...

Determining the client web app version in HTTP requests

We frequently update our single page application, but sometimes an older version with a bug can still be in use. It would be helpful if the client could include a version identifier with requests to let us know which code base is being used. Are there est ...

In what way can data be retrieved from within a useEffect block externally?

Essentially, I'm facing an issue with retrieving data from the DateView component in my ChooseCalendar component. The code that retrieves this data is located within a useEffect block due to passing a dateType variable as part of a useState to the com ...

jQuery fails to operate on products loaded through AJAX requests

Upon opening the page, jQuery functions correctly. However, when a product is loaded or changed via AJAX, jQuery stops working. I am currently using jquery-1.7.1.min.js $(document).ready(function () { $screensize = $(window).width(); if ($screensi ...