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?

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

What can be used instead of makeStyles in Material UI version 5?

My journey with Material UI version 5 has just begun. In the past, I would utilize makestyles to incorporate my custom theme's styles; however, it appears that this method no longer works in v.5. Instead of relying on {createMuiTheme}, I have shifted ...

I would like to share tips on integrating React.js with a backend through React Hooks and the process of deploying the application on Heroku

Looking to integrate the React front-end framework with my backend express.js and EJS using React Hooks. I am familiar with using app.get() in Express for handling server requests, but unsure how to coordinate that with starting a React server on localh ...

How can I silence the warnings about "defaultProps will be removed"?

I currently have a next.js codebase that is experiencing various bugs that require attention. The console is currently displaying the following warnings: Warning: ArrowLeftInline: Support for defaultProps will be removed from function components in a futur ...

`Div Elements Overlapping`

Lately, I have been working on my personal portfolio and I encountered an issue with the contact form overlapping the footer. Can anyone provide some guidance on how to resolve this? Any help is greatly appreciated. https://i.stack.imgur.com/neIbs.gif ...

Custom Sign-in features in NextJS now direct users to the default form for entering login

I have been working on a web app that requires authentication using NextJS default auth middleware. However, whenever I try to log in, the app redirects me to the default NextJS form component at the URL /api/auth/signin?error=CredentialsSignin. Even thou ...

Prioritize the Menu display

Is there a way to bring the menu's black background in front of the body text in the image below? Here is the JSFiddle link for reference: https://jsfiddle.net/johnking/j58cubux/6/ The issue occurs when scrolling down and the menu is not clearly vi ...

What are some techniques for managing scrolling within a particular element?

I am currently working with Vue.js and utilizing Element UI components. I want to incorporate a scroll management function to achieve infinite scrolling. To better understand, please refer to the screenshot in the Example section: Despite trying differen ...

How to create a dynamic background color animation in jQuery similar to a progress bar animation

I have a container with text content (for example: My Name) and it is displayed in a RED background color along with a button. What I am looking for : When the button is clicked, I want to change the background color of the container from RED to BLUE, si ...

Moving smoothly while retaining absolute positioning

I have a question about a particular scenario. I have a div element that is styled like a ball and I want it to transition diagonally across the page to the bottom right corner instead of moving suddenly. However, this is not happening as expected. Can you ...

transferring information from the client to the MySQL database

I am facing an issue while attempting to send form data from a React application to a MySQL database using Node.js and Express.js. Currently, I am not receiving any errors or data. Below is the server-side code: app.use(express.urlencoded({ extended: true ...

Bootstrap CSS: arranging columns for mobile devices

UPDATE: Having implemented the solution provided in the accepted answer below, I find myself back at square one with the original layout before any adjustments were made. The issue still remains unresolved. Any advice on how to achieve the desired design o ...

Task: Relocate files within the create-react-app template to the main directory after installation

Looking for some help with a unique situation involving my project: I am currently working on a customized template based on create-react-app that incorporates both electron and redux. The goal is to relocate webpack and babel config files from the curre ...

What is the best way to target specific elements within my array using Jquery?

I have a Wordpress website where the posts contain images with the .aligncenter class. I want to style the images that are less than 400px in width by adding the display:inline-block; property and reducing their size to 40%. Here is the approach I tried: ...

What is the process for including or excluding a class from a horizontal scrollbar?

I've been trying to implement a back to top button on a horizontally scrolling page. However, I'm encountering difficulties in adding or removing the necessary class to show or hide the button. Here's the JavaScript code I'm using: $( ...

Send all requests made to /api/.. to express

I have configured an nginx server with a react app as the frontend and an express server serving as the backend. The express server is running on localhost:5000/ server { listen 80 ; server_name siteurl; server_name siteip; # SSL con ...

What is the best way to establish the primary color for the entire app?

Is there a way to easily set the color for @react-native-material/core's theme? I managed to change the color but I don't want to have to do it individually for each component. ...

Ensuring that a Box retains its visual appeal even as the screen size fluctuates within MaterialUI in ReactJS

Struggling with a minor yet bothersome issue related to an Avatar within my MaterialUI sidebar. Trying to maintain the proportion of this wrapped Avatar image(Link: https://i.stack.imgur.com/lt1Lj.png) as the screen size changes, but it slowly disappears ...

Adjust the size of a div element after updating its content using Mootools

I am currently utilizing mootools 1.2 on a basic webpage. There is a div that contains a form (referred to as formdiv) which is submitted through JS/ajax. Once the ajax request returns a "confirmation message" data, the formdiv updates accordingly. The is ...

Notifying Users of Payment Updates

In the process of developing our application, we integrated a Payment gateway called flutterwave. Every time a payment is successful or fails, a webhook is triggered which prompts us to send notifications through emails, SMS, and update payment statuses in ...

Issue encountered with the Custom Icon feature within the Switch Component

Every time I attempt to utilize the custom icon prop, I encounter the following error: index.js:1406 Warning: Failed prop type: Invalid prop icon supplied to ForwardRef(Switch), expected a ReactNode. I have experimented with various solutions but have bee ...