As the screen size shrinks, two components merge together

One issue I'm facing with my site is the component called NavPanel. This consists of two components - a back button (BackToButton) and a search field (SearchTextField). Everything looks fine on a standard screen size, but when the screen size decreases, these components start to overlap.

I would prefer it if the second component (SearchTextField) could be positioned under the first one (BackToButton) when the screen size is reduced. Do you have any suggestions on how I can achieve this?

    const Style = {
    paddingLeft: '8%',
    paddingRight: '8%',
    minHeight: '70px',
    alignItems: 'center',
    flexWrap: 'nowrap',
    whiteSpace: 'nowrap'
}

export default function NavPanel() {
    
    return (
        <Grid container sx={Style}>
            <BackToButton />
            <SearchTextField />
           
        </Grid>
    );
}

Answer №1

Here is the solution...

You may need to revisit your implementation of the grid.

Check out the modified code snippet here.


UPDATE 1

A:

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

B:

https://i.sstatic.net/8QapC.png


UPDATE 2

To resolve the issue, consider changing the breakpoint from sm to md. This adjustment will affect the stacking order of elements like PageNameBackToButton and FilterButtonSearchTextField, but it will prevent scenario A.

View the revised snippet here.

PageNameBackToButton Component

// Code for PageNameBackToButton component
// ...

FilterButtonSearchTextField Component

// Code for FilterButtonSearchTextField component
// ...

Filter Component

// Code for Filter component
// ...

Answer №2

<Grid container> is essential with <Grid item>s nested inside.

Similar to Bootstrap,

Utilizing a grid system maintains consistency in layouts while providing flexibility for diverse designs. Material Design's responsive UI adopts a 12-column grid layout.

Your code snippet would resemble this:

<Grid container spacing={1} sx={Style}>
  <Grid item xs={12} sm={6}>
    <BackToButton />
  </Grid>
  <Grid item xs={12} sm={6}>
    <SearchTextField />
  </Grid>
</Grid>

I highly recommend exploring the MUI Grid Docs.

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

Encountering a data retrieval issue when using the useSWR hook in a project using reactjs

I am trying to retrieve data from the backend using useSWR. However, I have encountered two bugs in the function getDataUseSWR. The errors occur at line 'fetch(url).then': 1: "Expected 0 arguments, but got 1."; 2: "Property 'then' does ...

Does the history.push() function in React get executed asynchronously?

Utilizing the history object that is passed from a component to a reducer in React, I am conditionally routing to other pages while updating the state. I realize this may not be the optimal way to handle navigation, but surprisingly it is still working. ...

Classname fails to modify the base style of the AppBar

Struggling to modify the appearance of the AppBar component by utilizing the className attribute, however, the .MuiAppBar-root class consistently takes precedence. const useStyles = makeStyles((theme: Theme) => ({ appBar: { backgroundColor: &apos ...

Ways to minimize an array using group by

I have a large dataset that needs to be grouped by COAGrpCode and ldgrGrp. Specifically, I need to sum the values of Opening, PrdDr, PrdCr, and Closing for each unique combination of COAGrpCode and ldgrGrp. Below is a sample of the data, which consists of ...

Send a parameter to the state from the component to access the object property key within a React array

I am managing a state that contains an array of objects: const [Value, setValue] = useState([{ Width: null, Length: null }, { Width: null, Length: null }]) In addition, I have a component where I need to retrieve the value for Value using the setValue fun ...

Changing the appbar color on scroll in Material UI is a simple process that can enhance the

Is there a way to dynamically change the background color as I scroll down on my NavBar Component? I've tried implementing it but for some reason, it's not functioning correctly. import { useScrollTrigger } from "@mui/material"; const ...

Internet Explorer is having issues displaying CSS text accurately, particularly in relation to the background-

Having an issue with Internet Explorer not displaying my background clipped text correctly. In other browsers like Chrome and Firefox, the code renders fine: https://i.stack.imgur.com/x9lio.png However, in IE it appears differently: Your code: HTML: & ...

The horizontal scrollbar is not displaying

(RESOLVED) Currently, I am developing a movie app that displays film titles through an Accordion feature using Bootstrap. Specifically, I have created an Accordion that showcases movies added to a favorites list. The intention is for this favorites secti ...

updating the HTML DOM elements using JavaScript is not yielding any response

One way that I am trying to change the background of a div is by using a function. Below is an example of the html code I am working with: $scope.Background = 'img/seg5en.png'; document.getElementById("Bstyle").style.background = "url("+$scope.B ...

Bootstrap's inline form features a button on a separate line from the rest of the form

I grabbed this code directly from bootstrap's official documentation: <form class="form-inline"> <div class="form-group"> <label class="sr-only" for="exampleInputAmount">Amount (in dollars)</label> <div class="inp ...

Tips for aligning MUI badge within IconButton border using ReactJS

I managed to create a unique Bluetooth connection status indicator using a combination of a tooltip and a badge. However, I'm encountering difficulties with the badge's positioning. Take a look at my code: <Tooltip className={classes.help} ti ...

Issue: Material popover remains open even after calling the onClose function

I have a Chat component with an input field that contains an endorsement. I'm trying to implement a popover functionality to display and select emojis, but the closing feature of the popover is not working properly. import React from "react"; impor ...

What is the reason behind enclosing arguments within braces when passing them to React functional components?

After spending an embarrassingly long time trying to debug strange behavior in my React components, I finally discovered the issue. It turns out that I had two components structured like this: // class component export class ParentComponent extends React ...

What is the reason behind the malfunctioning of this navigation menu?

This is a responsive navigation bar created using bootstrap. The issue I am facing is that I want the navigation items to be displayed in a single row. Here is the fixed-top navbar: Below is the navigation menu code: https://i.sstatic.net/Zqrvm.png ...

Link to text on tablet and phone

On my website, I have included a phone number in the HTML as text. When viewed on an iPad tablet, it automatically interprets the phone number and turns it into an underline blue link. Is there a way to format the phone number in a different style so it d ...

What specific width range would be best for my needs?

I used to have the default font style of Myriad Pro Light and a padding setting for my main menu on my website as follows: .menu > li > a { padding: 17px 15px 15px 15px; } Recently, I changed the default font style to Montserrat. However, this chang ...

What could be the reason behind a React Project not stopping when using Ctrl C to run the npm stop script

After initiating the project using npm create react app, I encountered issues trying to stop the React project with Ctrl C. Despite attempting various solutions such as reinstalling npm and node, executing 'taskkill -F -IM node', and utilizing $ ...

Error Encountered during Deployment of Custom React App on Heroku due to Fetch API Issue

After developing a small app using React without CRA, I successfully deployed it to Heroku. However, I encountered an issue where a static JSON file that I created isn't fetching properly (it works fine on my local machine). Upon encountering this pr ...

Encountering issues with Material-UI sample code compilation

As a newcomer to React and programming in general, I may be overlooking an obvious mistake here, for which I apologize. While working on my first components in React, I have been heavily relying on sample code from Material-ui. I managed to successfully bu ...

Django: Struggling with static files and navigating paths for CSS rendering

Sorry to ask, but I'm struggling with a problem and could use some help: My project directory has the following structure (there are more directories, but for now let's focus on these): projectfolder/ wsgi/ openshift/ templates ...