How can you animate a MUI v4 Grid element using CSS transitions?

I was exploring the potential of using breakpoints in the MUI v4 component to control the visibility of items in my Grid System.

How can I create a smooth CSS transition for b, transitioning from 0px to a defined breakpoint size of 3 for xl? Using % works, but I'm struggling to achieve the same effect with a Grid element. It seems to not have a width of 0px.

For example:


let show = true; //reactUseState

const toggle = (p) => {
  return (!p);
}

<Grid container direction="row>
  <Grid id="a" item xl={show ? 12 : 9}>{children}</Grid>
  <Grid id="b" item xl={show ? false : 3}>{otherchildren}</Grid>
</Grid>

<Button onClick={() => toggle(show)}>Show 1 or 2 items</Grid>

Hoping someone out there knows the secret trick!

Answer №1

Here is a solution that should do the trick:

<Grid container direction="row">
  <Grid className="right" id="b" item lg={show ? 12 : 9}>{'otherchildren'}</Grid>
  <Grid className={show? "left left-hide" : "left"} id="a" item lg={3}>{'children'}</Grid>
</Grid>

CSS styling:


.right {
  transition: ease 0.5s;
}

.left {
  transition: ease 0.5s;
  overflow: hidden;
}

.left-hide {
  flex-basis: 0% !important;
}

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 align NavLink to the right in AppBar?

<AppBar position="static" className={this.props.classes.appBar}> <Toolbar style={{ margin: "0 auto", width: "80%" }} > <Link to="/"> <img src={logo} alt="logo" width="65" height="48" /> </Link> <Nav ...

When formatting amounts, it is important to not allow the thousand separator to come after the decimal separator

I am tasked with ensuring that a thousand separator does not come after a decimal separator every time a key is pressed. Is it feasible to achieve this using regular expressions? If so, can you explain how? ...

What is the best way to include rxjs in an npm library - as a dependency, peer dependency, or both?

After researching numerous posts and articles on dependencies versus peerDependencies, I am still not entirely certain what to do in my particular situation.... I have a library (which is published to a private npm repository) that utilizes rxjs; for exam ...

Adding JSON data to a MySQL column in JSON format with the help of NodeJS

I currently have a MySQL table set up with the following specifications: CREATE TABLE `WorkOrders` ( `workorder_id` int(11) NOT NULL AUTO_INCREMENT, `intertype_id` int(11) NOT NULL, `equipment_id` int(11) NOT NULL, `reason_id` int(11) NOT NULL ...

React - Children components in an array not updating when props are modified within a callback function

The question may be a bit unclear, so let me provide further explanation. This is a personal project I am working on to improve my understanding of React basics and socket.io. Within this project, I have developed a CollapsibleList component and a NestedL ...

Is it time to say goodbye to MUI Material UI React Hook useTheme(), and if so, what should we replace

Is there a way to access theme props outside of JSX and CSS without using the legacy React Hook useTheme() or the sx prop? Imagine I have a component with complex logic that requires custom theme properties in certain handlers, but I want to avoid relying ...

The absence of color gradations in the TypeScript definition of MUI5 createTheme is worth noting

Seeking to personalize my theme colors in MUI5 using TypeScript, I am utilizing the createTheme function. This function requires a palette entry in its argument object, which TypeScript specifies should be of type PaletteOptions: https://i.stack.imgur.com ...

Deploying a React app in Cloud Foundry using a Staticfile deployment appears to be mistaken for a Node deployment, despite the presence of a buildpack

Currently in the process of deploying a React app to Cloud Foundry after successfully packaging it into static files. However, encountering an unexpected error during deployment: 16:24:44.467: [APP/PROC/WEB.0] bash: npm: command not found 16:24:44.519: [A ...

Find the quantity of items in each list individually and add them to a new list

Seeking a solution for a seemingly simple issue. I am attempting to calculate the number of list items and then add this count to the list in the parent div. The problem lies in the fact that it always displays the value of the last item in the list. For i ...

Creating a customized design for a q-popup-edit

As I navigate through using Quasar in Vue, I stumbled upon a q-popup-edit that allows me to gather input from the user. Despite my attempts at researching via Google and reading documentation, I have hit a roadblock when it comes to customizing the style o ...

A guide on toggling the password input type between text and hidden in a React application

I am facing an issue with toggling the input type between password and text to display the password in a login form. The expected functionality is that clicking on the eye icon next to the password input should reveal the password in plain text, but this i ...

encountering difficulties with installing dependencies using yarn or npm

After cloning a repository, I attempted to install the dependencies using npm install or yarn but encountered the following errors: For Yarn: https://gyazo.com/2fdf52c4956df2e565cc0b1cedf24628 For npm install: https://gyazo.com/a1d197e9ead89dbe4a7d3c5b8f ...

Optimizing performance: Enhance readback operations in Canvas2D by enabling the willReadFrequently attribute for faster getImageData processing

I am currently utilizing the react-wordcloud package and encountering an issue where the word cloud adjusts to fit 70% of the screen size whenever the container size changes. My console is being flooded with this warning message: https://i.sstatic.net/vdV ...

A simple guide on toggling a button in a React application to increment the number by either 1 or -1

Currently, I am in the process of implementing a unique voting system for a like and dislike ratio button similar to the concept seen on YouTube. The idea is that when the like button is clicked, the value increases by 1, and when the dislike button is cli ...

Sending parameters in GraphQL with Typescript results in an empty set of curly braces being returned

I am new to learning GraphQL with Typescript and I am trying to pass an argument in a GraphQL function to return something dynamically. I have been struggling with this issue for the past hour and could not find any solutions. Here are the relevant code sn ...

I am encountering an issue with my authentication system where it is returning

I'm currently experiencing an issue with my authentication system using passport. For some reason, I keep getting an 'undefined' value returned. Can anyone provide assistance? Here is the code snippet in question: app.js passport.use(new L ...

Troubleshooting Problem with Displaying SVG Images

Snippet for Header Component import React from 'react' const Header = () => { return ( <div> {/* Main-header */} <header className=''> {/* Header-background */} {/* <div c ...

Error code 1 occurs when attempting to execute the "npm run start" command

Every time I attempt to execute "npm run start" within my project folder, the following error message pops up: myLaptop:app-name userName$ npm run start > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c1a0b1b1ecafa0aca481f ...

Mui Material. Eliminate the padding on the grid component

I am having trouble removing the 8px padding that is being added to my grid items. I've tried modifying the code below but haven't had any success. The padding is set by .Mui-GridItem with a value of 8px and I can't seem to get rid of it. Ca ...

Encountering problems with ajax technology

As a newcomer to Laravel and Ajax, I am facing an issue with displaying the state of the selected country in a dropdown list. Although the data is successfully fetched from Laravel and received through Ajax, I am struggling to dynamically add it to the H ...