Enliven the transition between grid sizes

I'm currently working on a project using React and Material UI.

Seeking assistance on how to implement an animation for changing the size of a grid item. By default, the item is set to sm={3}, but when a user hovers over it, I want it to change to sm={6}.

Below is the code snippet:

<Grid
    item
    xs={this.state.hoverItem ? 6 : 3}
    spacing={24}
    onMouseEnter={this.handleItemHover}
    onMouseLeave={this.handleItemHoverLeave}
>
    <Paper
        elevation={this.state.hoverItem ? 5 : 1}
        className={classNames(
            classes.card,
            this.state.hoverItem && classes.cardHover
        )}
    >
</Paper>
</Grid>

Additionally, here is my JSS implementation:

card: {
    ...theme.mixins.gutters(),
    paddingTop: theme.spacing.unit * 2,
    paddingBottom: theme.spacing.unit * 2,
    transition: theme.transitions.create("width", {
        easing: theme.transitions.easing.sharp,
        duration: theme.transitions.duration.enteringScreen
    })
},
cardHover: {
    transition: theme.transitions.create("width", {
        easing: theme.transitions.easing.sharp,
        duration: theme.transitions.duration.leavingScreen
    })
},

Despite implementing these transitions, they don't seem to be functioning as expected.

Answer №1

Hey there! I really enjoyed tackling today's problem of the day. I decided to add some simple hover transitions to my implementation. Check it out on codesandbox:

See the Animated Switching Grid Size

By the way, I included your transition property in the code, just without specifying the width. It worked flawlessly. If you encounter any issues, feel free to report them on Material-UI now.

If the problem still persists, please do let me know!

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

Exploring methods to detect when a PHP page has been printed using the 'ctrl+p' shortcut and then subsequently updating

Hey there! I'm currently managing a php website that functions as an accounting system. Within this system, there are receipts, invoices, and other forms of documentation in use. However, I've encountered a problem with the main table in my myS ...

Data retrieval is currently not functioning, as React is not displaying any error messages

One of the components in my app is as follows: import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { compose } from 'redux'; import { translate ...

What is the reason behind Intellij Code Inspection indicating that a selector is not being used?

I have a small project consisting of two files located in the same folder. App.css .App-align-left { text-align: left; } App.js import React from 'react'; import 'App.css'; class App extends React.Component { constructor(p ...

What is the best way to establish personalized CSS styles specific to each subdomain?

I am in the process of establishing a multi-tenant application with a single instance and single database setup. The backend infrastructure is built using Ruby on Rails, while the frontend is handled by a separate AngularJS app integrated with a Rails fram ...

Utilize React Dropzone for effortlessly styling elements upon drop action

Currently, I am working on implementing Dropzone in React. My specific requirement is to display a text and a blue border in the center of the Dropzone area when files are dragged onto it (text: "you are inserting files"). This is how my current code look ...

The trick to organizing an array in useSelector() without triggering endless re-renders

I'm currently attempting to display a sorted list of anecdotes by utilizing useSelector() within the Redux framework for this exercise in my current course. However, every time I try to access the anecdotes from the state, I consistently encounter th ...

JavaScript event listener for SVG path element click is not functioning correctly as anticipated

How to determine if an element or its children have been clicked? I am trying to identify when a parent element or any of its child SVG icons with the attribute name set to "setGameState" have been clicked. The issue I am facing is that sometimes the even ...

Utilize React.js middleware to seamlessly redirect to the login page whenever an Axios response returns a 401 error

In utilizing react js, I have the following dependencies: "react": "^17.0.2", "react-router": "^5.2.1", "react-router-dom": "^5.3.0". I am looking to implement a middleware in my react js application that will redirect to the login page when an axios res ...

Preventing users from navigating away from the page without choosing an answer in a React application

My dilemma involves the implementation of a question component, where I aim to prevent users from leaving a page without selecting an answer. Below is my question component: import React, { Component } from 'react'; import { Link } from 're ...

Picture transports during change

Is there a way to increase the size of images in a List without causing other images to move when hovered? Currently, when an image is hovered, it increases in size but causes the surrounding images to shift to a new line and I would like to avoid this beh ...

What is the process for setting up a banner on one page that will automatically be reflected on all other pages?

Is there a way to have a banner in a div and display it on the home page so that it automatically appears on all other pages without needing to place the code on each page individually? Any assistance would be greatly appreciated :) ...

Error: Trying to break down a non-iterable object is not valid

Currently working on an Ionic React app and encountering the following error: Error: TypeError - Invalid attempt to destructure non-iterable instance Once I run the program, the error occurs at this point: . Shown below is a snippet of my code: import ...

What is the best way to implement my Vanilla JS Array manipulation technique in a ReactJS environment?

My REST API development is in its final stages, and I'm currently facing a challenge with converting an array received from the backend into either a Nested Object of Objects or an array of objects. This conversion would allow me to avoid directly acc ...

Oops! Looks like there was an error message in React JS. If you intended to display a group of children, make sure to

I'm encountering an issue with my project. Everything seems to be working fine until I include the Navbar component in the Skills section, then I receive the following error message. However, when I remove Navbar from the skill component, everything r ...

Can React Native support styling using server-side data?

One of my React Native (RN) components is rendering data from an external server. The data is enclosed within RN components. For example: ... <View> <Text>{this.props.db.greeting}</Text> </View> The 'DB' object is si ...

Is there a way to apply styles to a checkbox's child element depending on the checkbox's state without relying on ternary operators within Styled Components?

I am currently working on styling this component using Styled Components, but I feel like my current approach is a bit of a hack. What would be the best practice for incorporating Styled Components to style this component effectively? If I were to use Pla ...

Placing a CSS image with absolute positioning on top of a responsive image

Is there a way to keep the balloon image position fixed in relation to the grid image when resizing it? The balloons Balloon1 and B2 are technically within grid 5 and 7, but if you resize the grid left or right, the balloons will go off-center. Do I requ ...

The mobile website layout appears immaculate on the emulator, but it doesn't translate well on real mobile devices

Recently, I delved into the world of html/css/javascript and decided to create a website as a way to practice my skills. However, I have come to realize that many of the methods I used are not considered best practices. I am committed to improving and will ...

Retrieving the value of the react-calendar once it has been transferred to a different component

How can I retrieve the date value from the react-calendar component that is passed from the Calendar to the Input component? I need to access this date once it is sent over. import React from "react"; import Calendar from "./Calendar"; ...

The top margin is experiencing issues and is not functioning correctly

I'm struggling to identify the problem with this script: http://jsfiddle.net/AKB3d/ #second { margin-top:50px; ... } My goal is to have the yellow box positioned 50px below the top border of the right box. However, every time I add margin-top to ...