Troubleshooting: Issues with React Material-UI breakpoints not functioning

Trying to create a responsive navbar using Material-UI. The goal is to hide the IconButton between 960px and 1920px, and display it from 0px to 960px. However, it seems to work only below 960px. Here's a snippet of the code for IconButton and ul:

    <div className={classes.right}>
        <IconButton
          edge='end'
          className={classes.btnMenu}
          size='medium'
          onClick={(e) => setShowMenu(!showMenu)}
        >
          <MenuIcon
            className={classes.btnMenuMenu}
            size='medium'
          ></MenuIcon>
        </IconButton>
        <ul
          className={`${classes.list} ${
            showMenu ? classes.showList : classes.removeList
          } `}
        >
          <li className={classes.li}>
            <a href='#!' className={classes.navLink}>
              Home
            </a>
          </li>
          <li className={classes.li}>
            <a href='#!' className={classes.navLink}>
              About
            </a>
          </li>
          <li className={classes.li}>
            <a href='#!' className={classes.navLink}>
              Portfolio
            </a>
          </li>
          <li className={classes.li}>
            <a href='#!' className={classes.navLink}>
              Contact
            </a>
          </li>
        </ul>
      </div>

In the styles.js file, applied the following code to style the IconButton:

btnMenu: {
width: '100%',
display: 'none',
[theme.breakpoints.down('sm')]: {
  display: 'inline-block',
 },
},

Despite this styling, the IconButton still appears above the ul, as shown in the image below. Here is the GitHub repository link: GitHub Repository

Answer №1

To resolve the issue, I made a simple adjustment by replacing the MenuIcon with a fontawesome bars icon and added the .btnMenu class to the <i>...</i> tag. This change resolved the issue and now everything is functioning as expected. While I'm not entirely certain about what caused the problem with IconButton, making these modifications did the trick...

<div className={classes.right}>
         
        <Button onClick={(e) => setShowMenu(!showMenu)}>
          <i className={` ${classes.btnMenu} fas fa-bars`}></i>
        </Button>
        <ul
          className={`${classes.list} ${classes.list2} ${
            showMenu ? classes.showList : classes.removeList
          } `}
        >
          <li className={classes.li}>
            <a href='#!' className={classes.navLink}>
              Home
            </a>
          </li>
          <li className={classes.li}>
            <a href='#!' className={classes.navLink}>
              About
            </a>
          </li>
          <li className={classes.li}>
            <a href='#!' className={classes.navLink}>
              Portfolio
            </a>
          </li>
          <li className={classes.li}>
            <a href='#!' className={classes.navLink}>
              Contact
            </a>
          </li>
        </ul>
      </div>

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

The function useCollectionData in react-firebase-hooks fails to return any value

I am encountering an issue while attempting to query a collection using useCollectionData with a where query. Every time I try, it just returns undefined. I have reviewed the documentation available on GitHub, but unfortunately, I haven't had any succ ...

I am facing an issue where new tags are not being created when I pre-fill values in the tags input field on Bootstrap

When working on the Product Edit Page, I successfully displayed the old data that was selected previously. However, I am facing an issue with adding new tags. The new tags do not appear when I press enter or space after typing in the input field. It is pos ...

Unwanted gap appears in the image slider

There seems to be a pesky little gap right below my image slider that I just can't seem to get rid of. I was hoping to spruce it up with a box-shadow, but when I tried it out on jsfiddle, it ended up looking pretty awful because of the annoying gap. I ...

Can CSS calc() achieve modulus behavior?

Is it possible to dynamically adjust the height of an element based on screen size using calc(), while still maintaining alignment with a specified baseline grid? The height should always be a multiple of the defined variable $baseline. I've noticed ...

What is the correct method for importing dynamic components using Next JS? (WordPress Flexible Content)

I'm a newcomer to NextJS and I'm having trouble figuring out the proper way to achieve this. Specifically, I'm attempting to utilize WordPress along with ACF's Flexible Content module as a form of page builder. In my index.js file, I a ...

The CSS styling of Vuetify TreeView does not support text wrapping

I'm having trouble getting the long text in this CodePen snippet to break and wrap properly. It extends off screen, rendering the append button unclickable. I've experimented with various CSS rules but haven't found a solution yet. Check ou ...

Show an SVG overlay when hovering over an image

Is there a way to create a hexagon shape around an image when it is hovered over using CSS only, even if the image itself has a circular border-radius of 50%? ...

The React Native Flatlist encountered an error due to a mismatch in function overloads

I'm currently working on a React Native app using Typescript, and I've encountered an issue with the Flatlist renderItem function. As someone who is new to both Typescript and React Native, I received the following error message: No overload ma ...

Show the nested div when hovering over the containing div using JavaScript

I have a situation where I have multiple divs within a parent div, all using the same class. Here is an example: <div class="deck-content"> <div class="deck-box">TEST< <div class="deck-hidden">< <span class= ...

JavaScript code that moves the active link to the top of the navigation when the window width is less than or equal to 800px

I'm working on a responsive navigation that is fixed at the top and switches from horizontal to vertical when the screen size is less than or equal to 800 pixels wide. However, I'm facing an issue with moving the active link to the top of the na ...

How can a block be made to stay fixed and float in a flexbox layout?

There are three blocks within the body of this page. Title bar Content block Bottom block I have employed a flex display for the body layout. My goal is to make the title bar float, meaning it should always remain at the top when scrolling. I attempted ...

When my Gatsby.js webpage refreshes, the footer component is rendered twice

Thank you for taking the time to review my issue. Any assistance would be greatly appreciated. **Update: I believe I have identified the source of the problem, but the reason behind it is still unclear to me. Previously, on my products/merch page, there w ...

Issue with spacing in 3x3 photo rollover grid

I am currently working on a 3x3 grid layout featuring image roll overs. Within this layout, the three images on the second row are linked to pages on the website. My goal is to incorporate a 4px padding around all columns and rows, centered at 1024x600 on ...

The Visualforce page is not displaying page breaks correctly for cells with rowspan in the table

Having encountered a similar issue to this question: table rowspan page break On my Visualforce page, I have an HTML table with a custom rowspan in one column (varies based on the number of spanned rows) and I'm experiencing a styling problem (see is ...

Ensure that Mathjax underscores are consistent with the height of other characters

Presented below is the latex code being used with Mathjax. \class{mathjaxCursor}{\text{_}} ...and here is the accompanying css: .mathjaxCursor { font-weight: bold; background-color: red; } This setup results in the following display: ...

Please provide either a render prop, a render function as children, or a component prop to the Field(auto) component

While working on my project and implementing an Auto complete feature using final-form, I encountered the following error: Must specify either a render prop, a render function as children, or a component prop to Field(auto) In order to resolve this issue ...

Space in the middle of a body and a div

After extensively searching for a solution to the issue plaguing my website, I found that there was always an annoying gap at the top of the page. Despite trying various solutions, none seemed to work. Upon inspecting the website in Firefox, I discovered t ...

Tips for accessing <Field> values in redux-form version 7.0.0

class CustomForm extends React.Component { constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); } handleClick() { const { Add, noteList } = this.props; Add('this is title value' , 'this is ...

Accessing information from Cookies within Jest tests using js-cookie

Can someone please guide me on how to test the function Cookies.get using Jest testing? I have a util.js file where I am calling the following code: const fullObjectStr = Cookies.get(cookieName); Now, I am looking to write tests for this using jest. Any ...

What is the best way to display a Bootstrap toggle?

I am facing an issue with a Bootstrap toggle in a Handlebars template. When the page initially loads, the toggle is visible, however, after re-templating the Handlebars template that contains the toggle, it disappears. Before Re-Template: Initial code : ...