Do not insert a MUI divider after the final item in the menu

Is there a way to remove the divider after the last category when using MUI components and adding a divider after each category?

https://i.sstatic.net/Gx0Zb.png

This is my code with the divider right at the bottom before the closing tag.

    export const MenuItemGroup = ({ label, items, menuVariant, onItemClick }: MenuItemGroupProps) => {
  return (
    <Box>
      <>
        {label !== undefined && label !== null ? (
          <Box sx={{ margin: '16px', marginBottom: '8px' }}>
            <Typography variant="body2medium" sx={{ color: 'var(--sds-ref-color-base-black70)' }}>
              {label}
            </Typography>
          </Box>
        ) : (
          <></>
        )}
      </>
      <>
        {items &&
          items.map((item, itemIndex) => {
            return <MenuItem key={itemIndex} item={item} menuVariant={menuVariant} onItemClick={onItemClick} />;
          })}
      </>
    </Box>
  );
};

const MenuGroupSection = ({ label, groups, menuVariant, onItemClick }: MenuGroupSectionProps) => {
  return (
    <Stack direction="column" sx={{ display: 'flex', width: '100%' }}>
      {label !== undefined && label !== null ? (
        <>
          <Box sx={{ margin: '16px', marginBottom: '8px' }}>
            <Typography variant="body2semibold" sx={{ color: '#000000' }}>
              {label}
            </Typography>
          </Box>
        </>
      ) : (
        <></>
      )}
      <Stack direction="row" sx={{flexWrap: 'wrap', display:'grid' , gridTemplateColumns : 'auto auto' }}>
        {groups &&
          groups.map((group, index) => {
            return (
              <MenuItemGroup
                key={index}
                label={group.label}
                items={group.items as MenuItemNode[]}
                onItemClick={onItemClick}
                menuVariant={menuVariant}
              ></MenuItemGroup>
            );
          })}
      </Stack>
      <Divider sx={{ marginLeft: '16px', marginRight: '16px' }} />
    </Stack>
  );
};

Answer №1

To accomplish this, you can send a prop to the MenuGroupSection component that specifies whether it is the final section:

const MenuGroupSection = ({ label, groups, menuVariant, onItemClick, isLast }: MenuGroupSectionProps) => {

Then, display the Divider only if it is not the last one:

{!isLast ? <Divider sx={{ marginLeft: '16px', marginRight: '16px' }} /> : null}

Do you think this approach would suit your requirements?

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

Caution: The attribute name `data-*` is not recognized as valid

I am attempting to import an SVG file in my NEXT.js project using the babel-plugin-inline-react-svg. I have followed all the instructions and everything is functioning perfectly. // .babelrc { "presets": ["next/babel"], "plugin ...

Set the style properties of one class to match the style properties of another class using JavaScript

I need to dynamically create a div using the Bootstrap panel for displaying it. The div's class will either be "panel panel-success" or "panel panel-danger" based on the server response, which can be either "success" or "failure." To assign the class ...

Attempting to modify the background color of an iFrame in Internet Explorer

I am experiencing an issue with my webpage where the iFrame is displaying with a white background in IE, while it shows up with a blue background in Firefox and Chrome. I have attempted various solutions to make the background of the iframe blue or transpa ...

The cube mesh is failing to render inside the designated div

I created a Torus and Cube Mesh in my scene, but I want the cube to be positioned at the bottom right corner of the screen. Here's what I tried: <div style="position: absolute; bottom: 0px; right:0px; width: 100px; text-align: center; "> & ...

AngularJS Toggle Directive tutorial: Building a toggle directive in Angular

I'm attempting to achieve a similar effect as demonstrated in this Stack Overflow post, but within the context of AngularJS. The goal is to trigger a 180-degree rotation animation on a button when it's clicked – counterclockwise if active and c ...

`Issues with CSS/JQuery menu functionality experienced in Firefox`

After creating a toggleable overlay menu and testing it in various browsers, including Internet Explorer, everything seemed to work fine except for one major issue in Firefox (version 46). The problem arises when toggling the overlay using the "MENU" butt ...

The transfer with ipcRenderer.postMessage in Electron has encountered an invalid value

I encountered an issue with the message Invalid value for transfer when attempting to utilize the message-ports-reply-streams feature for the first time. In my preload.js file, I defined the following api: contextBridge.exposeInMainWorld( "api&quo ...

Tips for maintaining the footer at the bottom of the page regardless of the screen size

In my current project, I am dealing with several web pages. For each page, I have arranged three div tags: Header Body (content) Footer The issue arises when it comes to the body div tag, which houses the main content of a page such as forms and descrip ...

Can <option> tags be arranged side by side using CSS?

Here is a form I am working with: <form action="file.php" method="GET"> <input type="hidden" name="page"> <select> <option>Text 1</option> <option>Text 2</option> <option>Text 3 ...

Creating a CSS template for organizing sidebar and footer divisions on a webpage

I am facing an issue with the layout of my website. I have a container that is positioned relatively and houses various divs for header, sidebar, main-content, and footer. The problem lies with the sidebar and footer components. The sidebar has been posit ...

Creating a hover effect for displaying image masks

My website features a profile page displaying the user's photo. I am attempting to create a functionality where when the user hovers over their photo, a transparent mask with text appears allowing them to update their profile picture via a modal. How ...

Tips for optimizing server requests in NextJS or React to prevent unnecessary multiple requests

I am currently working on a side project and I have an inquiry regarding the frontend authorization flow I need to design. The technology stack I am using includes Next.js, Express, and MDB. One of the challenges I am facing is implementing authorization ...

React not properly updating state variable with setState

I am facing an issue while attempting to assign the response data from an API call to a state variable. There is an array called 'divisions' in the 'responseJson' object that I am trying to set to the 'divisions' array in the ...

Chrome is failing to set the cookies that are being sent

I have tried numerous combinations and looked at similar questions, but nothing seems to be working for me. Just to clarify, I am running everything on localhost. regUser = () => { var username = getE("username-input").value; var e ...

Is there a way to retrieve the input value of a TextField in Material UI without relying on the onChange event?

Instead of using this.refs.myField.getValue() or this.refs.myTextField.input.value, which are deprecated, I am looking for an alternative solution. I prefer not to use the onChange event inside the TextField component but convert the text when the user cl ...

Developing a custom mixin to alert a banner at the top of the webpage

I currently have a feature on my website that triggers a pop-up notification whenever a message is received from another user. The pop-up consists of a div displaying the content of the message along with a close button. After exploring various methods to ...

Exploring the intricacies of MUI spacing, such as utilizing the `Box` component with `py={[5, 5, 10]}` to achieve desired padding levels

In the code snippet <Box component="section" py={[5, 5, 10]}>, what does the [5, 5, 10] signify? I know that 'py={5}' denotes padding of 5 units for top and bottom. But what is the significance of the array '[5, 5, 10]'? ...

Using Tailwind classes as a prop functions correctly, however, it does not work when directly applied

Here's a component snippet I'm working on: export const TextInput = ({ label, wrapperClassName = "", inputClassName = "", labelClassName = "", placeholder = "", ...props }: InputProps & Fiel ...

Tips for accessing subdocument data from Mongoose in the frontend using ReactJs

I am looking to retrieve comprehensive information about a collection known as "commercant", which includes another collection called "personne" in the front end using ReactJs. Although Postman returns all data, the front end is struggling to interpret the ...

Does the Error page in Next JS 13 fail to properly manage fetch API errors?

After referencing the documentation for Next.js with app router, I followed the instructions to create an error.tsx page within my app folder (app/[lang]/error.tsx). This file contains the code provided in the docs. Additionally, I included some API calls ...