When a dropdown menu is clicked, the scrollbar magically vanishes

import { signIn, signOut, useSession } from "next-auth/react";
import { buttonVariants } from "../ui/button";

import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";

export default function SignInButton() {
  const { data: session } = useSession();

  if (session && session.user) {
    return (
      <DropdownMenu>
        <DropdownMenuTrigger className="right-0 outline py-2 px-2 rounded-md">User</DropdownMenuTrigger>
        <DropdownMenuContent>
          <DropdownMenuLabel>My Account</DropdownMenuLabel>
          <DropdownMenuSeparator />
          <DropdownMenuItem>Subscription</DropdownMenuItem>
          <DropdownMenuItem onClick={() => signOut()}>LogOut</DropdownMenuItem>
        </DropdownMenuContent>
      </DropdownMenu>
    );
  }

  return (
    <button className={buttonVariants({ variant: "outline" })} onClick={() => signIn()}>
      LogIn
    </button>
  );
}

I encountered an issue with the dropdown menu where clicking it causes the menu button to move right and the Chrome scroll bar disappears. Is there a way to solve this using Tailwind CSS or any other method?

Answer №1

Here is the solution to your problem:

<DropdownMenu modal={false}>

According to the documentation, the modal is set to true by default, which prevents user interactions with other elements on the page. By setting it to false, users can now scroll through the page while the menu is open.

On a side note, the suggested fix in the global.css file leads to a hydration error and should be avoided.

Answer №2

It was so frustrating dealing with this problem! I struggled with the same issue 😤. The solution is simple - just include a single line of CSS in your global styles:


/* style.css */

#__next {
    @apply h-full;
    overflow-y: scroll;
}

By implementing this, you ensure that the scrollbar remains consistent, preventing any content from shifting unpredictably.

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

Using CSS background-image URL in .NET MVC tutorials

What is the correct way to route to an image in an MVC web application? MVC has default routes, meaning you can access the same page in multiple ways: 1. localhost 2. localhost/home/index However, you can also do it this way, changing the root directory. ...

What is the trick to accessing an object's key and value when you are unsure of the object's

Currently, I am in the process of constructing a React component that is designed to receive an array of objects. However, I have encountered a question: Is there a way for me to retrieve both the key and value of an object within the map function without ...

Issue with Retina display: containing div fails to properly expand to accommodate 1000px width div

As I was preparing to launch a new webpage, I decided to test how it looked on an iPad with Retina display. Unfortunately, the page didn't appear as expected. If you visit the link on an iPad Retina, you can see the issue: The problem becomes apparen ...

Remove 'File' option from the Menu in Tiny MCE

Is there a way to selectively remove the "File" option from the Menu Bar without specifying each individual menu item? https://i.sstatic.net/SFgvi.png I attempted the following method: menu: { edit: {title: 'Edit', items: 'undo redo | cut ...

Dealing with Issues in Projectile Image Display: Solutions for Resolving the Error

I've been attempting to change my projectile from circles to images, but I'm encountering this error File "C:\Users\Habib\Desktop\PYTHONGGAME\py.py", line 353, in <module> bullets.append(projectile(round(player ...

Unwanted bottom padding appears in Bootstrap 4 alerts outside of containers

Struggling to design a sleek fixed bootstrap 4 alert? The issue I'm facing is that the alert displays unwanted bottom padding when it's not placed inside a container. However, since it needs to be fixed and auto-centered, placing it within a con ...

Switch up the Quasar Element's Appearance

I'm currently using the Quasar framework in my application (click here to check it out). Within the "Timeline" function, I have integrated a q-select element for selecting a country. While I successfully fixed the width of the q-select element itself, ...

Link in navigation located above on the page

I am trying to place this line at the top of the page above the navigation links (as shown in the screenshot). In the screenshot it is the line above the Home link. I want the height of the ".navbar-links-" to be 100%. Here is the code for this element: ...

Tips for aligning and emphasizing HTML content with audio stimuli

I am looking to add a unique feature where the text highlights as audio plays on a website. Similar to what we see on television, I would like the text to continue highlighting as the audio progresses. Could someone please provide me with guidance on how ...

What is the best way to locate the position of a different element within ReactJS?

Within my parent element, I have two child elements. The second child has the capability to be dragged into the first child. Upon successful drag and drop into the first child, a callback function will be triggered. What is the best way for me to determi ...

Flexbox properties are being ignored by input fields

Hey there, I'm currently working on a product calculator and need to create 9 input fields organized in 3 rows of three columns. However, when I try to use display: flex and flex-direction: row on the parent div, it doesn't seem to be working as ...

Applying styled text to a Node.js chat application

I developed a chat application using node.js which allows users to enter a username and send messages. The messages are displayed in a <ul> format showing "username: message". I was looking for a way to make the username appear bold and in blue color ...

using javascript to target a specific css selector attribute

I have a CSS file with the following code: .datagrid table tbody td { color: #00496B; border-left: 1px solid #E1EEF4; font-size: 16px ;font-weight: normal; } Is there a way to use JavaScript to dynamically change the font size? The code below worked ...

Tapping on the emphasized hyperlink within an unorganized roster

I am currently working on a page and have encountered an issue. The problem lies in the fact that users must click on a link before they are redirected to the target page. Is there a way to make the highlighted box for each of those links active so it resp ...

Error encountered in React Testing Library: 'removeEventListener' function requires 2 arguments to be executed successfully, but only 1 argument was provided

I have a React class component with an event. constructor(props) { super(props); this.monthRef = React.createRef(); this.yearRef = React.createRef(); this.state = { moIndexActive: props.initialMonth - 1, yeIndexActive: years.f ...

Using innerHTML to replaceAll also modifies characters within the tags

I created a custom function to emphasize specific strings within a text by surrounding them with span tags and updating the content using the innerHTML property of the targeted element. However, I encountered an issue while working with innerHTML instead ...

Attempting to make Navbar vanish as the page size decreases

I am a beginner in html and css and my instructor wants us to create a resume using bootstrap. Bootstrap is designed to provide interactive design that adjusts seamlessly across different devices. I am currently working on aligning elements and I would lik ...

Basic progress bar

I'm attempting to create a basic download bar, but it's only displaying as a solid color without any transition animation. Furthermore, the "repeating-linear-gradient" feature isn't functioning and I'm struggling to figure out why. I&a ...

Is the latest update of Gatsby incompatible with Material UI?

Encountering an issue while running this command portfolio % npm install gatsby-theme-material-ui npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" class= ...

The PHP "include" function seems to be malfunctioning when used inside

Hey there! I'm trying to incorporate an echo statement that includes a variable along with some CSS and an image, but for some reason it's not working as expected. Can anyone lend a hand? <?php if (isset($_POST['sharebutton'])) ...