ReactStrap: Issue with displaying an elongated dropdown menu within a table cell

I am facing an issue with a dropdown menu embedded inside a table:
https://i.sstatic.net/iOusF.png

The dropdown list is quite long with 16 items. However, when I try to scroll down to access the last items, the entire table scrolls down along with the dropdown list. This makes it difficult to reach the end of the list and results in a messed-up UI.

Here is the code for the dropdown list:

const statusDropDown = (
      <Dropdown
        isOpen={this.state.statusUpdateDropDownOpen}
        toggle={this.toggleStatusUpdateDropDown}
        // scrollable={true}
      >
        <DropdownToggle className="my-dropdown" caret>
          {this.state.statusUpdateDropDownValue}
        </DropdownToggle>
        <DropdownMenu>
          {Object.entries(listeDesStatus).map(([key, value], i) => {
            console.log("INSIDE TABLE, value is");
            console.log(value);
            return (
              <DropdownItem
                key={i}>
                <div value={key} onClick={this.changeStatusUpdateDropDownValue}>
                  {value}
                </div>
              </DropdownItem>
            );
          })}
        </DropdownMenu>
      </Dropdown>
    );

This dropdown list is rendered within the table like this:

 <tbody>
{Object.entries(this.state.operationSavInformation).map(
  ([key, value]) =>
    key !== "id" &&
    (key === "Status" ? (
      <tr key={key}>
        <td>{key}</td>
        <td>
          {statusDropDown}
        </td>
      </tr>
    ) : (
      <tr key={key}>
        <td>{key}</td>
        <td>
          <strong>{value}</strong>
        </td>
      </tr>
    ))
)}
</tbody>

After some research, I found that setting a fixed height for the dropdown list might resolve this issue:

 const statusDropDown = (
  <Dropdown
    isOpen={this.state.statusUpdateDropDownOpen}
    toggle={this.toggleStatusUpdateDropDown}
    // scrollable={true}
  >
    <DropdownToggle className="my-dropdown" caret>
      {this.state.statusUpdateDropDownValue}
    </DropdownToggle>
    <DropdownMenu style={{ maxHeight: "28px" }}>
      {Object.entries(listeDesStatus).map(([key, value], i) => {
        console.log("INSIDE TABLE, value is");
        console.log(value);
        return (
          <DropdownItem
            key={i}>
            <div value={key} onClick={this.changeStatusUpdateDropDownValue}>
              {value}
            </div>
          </DropdownItem>
        );
      })}
    </DropdownMenu>
  </Dropdown>

The result can be seen here:
https://i.sstatic.net/d4zAv.png

Although this has partially resolved the issue by allowing access to the last items in the list, it has caused unexpected behavior with the first element. What I actually want is to fix the height of the dropdown list and make it scrollable so that only two items are displayed, and users can scroll down to view the rest. Is this possible?

Answer №1

One way to solve this issue is by setting a max-height and applying overflow: scroll to the dropdown menu.

.really-tall-menu {
  background: blue;
  max-height: 200px;
  overflow: scroll;
  width: 80px;
}
<ul class="really-tall-menu">
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
  ...
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
</ul>

Answer №2

To achieve the desired effect, include the following style: maxHeight: 28px; overflow: scroll; within your DropdownMenu element.

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 happens to the parent scope in Javascript when declaring a subclass and why does it get overridden?

I have two classes in JavaScript, with one inheriting from the other. The structure is as follows: var Parent = (function(){ var self; var parent = function(){ self = this; self.type = 'Parent'; }; parent.protot ...

Using jQuery to retrieve the nth child from a table after dynamically creating it with AJAX

When using AJAX in the code below, I fill and create simple data after retrieving it. $.ajax({ method: 'GET', url: '/analyzePage/searchTag/' + tagName, contentType: false, processData: false, success: function (data ...

Using CSS to overlay a background image on top of a background gradient

Struggling to get both a background gradient and a background image (transparent PNG) to display in my div. No matter what, only the color gradient shows up while the image remains hidden. If I use a solid color instead of a gradient, the image displays ju ...

I relocated the navigation HTML code to a new file and as a result, the JavaScript functionality is

After successfully implementing the hamburger icon animation in my navbar using JavaScript, I decided to move the nav code to a separate file for better organization. However, the decision resulted in an error where clicking on the burger icon returned a m ...

What is the best method for automatically filling in the grid-cols-x property in tailwindcss grids

Currently, I am in the process of developing a page using NextJs and TailwindCss. In this project, users have the ability to upload an image from their local device and specify the number of pieces they would like the image to be split into horizontally an ...

Is the AngularJS application failing to transmit data accurately to Node.js?

I've been grappling with this issue for a few days now and I can't seem to pinpoint the problem. As someone relatively new to the MEAN stack, I might be overlooking something obvious. I followed the boilerplate code from mean.io for both the back ...

Parsing error encountered while trying to handle an unexpected token at line 214, character 33. It appears that an appropriate loader is missing to process this particular file type

I've been developing a Typescript React project for the past few months without any issues. However, things took a turn yesterday when I decided to run npm audit fix and npm audit fix --force in order to address some security concerns that appeared ou ...

Redirect to a specific webpage depending on a certain condition

I currently have a home page set up and now I would like to create a homePlus page that is controlled by a localStorage variable called alreadyShown. The concept is that once the homePlus page is shown for the first time, we will change the value of alread ...

Having trouble with *ngif not functioning properly after initial click in Angular 6

How do I create a Select field in Angular 6 that will hide or display another div based on the selected value? Below is the code snippet: <div class="form-group"> <label for="servicePriviledges">Managed</label> < ...

Tips for updating the values of 'Sec-Fetch-Dest', 'Sec-Fetch-Mode', 'Sec-Fetch-Site', and 'Sec-Fetch-User' using Axios

I'm having trouble figuring out how to set specific values for the 'Sec-Fetch-Dest', 'Sec-Fetch-Mode', 'Sec-Fetch-Site', and 'Sec-Fetch-User' headers when making a request through an axios instance in Vue. Unfo ...

Utilizing server-side caching middleware with tRPC version 10

Currently, I am working on a Next.js project and exploring the possibility of incorporating in-memory caching for tRPC results. Each tRPC procedure should have the option to set a custom TTL for caching purposes. My initial thought is that utilizing tRPC&a ...

What is the best way to utilize purgeCss in conjunction with other module exports?

After reading the documentation, I want to integrate purgeCss into my NextJS project. The recommended configuration in the docs suggests updating the next.config.js file like this: module.exports = withCss(withPurgeCss()) However, I am unsure where exact ...

Issues with browser tab icon disappearing upon being pushed to Github for a Vue project

I'm facing an issue where my browser tab icon is not showing up after I push my repository to GitHub. Interestingly, it shows up perfectly fine when I test it on localhost. On the left is my website hosted on GitHub, while on the right is my website ...

Ways to achieve combined outcomes using ng-repeat

Check out this plunker. <div ng-repeat="subCategory in subCategorys | filter:{tags:tag}:true | orderBy:'id'"> {{subCategory.id}} {{subCategory.name}} {{subCategory.tags}} <br/><br/> The detailed information of ...

Error Handling with Node.js Sequelize RangeError

Currently, I am in the process of setting up a table to store user sessions. Specifically, I plan to save the IP address as an integer and have been exploring various methods for achieving this. You can find more information on this topic here: IP-addresse ...

"Encountered a problem while setting up the Mailgun webhook to handle both multipart and URL encoded

I have been working on creating a web hook listener for Mailgun, and I encountered an issue when I realized that Mailgun can post webhooks using either multipart or x-www-form-urlencoded content-types. Currently, my code uses Multer to handle multipart b ...

Leveraging window environment variables for displaying or hiding a React component

Is it a viable option to display or hide a React component using window.env? For instance, imagine we have a feature that is not yet ready for release, and we are considering hiding it by setting window.env.FEATURE_ENABLED=0 (these variables will be fetch ...

The left side of my image doesn't quite reach the edges of the screen as desired

Even after setting the padding and margin in the parent container to 0, the image is still not filling to the edges. Here is the image. This snippet of code shows my JavaScript file: import styles from './css/Home.module.css'; export default fun ...

Using the ampersand symbol '&' in Sass to target the body tag with a particular class applied

Demo: https://codepen.io/moradxd/pen/WJpPyQ Consider this sample HTML code: <body class="boxed"> <div class="text-white"> <a href="#" class="btn-featured">Button</a> </div> </dody> I am implementing the follow ...

Ways to determine the current page I am viewing

I am working with a list of tabs and I need to track my current location every time I click on a specific tab. My MainCTRL controller, which is the parent of all tab controllers, needs to be aware of the active tab at any given moment. I attempted to use n ...