Ways to adjust the size of a component with visual impact when another component is being displayed within it?

I'm working on a modal component that pops up with a form for inputting data. Alongside the form, another component should appear under certain conditions (like fetching data successfully). I want the entire card containing these elements to smoothly expand horizontally on desktop or vertically on mobile when the second component shows, gradually reducing the width of the first box during the transition.

To achieve this effect, I initially tried using MUI Grid Container and Grid items, but encountered issues where the second item ended up on a new line or positioned to the right without affecting the overall size of the modal card.

This is the style applied to the modal card:
sx={{
                    position: 'absolute',
                    top: '50%',
                    left: '50%',
                    transform: 'translate(-50%, -50%)',
                    display: 'flex',
                    flexDirection: 'column',
                    transitionDuration: '500ms',
                    minWidth: '30%'
                }}

Thinking of a workaround, I attempted wrapping the two components in a DIV element and applying custom CSS to leverage transition effects. However, I couldn't get it to work as expected.

Here's the style applied to the wrapper DIV:
<div style={{ display: 'flex', flexDirection: 'row', width: '100%' }}>
This is the div containing the form grid container (1):
<div
                        style={{
                            flexGrow: 1,
                            minWidth: '30%',
                            transitionDuration: '500ms',
                            transitionTimingFunction: 'ease-out'
                        }}
                    >
This is the div holding the component displayed when the condition is met (2):
 <div
                            style={{
                                paddingLeft: 10,
                                transitionDuration: '500ms',
                                transitionTimingFunction: 'ease-in',
                                whiteSpace: 'nowrap',
                                minWidth: condition ? '200px' : '0%',
                                width: '0%'
                            }}
                        >

If anyone could provide guidance on how to make this CSS transition work seamlessly, I would greatly appreciate it. As a newcomer to CSS, any help is welcome!

Thank you

Answer №1

After retrieving the information, you have the option to insert a class (e.g., .active) into the main container and apply specific styles to be modified, such as

container.active > child{Blahblah styles}

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

When utilizing the col-md class, the scope value in Angular-vs-repeat appears to be empty

When placed within a section containing the col-md class, the scope value will be empty. You can see an example of this in the provided Plunker linked in the comment section. The scope value becomes empty once the code snippet <div style="visibility:hi ...

Uniting 2 streams to create a single observable

I am in the process of merging 2 different Observables. The first Observable contains a ShoppingCart class, while the second one holds a list of ShoppingItems. My goal is to map the Observable with shopping cart items (Observable<ShoppingItems) to the i ...

Personalize numerous mui elements

While MUI's docs provide the ability to customize a single component, what if you want to customize multiple components at once? For example, can you apply the same custom styles to both MuiPaper and MuiList? Here is an example of how you can customi ...

Learn the necessary steps to ensure that your content, including videos and images, is displayed correctly using HTML and CSS

I recently put together a simple webpage using a tutorial I found online. The layout includes two videos and two images arranged in a horizontal column, with the potential for more images to be added later on. Everything was looking good until I inserted t ...

What is the best way to reduce the size of an image using a URL?

As I work on creating a website in React for a company, my main focus is on developing a drive repository where users can upload files. One issue that has arisen is the performance of the "photos" folder, as it contains numerous high-resolution images th ...

jQuery UI Datepicker extending beyond its bounds

My Datepicker is expanding and filling the entire screen. What could be causing this issue? Here is my code: Additionally, how can I change the date format in jQuery to appear as dd-mm-yyyy? https://i.stack.imgur.com/IQzVV.png HTML: <!DOCTYPE html&g ...

Are there any alternative methods for clearing form fields following a successful thunk dispatch in React?

When implementing a Post API call in Thunk, I dispatch a boolean success key for successful requests and an error message for errors. Now the goal is to clear form data upon success and display the error message upon an error. To achieve this, I utilize ...

Preventing endless loops in UseEffect caused by dependencies

Working on a Todo app where I'm fetching data from Firebase on mount and also on new state changes (when user adds a new todo). I've been practicing and trying to learn, but I'm having trouble with it. Any help is appreciated! ` import Reac ...

Error: React Validation cannot convert an undefined or null value to an object TypeError

React validation library has been utilized by me. https://www.npmjs.com/package/react-validation No errors are displayed when I navigate to my page from another page, but a error occurs upon refreshing the page. TypeError: Cannot convert undefined or ...

A step-by-step guide on initializing and setting a cookie value with expiration

Below is the code I have added. Can someone please help me locate the bug? Here is the code snippet: $_SESSION['browser'] = session_id(); setcookie($expire, $_SESSION['browser'], time() + (60 * 1000), "/"); echo "Value is: " . $_COO ...

Retrieving data in [slug].js using Reactjs

I am currently working on a project in Reactjs utilizing the "nextjs" framework. I have successfully managed to retrieve data (specific blog details) based on the slug([slug.js]). However, I now need to display data from all other blogs within the same c ...

The request to http://xx-xx.s3.amazonaws.com/ was unsuccessful due to a preflight access control check failure

While attempting to implement a direct upload to an S3 bucket using React Fine Uploader, I encountered an error when trying to upload files. The error message stated: "XMLHttpRequest cannot load . Response to preflight request doesn't pass access c ...

What is the process for overriding the module declaration for `*.svg` in Next.js?

The recent modification in Next.js (v11.0.x) has introduced new type definitions: For next-env.d.ts (regenerated at every build and not modifiable): /// <reference types="next" /> /// <reference types="next/types/global" /> ...

Utilizing the Public Directory in Vite Compilation

One issue I encountered in my project with Vite version 2.9.7 is related to the handling of images stored in the public folder within the project's root directory. To import these images, I utilized Vite's import.meta.glob function, like so: imp ...

React-Refresh: Unable to locate module - runtime.js

Issue: I am facing a "Module not found" error related to react-refresh/runtime.js in my React project. The error message indicates that the import being attempted is outside of the src directory of the project, causing the error to appear in the live brow ...

How can you make a Unity Web GL html container adjust its width to match the size of the browser window?

Looking to create a Unity WebGL build that allows for specifying width and height in the HTML template. How can I dynamically set the width of div id="gameContainer" based on the browser window width to ensure it always fills the space? .webgl-content ...

The listener for ObservableList is not functioning properly

I am currently working on an application that includes a GUI. One issue I am facing is integrating the List from the Model package into a ListView in the GUI package. The content of this list changes as the program runs. Initially, the List is empty but g ...

Efficiently adapting html content for Vue localization

I've been utilizing the v-html tag to display HTML in my Vue pages. However, I came across a string that was a complete HTML file with content like this: <html xmlns="https://www.w3.org/1999/xhtml"> <head> .... <style> < ...

Issue with MaterialUI and ReactJS: MobileDatePicker does not close after selecting a date

After implementing closeOnSelect for selecting a date, I am encountering an issue where the date picker remains open even after selection. The only way to make it disappear is by either escaping or clicking the OK or Cancel buttons. This issue occurs on bo ...

Clearing Up CSS Height Definitions

Based on my observations from other posts, it seems that to establish the height of an element in percentages or pixels, etc., the parent element's height also needs to be explicitly defined. This implies that the height settings must be specified all ...