Creating a full-width menu with Material UI - a step-by-step guide

I am currently working on creating a mobile menu that spans the full width of the screen.

Despite my efforts, it seems like I might be misunderstanding something as my CSS rules are not being applied correctly.

Here is a live code example for reference: https://stackblitz.com/edit/react-ucvbgt-sur6ne?file=demo.js

https://i.stack.imgur.com/7d5pQ.png Any help or guidance would be greatly appreciated. Thanks!

Answer №1

Although this question is not recent, I encountered the same issue and managed to find a effective solution which I would like to share here.

The code you are currently using is missing two crucial elements: the marginThreshold property and a maxWidth style. The marginThreshold determines how close to the window edge the popover can be displayed. Additionally, including the maxWidth style ensures that the menu stretches across the full width as intended.

Below is the updated version of your menu component:

  <Menu
    position="relative"
    id="basic-menu"
    anchorEl={anchorEl}
    open={open}
    onClose={handleClose}
    marginThreshold={0}
    slotProps={{
      paper: {
        sx: {
          color: 'red',
          width: '100%',
          maxWidth: '100%',
          left: '0px',
          right: '0px',
        },
      }
    }}
    MenuListProps={{
      'aria-labelledby': 'basic-button',
    }}
  >

In addition to addressing the above issues, it's worth noting that the PaperProps attribute has been deprecated. As a replacement, I've switched to utilizing the new slotProps pattern.

Answer №2

Consider switching your menu layout to a drawer format, specifically with the anchor set to 'top' position.

To deepen your understanding, check out this resource: https://example.com/drawer-layout-guide

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 is the best way to display content next to an image, as well as below the image once it finishes?

Currently, I am working on customizing my blog posts in WordPress. My goal is to have the content of each post displayed next to the post thumbnail, and once the image ends, the content should seamlessly flow underneath it from the left side. I have imple ...

Trigger the react-native-side-menu to open when the button is clicked

Currently developing a react native app for iOS and utilizing the react-native-side-menu library for implementing a side menu. Looking for assistance on how to open it when a button is clicked on the screen, rather than scrolling from the left end. Any su ...

Is there a way to manipulate a DOM element using a component?

import { FlagIcon, ChartIcon, ShareIcon, ConnectIcon, HearIcon, AnalyticsIcon, AddIcon, RemoveIcon, } from "../../icons/Icons"; import "./Sidebar.scss"; import ReactDOM from "react-dom"; const Sidebar = () =&g ...

Problem with CSS dotted borders appearing as dashed in Chrome when applied to adjacent columns in a table

After testing the code on both Chrome and Firefox browsers, I noticed that they display the border differently. In Chrome, there is a dash in between adjacent cells while in Firefox, there are no dashes rendering. Can anyone suggest a solution to fix thi ...

Updating the React component's props array within a function inside the component causes changes to the array

I am currently tackling a ReactJS issue that has me stumped. I have a component that accepts an array of objects as props. Within the constructor, I need to manipulate this array and set the modified version to the component's state. constructor(pro ...

Is it possible to impose a different style on an element from another culture?

I am currently developing a themes library along with a demo page. The challenge I'm facing is that the demo page needs to showcase styles from the library without using all of the elements. For instance, consider the following style in an external s ...

Transitioning smoothly from mobile to tablet views with the sidebar activated in Semantic-UI

My HTML includes a pointing menu when the screen width exceeds 630px. Below 630px, it switches to a sidebar with a menu button: <nav class="ui inverted sidebar menu vertical slide out" id="m_menu"> <a href="index.php" ...

Setting maxFontSizeMultiplier for all Text components

Is there a way to apply the prop maxFontSizeMultiplier={1} to all instances of <Text/> in my app without the need for a custom component? ...

The issue at hand is that one of the JavaScript buttons is functioning properly, while the other is not playing the video as intended. What steps can

I've been working on a script for my school project website that should make buttons play videos, but I'm running into an issue where it only works for the first button (btn). Programming isn't my strong suit, and I put this together based o ...

Troubleshooting issues with the add-comment and remove-comment functionalities in a react-redux application

I'm working on a comment widget using react-redux. I've encountered an issue where, when I click on the add comment button, nothing happens. Also, when I try to delete a comment, I get an error saying that map is not a function even though I am p ...

Solutions for altering the appearance of a combobox using CSS

Currently, I am experimenting with javafx 2 and trying to modify the background color of the menu/list through CSS. Despite attempting the code snippet below, nothing seems to be working as expected. Do you have any suggestions or insights on how to achi ...

Even with the specified headers in the fetch request, the Next.js 13 and /src/app still exhibit a static component behavior

I am currently experimenting with Next.js 13 using the /src/app folder and have a component called @/components/LinkList.jsx const readLinks = async () => { return fetch(process.env.URL, { headers: { Authorization: '' }) .then(response = ...

The type unknown[] cannot be assigned to type React.ReactNode

import * as React from 'react'; import { List, ListItemButton, ListItemIcon, ListItemText, ListItem} from '@mui/material'; import LightbulbOutlinedIcon from '@mui/icons-material/LightbulbOutlined'; import NotificationsNoneOutl ...

Obtain the root URL path for React application

I am currently working on a react app using create-react-app and react-router. I am trying to determine the root URL path of my react app, especially since it may be served in different locations: For production: example.com/interface/ For local developm ...

Place two divs side by side with the second div filling up the remaining space on the line

Hello there, can anyone lend a hand with this problem? This is the code I have been working with: <html> <body> <div style="width=100%"> <div style="float:left; background-color:Red; height:100px">Red</div> <div st ...

Encountering a problem with withStyles in the latest release of Material-UI version

I am facing an issue with mui/material v5.0.4 and ts v4.4.4 when using the withStyles method. The error occurs when I try to use the AntSwitch component: 'AntSwitch' cannot be used as a JSX component. Its element type 'ReactElement<any, ...

Looking to transform an HTML table into a stylish CSS layout complete with a form submission button?

Recently, I've been delving into the world of CSS and PHP as I work on converting old code entirely into HTML and PHP with a touch of CSS. The visual aspect seems fine, but I've hit a roadblock with the submit form due to an IF statement in PHP. ...

developing a custom modal using a button in a React project with Material UI

Hello everyone, I have a question regarding React. I am fairly new to React and need some assistance with adding a new function that creates a Modal. I want to call this function onClick when the add icon is pressed (line 43). Any help would be appreciated ...

"Attempting to nest a map function inside another map function is resulting in the absence of displayed

I have encountered an issue with displaying data in my React component. I am trying to map through two sets of data, one containing items from a JSON file and the other containing image links. When I use props.detailData.map on its own, the content displ ...

"Master the art of creating a curved circular arrow using a combination of HTML, SVG, D3.js

I am looking to design an SVG circle with a fading stroke that blends into the background and features an arrow at one end. The goal is for the ring to fade out completely right above the arrow, similar to the visual reference provided in the image.view ex ...