ReactJS Material UI Horizontal Menu with CSS Styling

I am currently working on creating a horizontal menu with ReactJS and Material UI. However, I am facing a challenge where the menu is not responsive. Even when I resize the browser window, the menu size remains the same and only updates when I refresh the page with F5.

import React from 'react';
import AppBar from 'material-ui/AppBar';
import Drawer from 'material-ui/Drawer';
import MenuItem from 'material-ui/MenuItem';
import IconButton from 'material-ui/IconButton';
import NavigationMenu from 'material-ui/svg-icons/navigation/menu';
import NavigationClose from 'material-ui/svg-icons/navigation/close';
import Paper from 'material-ui/Paper';
import Menu from 'material-ui/Menu';

const style = {
  display: 'inline-block',
  margin: '0 32px 16px 0',
  width: '100%'
};

const styleq = {
  display: 'inline',
  float: 'left',
  width: '25%'
};

export default class MenuAlumno extends React.Component {
render() {
    return (
        <div>
            <AppBar
                title={<span style={STYLES.title}>- PLATFORM FOR INCIDENTS -</span>}
                onTitleTouchTap={this.handleTouchTap}
                titleStyle={STYLES.titleStyle}
                iconElementLeft={this.state.drawerOpen ?  <IconButton><NavigationClose/></IconButton> : <IconButton><NavigationMenu/></IconButton>}
                onLeftIconButtonTouchTap={this.controlMenu}
            />
            <Paper style={style}>
              <Menu>
                <MenuItem primaryText="Maps"  style={styleq}/>
                <MenuItem primaryText="Books"  style={styleq}/>
                <MenuItem primaryText="Flights" style={styleq} />
                <MenuItem primaryText="Apps" style={styleq} />
              </Menu>
            </Paper>
        </div>
    );
}
}

Answer №1

Having faced the same issue, it has been quite frustrating to deal with! I have a strong affinity for MUI, but the nesting can definitely complicate things at times... However, I managed to find a solution that worked for me. Simply keep your MenuItems as they are and adjust your Menu props like so:

<Menu autoWidth={false} width="100%" listStyle={{width: '0.01%'}} style={{width:'100%'}}>

Answer №2

It seems like there may be a fixed width element causing some issues.

Could you provide a URL where I can view the problem in action or any additional details to help me better understand the situation? It's a bit challenging to diagnose based on the information provided.


UPDATE

When utilizing the Menu component, ensure to set the "autoWidth" prop to "false". Referencing the code snippet, you'll notice that the default value is "true," which enforces a specific width for the menu.

<Menu autoWidth={false}>

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

Distinguish between regular JSS and JSS with Component

I've been working on a project with React and Material-UI, utilizing JSS for styling. As the project grows, I'm looking to better organize the JSS structure. Currently, each component has its own JSS code within the component file. One thing I a ...

Tips for enabling resize functionality on individual components one at a time

Check out my Codepen link for the resizable event While using Jquery UI resizable, everything is functioning correctly. However, I am now looking to have the resizable event activate one block at a time. When another block is clicked, the resizable event ...

The issue with CSS right alignment not functioning as expected

My attempt to align text to the right using a CSS rule is not working as expected when applied to a font within a cell. Can anyone help me troubleshoot this issue? Take a look at my code snippet below: CSS: .font1 { font-size: 60px; text-align: ...

Unable to render a child div completely opaque using the opacity attribute

I am currently working on a popup feature that, when displayed, will blur the background of the page to a grey color. The .cover element is responsible for this overlay effect. Unfortunately, I am facing issues overriding its default opacity:0.6; property ...

Changing color based on AngularJS condition using CSS

My HTML code looks like this: <div> <i class="glyphicon glyphicon-envelope" style="margin-top: -50px; cursor:pointer; color: #1F45FC" ng-click="createComment(set_id)"> </i> Route <center> ...

The use of window.Image() is ineffective when working with TypeScript and React

In my React project, I am utilizing the KonvaJS library. You can find more information about it here. To display an image using JavaScript/React, I have implemented the following code: componentDidMount() { const image = new window.Image(); ima ...

Leveraging the :has pseudo-class in Tailwind along with adjacent sibling selectors

My CSS code is working perfectly as intended. [data-type='transfer']:has(+ [data-type^='sale_']) { opacity: 0.25; } This CSS snippet targets elements with data-type="transfer" that are next to elements containing data attri ...

What is the best way to transfer values or fields between pages in ReactJS?

Is there a way to pass the checkbox value to the checkout.js page? The issue I'm facing is on the PaymentForm page, where my attempts are not yielding the desired results. Essentially, I aim to utilize the PaymentForm fields in the checkout.js page as ...

Switch up between two distinct colors every three elements using a single selector

I have a group of tr items in my list and I want to apply CSS styles to them in a specific pattern : red red red black black black red red red black and so on. Is there a way to achieve this using just one selector? Currently, I'm doing it like th ...

Struggling with setting up routes in Express and React - need help troubleshooting!

Currently in the process of learning Express/React and attempting to configure routes and establish basic database connections. I have a hunch that I am overlooking something simple. Below is a condensed version of the setup I am working with. Backend se ...

Having trouble with running npm install after updating node js?

Images displaying error messages First Image Second Image Third Image Version of Node.js ...

Align text vertically next to an image

I am facing a challenge with aligning text vertically next to an image floated left. I have tried various solutions recommended on different platforms, but none seem to work for me. Despite following the suggestions provided in this particular solution, I ...

Tips for properly displaying a table when the TableHead and TableBody are separated into different sections

Is it possible to render a table with the tableHead and tableBody in different sections while ensuring that they have the same width for each column? <Table container aria-label="simple table"> <TableHead> <TableRow> <Ta ...

Maintaining nth-child(odd) following filtering using jQuery

I am using a jQuery script to filter a table with multiple entries on this site. The filtering works well, but the issue arises when it comes to maintaining the correct tr:nth-child(odd) color that I have specified in my CSS. After filtering, the original ...

What could be causing the lack of functionality for my button click in my JavaScript and HTML setup?

Currently, I am attempting to implement a functionality where I have two buttons at the top of my page. One button displays "French" by default, and when I click on the "English" button, it should replace the text with "French" using show and hide methods. ...

The error message "ERR_CONNECTION_TIMED_OUT when trying to access Google APIs fonts

Upon deploying my web project on the client server, I encountered an error and noticed slow page loading. GET https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic net::ERR_CONNECTION_TIMED_OUT The browser ...

Adjust the outline hue of MUI SvgIcon by utilizing a personalized SVG

When working with custom SVGs, I have found that I can easily change the fill color using SvgIcon. import { ReactComponent as MyIcon } from '../my_custom_logo.svg'; <SvgIcon component={MyIcon} inheritViewBox color="primary" /> Ho ...

Tips for creating a dynamic logo that zooms in when you hover over it

Is there a way to create a zoom effect for the logo in my navigation bar when hovering over it without using jQuery? I've tried various codes from different sources but none seem to work. The .logo class is assigned to the logo in the nav bar. Any sug ...

Tips on making Material-UI Drawer compress other content when it is open

Seeking assistance from those familiar with CSS and Material UI! I'm currently working on implementing a Material UI Drawer component that doesn't just slide out over the top of the page content, but actually causes the page content to adjust aro ...

What is the best way to dynamically generate a component and provide props to it programmatically?

I am interested in creating a function that can return a component with specific props assigned to it. Something like a reusable component for Text/View/Pressable, where styles can be extracted and passed as props. Personally, I find it more efficient to s ...