I am looking to incorporate a scroll feature into my form, as it is being displayed within a modal that is a separate component

Due to the size of my employee form exceeding the screen capacity, I need to incorporate a scroll property into my modal content. The form contains numerous fields that cannot be modified.

Could you assist me in resolving the scrolling issue? Thank you!

Here's My code

import React from 'react';
import modalCSS from '../styles/modal.module.css';
import PurchasesForm from './forms/PurchasesForm';
import SalesForm from './forms/SalesForm';
import ExpensesForm from "./forms/ExpensesForm";
import InventoryForm from './forms/InventoryForm';
import StocksForm from './forms/StocksForm';
import EmployeeForm from './forms/EmployeeForm';
import SalaryForm from './forms/SalaryForm';
import LedgerForm from './forms/LedgerForm';

function Modal({ prop, closeModal, propObject, setPropObject, operation, updateItem }) {

    return (
        <div className={modalCSS.container}>
            <div className={modalCSS.modalBox}>
                
                <div className={modalCSS.header}>
                    <h1 className={modalCSS.title}>Add {prop}</h1>
                    <img src='/images/cross.svg' alt='cross-mark' className={modalCSS.crossBtn} onClick={() => closeModal()}/>
                </div>

                <div className={modalCSS.modalContent}>
                    {prop === "Sale" && <SalesForm sales={propObject} setSales={setPropObject} operation={operation} updateItem={updateItem} />}
                    {prop === "Purchase" && <PurchasesForm purchase={propObject} setPurchase={setPropObject} operation={operation} updateItem={updateItem} />}
                    {prop === "Expense" && <ExpensesForm expense={propObject} setExpense={setPropObject} operation={operation} updateItem={updateItem} />}
                    {prop === "Inventory" && <InventoryForm inventory={propObject} setInventory={setPropObject} operation={operation} updateItem={updateItem} />}
                    {prop === "Stock" && <StocksForm stock={propObject} setStock={setPropObject} operation={operation} updateItem={updateItem} />}
                    {prop === "Employee" && <EmployeeForm employee={propObject} setEmployee={setPropObject} operation={operation} updateItem={updateItem} />}
                    {prop === "Salary" && <SalaryForm />}
                    {prop === "Ledger" && <LedgerForm />}
                </div>
            </div>
        </div>
    )
}

export default Modal

Here's the CSS file

modal.module.css

.container{
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
}

.modalBox{
    height: fit-content;
    width: 60%;
    background-color: #FFF;
    border-radius: 10px;
}

.header{
    padding: 1%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* background-color: #F0F0F0; */
}

.crossBtn{
    height: 30px;
    width: 30px;
    cursor: pointer;
}

.modalContent{
    height: 100%;
    /* overflow: auto;
    overflow-x: hidden; */
    padding: 1%;
}  

This is the issue encountered when setting height: fit-content; in the modalBox class

enter image description here

If height: 80%; is set in modalBox and height: fit-content; in modalContent class, then this effect occurs

enter image description here

The modal remains intact while the form continues to overflow despite implementing the overflow property.

Please provide suggestions for a solution considering my preference to keep height: fit-content in the modalBox class due to various forms being accommodated. Your guidance would be much appreciated. Thank you!

Answer №1

To implement a fixed height with vertical scrolling, you can apply the following CSS to the modalContent class:

height: 500px;
overflow-y: auto;

Adjust the height value to suit your needs. Give it a try and see if it resolves the issue. Thank you.

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

The multiple-choice selection tool is not displaying any choices

I am having an issue with my ng-repeat code in conjunction with the jquery multiple-select plugin. Despite using this plugin for a multiple select functionality, the options generated by ng-repeat are not visible. Below is the code snippet in question: & ...

When using applyMiddleware inside the createStore() function, the listener state is unable to detect changes

I'm currently working with React, react-redux, and redux. Recently, I encountered an issue. When I implemented the following code: const store = createStore(reducers); store.subscribe(() => { console.log(getState()); }); => ...

After saving a rich field in Microsoft Sharepoint, I noticed that a new "External Class" was automatically added to my CSS

Although I am new to Sharepoint, I have experience in HTML and CSS. I recently created a mini HTML application that changes the pictures of hyperlinks on hover. It works perfectly when run on a normal browser outside of Sharepoint. However, the issue aris ...

Developing a unique bundle with tailored elements

I am interested in developing a custom Material UI component and making it available as a standalone package within my company's private NPM repository. Specifically, I have customized the Date Picker to create a Date Range Picker since Material UI d ...

Change the color of active buttons on dynamically generated buttons

My current challenge involves getting a button to stay active when pressed, especially when dealing with dynamically created buttons. Here is my current setup: <Grid container sx={{ padding: "10px" }}> {Object.values(CATEGORIES).map((c) => { ...

Simple steps to integrate Facebook chat messenger into Next.js

I've been attempting to integrate Facebook customer chat into my Next.js app, but I'm encountering issues. Despite thoroughly reviewing my code, I can't seem to identify the problem. What is the correct method for adding Facebook customer c ...

Issue with text-nowrap not functioning as intended within Bootstrap 4.5 table cells

Is there a way to eliminate the space between two columns in my layout? I want to get rid of the highlighted space below. I attempted using text-nowrap, but it didn't achieve the desired result. <link href="https://stackpath.bootstrapcdn.co ...

Retrieve the Typescript data type as a variable

I have the following components: type TestComponentProps = { title: string; } const TestComponent: React.FC<TestComponentProps> = ({ title, }) => { return <div>TestComponent: {title}</div>; }; type TestComponent2Props = { bod ...

Grid-based timekeeping design

Currently working on a clock grid layout and seeking some advice on the next steps. The layout has been created but still needs some adjustments to achieve perfection. What would be the most effective approach for correcting it? Would offsetting it using a ...

Managing state arrays in React JS: A guide to efficiently adding and removing items using a single function

Using React JS Class Component. Within a single function, I am attempting to... Add an integer value to an array if it is not already in the array and also remove a value from the array if it does exist. Note that initially the array will be empty [] My ...

Is there a way to customize padding on the right side of MUI 5 input fields?

Currently, I am utilizing MUI 5 and have a requirement to modify the default right padding on an input field. I managed to adjust the padding by updating the MuiInputBase-input inside a CustomizedNativeSelect. However, the new padding-right is not able to ...

Creating PropTypes from TypeScript

Currently in my React project, I am utilizing TypeScript along with PropTypes to ensure type checking and validation of props. It feels redundant to write types for both TypeScript and PropTypes, especially when defining components like ListingsList: inte ...

Making sure to correctly implement email input fields in HTML5: Surprising behaviors observed with the email input type in the Chrome browser

Within the upcoming code snippet, a basic email validation is implemented. An input field's background color will display as white for valid emails and yellow for incorrect values. This functionality operates seamlessly in Firefox; however, in Chrome, ...

Managing a group of checkboxes with Material UI controls

I have been working on a dropdown menu that contains multiple checkboxes, and I am facing an issue where clicking one checkbox results in all checkboxes being checked. Below is my current implementation: const [isChecked, setIsChecked] = React.useState(fal ...

How can you update an image's source when hovering over it?

My goal is to switch the image source upon mouseover using a combination of asp.net and javascript. Here is the code I am currently using: <asp:ImageButton id="button" runat="server" Height="65px" ImageUrl="~/images/logo.png" OnMouseOver="src='~ ...

Is it necessary to always provide a return value from a redux middleware function?

After reviewing the various examples provided in the redux documentation, it seems like there is always a return value from the middlewares. However, in my experience, simply calling next(action) and not returning anything seems to work without any issues. ...

A guide to displaying a component when clicked using React

Currently, I am attempting to display a map of a specific location passed down from a parent component. Utilizing google-maps-react has raised a couple of uncertainties for me: Firstly, I am uncertain about how to invoke functions with onClick within my r ...

Using React JS to style the PaperProps of a Dialog Component in Material-UI

Currently, I am utilizing Dialog components from material-ui in ReactJs. <Dialog fullScreen open={this.state.open} PaperProps={{ classes: {root: classes.dialogPaper} }} onClose={this.handleClose.bind(this)} transition={this.props.transition}> ...

Running the gulp uncss command with regex to ignore specific elements is not functioning as expected

I have been attempting to integrate uncss into my gulp workflow. In order to exclude certain classes, such as those added through javascript, I am specifying these classes with "ignore" (specifically, I am trying to remove the css from the jquery plugin m ...

Font discrepancies in HTML field types "text" and "textarea" are causing inconsistent font display

Why do the text in my "text" and "textarea" fields show different fonts on my pages' HTML? I attempted to specify the font type in both the background CSS file and within the HTML, but it did not resolve the issue. Just to be transparent...I'm ...