There are issues with React Grid2 not adhering to specified row and column definitions and lacking

I am currently in the process of creating a website with react, and I have reached the point where I need to showcase some products. To achieve this, I am utilizing React's Grid2 due to its flexibility for customization and responsiveness to different window sizes. Each product is represented using React's Card component.

However, I have encountered an issue that I am struggling to resolve.

Please take a look at the following codesandbox: https://codesandbox.io/p/sandbox/lucid-cloud-h2z92f

The number of rows and columns should adjust based on the current screen size and the maximum height/width of each grid item (product card), allowing them to grow or shrink as needed when resizing the window. My understanding is that Grid2 should be able to handle this seamlessly.

For example, please visit and explore how the product "boxes" adapt to different window sizes by shrinking and growing accordingly. This is precisely the behavior I am aiming for.

In the current state of the sandbox, you will notice that the individual grid items do not exhibit the desired responsive behavior when resizing the window. Furthermore, the grid items overflow the backgroundBox boundary. Ideally, each grid item should scale appropriately to fit all 12 items (6 products on 2 rows) within the backgroundBox.

Additionally, it appears that the max width/height of the grid item is fixed instead of serving as an upper limit for adjusting the item's size.

Interestingly, specifying wrap="nowrap" instead of wrap="wrap" causes all 12 products to align in a single row, but they exhibit the responsive shrink/grow behavior that I desire when resizing the window. In this case, the max width/height limits are correctly observed.

It also seems that the specified grid item sizes (xs, sm, md, lg) are not having any effect.

Answer №1

In the products.map Grid element, you are currently only adjusting the number of columns based on screen size. However, it's important to incorporate logic for shrinking as well. Experiment with custom styles in the Grid props like:

sx={{
    flexGrow:
    flexBasis:
    maxWidth:
    transition: //to ensure smooth size changes
}}

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

calculating the duration between successive PHP form submissions

I am trying to calculate the duration between when a user submits a PHP form and when they submit it again. The form reloads on the same page, essentially refreshing it. Additionally, the user may enter the same data again. I want the timer to start runnin ...

Creating a reusable React component for integration into various MVC projects within Visual Studio 2017

Creating an MVC website in Visual Studio with the following technology stack: TypeScript React Components Redux C# backend I am interested in packaging and consolidating the company's <Header />, its child components (<Navbar />, etc.), ...

Using ES6, when utilizing array map in ReactJS, the function does not produce a return value

One challenge I'm facing involves mapping an array to find a specific string value. Unfortunately, despite my efforts, the map function is not returning anything as expected. class Application extends React.Component { constructor(){ super(); ...

Experiencing an internal server error while using Axios (error 500)

I have my django-rest-framework api running on port 80000 and my react project on port 3000. Cors-headers are installed in Django, and I am successfully making requests to the API. However, there seems to be a problem: import axios from 'axios'; ...

Trouble with closing windows in the in-app browser on Android devices

Is there a method to successfully close the in-app browser? Despite window.close working on iOS devices, it is not effective on Android. I have experimented with alternatives like window.top.close and window.open("", "_self") window.close, but none have ...

Looking to implement an underline effect using CSS for the active tab that mimics the hover effect already applied

How can I ensure that the underline on active tabs (Domov) matches the hover effect on other tabs? The border-bottom currently creates a border that is lower than the hover effect, resulting in inconsistent underlines as seen on this page - (try moving ...

Video on Youtube keeps playing even after the overlay is closed

I successfully created an overlay with an embedded YouTube video that automatically opens when the page loads. Everything was going smoothly until I encountered a problem - when I close the overlay while the video is playing, the audio continues to play in ...

Begin 5 seconds after loading

First time attempting this task. My goal is to trigger the loading of an I have been trying to write a script for this, but it's not functioning as expected. HTML : <div id="div1"> <a id="single" href="#">Single Play</a> & ...

Avoiding the "too many renders" error when invoking a function in React

export default function Weather({destination}) { const [location, setLocation] = useState('') const [dataExtended, setDataExtended] = useState({}) const urlExtended = `https://api.openweathermap.org/data/2.5/forecast?q=${destination}&units=m ...

Unable to set the height of WebDataRocks as a percentage

I've recently started using WebDataRocks and I'm having trouble getting the height to fill the window. Despite what the documentation says (), which states, "The height of the pivot table in pixels or percent (500 by default)". The code snippet ...

Using Bootstrap's CSS classes, is it possible to modify the background color of a table cell?

I'm currently working with Bootstrap 5.0 CSS and attempting to create a table with customized cell colors using some of my own CSS styles. The color property seems to be working correctly, but I'm running into an issue with Bootstrap not recogniz ...

Conceal particular table cells through jQuery

I am a beginner in the world of jQuery. My goal is to hide certain cells in a row when clicked, and have them displayed again when clicked once more. I've searched high and low for a solution, but all I find is how to hide entire rows. Here's an ...

Can the TEXT from a <select> be passed as the value of a hidden <input> element?

<form method="POST" action="question-function.php"> <label>Choose Category</label> <select name="catid" id="catid" class="form-control"> <?php $sel3 = mysqli_query($ ...

Send back alternate HTML content if the request is not made via AJAX

Last time I asked this question, I received several negative responses. This time, I will try to be more clear. Here is the structure of a website: Mainpage (Containing all resources and scripts) All Other pages (HTML only consists of elements of that ...

Deactivate participant's mic using AWS Chime SDK for JavaScript

Is there a way to mute specific attendees using Amazon Chime SDK JS v3.14 and also mute all attendees while utilizing the Amazon Chime SDK Component Library React? I attempted to mute attendees by sending a message via sendData, but unfortunately it did n ...

finding the source file or code where a particular html element is being generated

In the HTML file I have, there are multiple JavaScript files added. Whenever I run the HTML file, a title tag is automatically created in my HTML file. I do not want this title tag to appear in my HTML file. How can I prevent this from happening? Or how c ...

In Internet Explorer, the list items are overlapping, while functioning perfectly in all other web browsers

I've encountered a strange issue with my list item in Internet Explorer. Despite working perfectly in Chrome and other browsers, it fails to function properly in IE. I've built this application using the Vue framework and have faced various probl ...

The quote generator is on strike, API refuses to provide fresh quotes

After building my entire project in Visual Studio Code and testing it on Chrome and Explorer, I was excited to see that it worked perfectly - retrieving a new quote and author with the press of a button. However, when I tried to put it into Codepen, I enco ...

Perpetual spinning of image grid

Are there any jQuery libraries available for continuous image rotation within an array? I have a collection of 30 partner logos that I would like to rotate continuously using either a jQuery library or plain CSS code. These images and information will be l ...

Issue with sending an ajax post request using Jquery

The jquery ajax request below is not working as expected: $(document).ready(function(){ var friendrequest = $(".friendrequest").val(); $(".afriendreq").click(function(){ $(".afriendreq").hide(); ...