The issue of not being able to type in the sweetalert 2 input within a material UI modal in a

Within a card displaying an order, there is a sweetalert2 popup that opens when trying to cancel the order, asking for a cancellation reason. This feature works seamlessly on the orders screen. https://i.sstatic.net/RWhOA.png

<Grid item md={8} sm={12}>
    orders.map((order) => <SupplierOrderBlock data={order} />)
</Grid>

When attempting to cancel an order, two sweetalerts are triggered. The first prompts the user to enter a reason, and if left blank, the second alert insists on providing a reason before cancelling.

const cancelOrder = (orderID, status) => {
    Swal.fire({
      title: "Are You Sure You Want to Cancel Order",
      text: "Please Enter the reason for the cancellation of order",
      input: "text",
      showCancelButton: true,
      confirmButtonColor: "#1c8fec",
      cancelButtonColor: "#fa013b",
      customClass: 'swal-wide'
    }).then((result) => {
      if (result.value == '') {
        swal({
          title: "You can not cancel without giving a reason",
          showCancelButton: true,
          confirmButtonColor: "#1c8fec",
          cancelButtonColor: "#fa013b",
          buttons: {
            Confirm: { text: "Okay", className: "okayButton" },
          },
        });
      }
else if (result.isConfirmed) { //cancel order}

This functionality operates smoothly. Now, when using the same component within a Material UI modal in my dashboard, I encounter an issue where text cannot be entered.

<Modal
        open={modal}
        onClose={handleClose}
        aria-labelledby="simple-modal-title"
        aria-describedby="simple-modal-description"
        style={{ width: "60%", zIndex: 1, marginLeft: '-10%' }}
      >
        <Box style={{ marginLeft: "50%", marginTop: "25vh", width: "100%", position: 'absolute' }}>
          <SupplierOrderBlock data={supplierorder} />
        </Box>
      </Modal>

https://i.sstatic.net/P3jJt.png

If I remove the Z-index property from the Modal, the sweetalert goes behind the modal https://i.sstatic.net/n9ZV7.png

However, upon closing the modal, it allows users to enter a reason https://i.sstatic.net/rap2j.png

Answer №1

Having trouble with untypeable input in SweetAlert2 nested within a Material-UI Drawer in your React app? Here's a solution:

The issue stems from MUI Drawer/Modal Focus management. To fix it, utilize the disableEnforceFocus property on the drawer/modal. When set to true, this allows the drawer to lose focus, enabling user input.

Keep in mind that this change may impact accessibility for screen readers, so proceed with caution.

Check out the code snippet below -

<Drawer id="drawer" anchor="right" open={true} **disableEnforceFocus**
}}>
    {
    <MyComponent/>//Inside this component i have sweetalert
    }
</Drawer>

It's possible that using the same property could resolve a similar issue with a MUI Modal as well.

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

serving index.html using express and react

I am currently working on an application with Express, which includes a create-react-app. My goal is to display the index.html file located in the public folder of the create-react-app when a user visits the root URL. Below is the code snippet from my inde ...

Steps to handling and resolving a vulnerable npm security issue regarding semver that is susceptible to Regular Expression Denial of Service

Encountering an error in my azure pipeline: The issue is with semver, which has a vulnerability to Regular Expression Denial of Service. Severity: moderate More info When trying to resolve the error by adding semver to my resolutions in package.json: &q ...

What is the most effective method for updating edited rows in a DataGrid MUI and transferring them to

Is there a way to update the values I just edited in firebase after using editRow (please correct me if I'm mistaken)? Within DataGrid //Enable row edit mode editMode="row" //Any updates made in the row are stored in this variable, overrid ...

Struggling to grasp how to implement Redux and React-router together in one component

I have recently embarked on learning TypeScript and encountered a confusing behavior. Upon encountering this error: Type 'ComponentClass<{}>' is not assignable to type 'StatelessComponent<void | RouteComponentProps<any>> ...

In which part of my code should I implement the string to numerical function for my OrderBy function?

I successfully implemented a sortable header for my table with no errors, everything is functioning as expected. However, there is a small issue that I anticipated beforehand. The data in my JSON is string-based with numerical values that include symbols l ...

The Firebase Firestore library (version 9.6.8) encountered an issue communicating with the Cloud Firestore backend. The backend failed to respond within the expected 10-second timeframe, resulting in an error specific to react

I've encountered an issue while working on react-native. Firebase authentication works fine, but I'm having trouble with Firestore. The problem seems to be specific to the Android Emulator as the iOS emulator is functioning correctly. error only ...

Utilizing Axios to Extract Data from a Specific Row in a React MUI Data-Grid Table

In an attempt to implement the functionality of returning all data from a selected row using this example, I encountered an issue. Unlike the demo, which uses the useDemoData mod for table population, my approach involves utilizing Axios to fetch data from ...

Illustration: Fixing a CSS Issue

After implementing Technique #8 from the Nine Techniques for CSS Image Replacement, I am not getting the desired results. Instead of correctly positioned images, the output is not what I anticipated. Here is a link to see for yourself: I made a modificati ...

Implementing clickable actions to add new entries in a React.js application (using Redux toolkit)

I am currently working on my PET project using Redux toolkit and encountering some issues with inputs. When I add an input on click, it gets added correctly, but I am unsure if it is being added in the right place (it should be added in the ITEMS array). A ...

Can you please enlighten me on the significance of "m" in the context of MUI styles?

One of my MUI components has a unique property called sx. Can you explain what the value m:1 signifies in this context? sx={{ display: 'flex', flexWrap: 'wrap', '& > :not(style)': { m: 1, width: 128, h ...

What is the method for implementing right/left text ellipses on flexed buttons that span the entire viewport width using CSS?

I currently have the following code: .viewport { width: 300px; } .container { --color-dark: rgb(40, 40, 40); --color-light: rgb(255, 255, 255); --color-base-background: rgb(255, 255, 255); ... <div class="viewport"> <di ...

working with Selenium in the Chrome web browser

Within a file named e2e.js, the following code was written: const webdriver = require('selenium-webdriver'); const driver = new webdriver.Builder().forBrowser('chrome').build(); driver.get('https://www.google.co.il/'); I h ...

Unable to set value for React MUI TextField in React Hook Form Controller inside MUI Stepper Dialog

I am facing an issue with my Button that triggers a MUI Dialog to open. Within the Dialog, there is a MUI Stepper as part of my form which has different required and non-required inputs. //Sample Input <Controller name="stateName" co ...

Incorporate external input properties into Material UI's TextField component

I've integrated react-payment-inputs library for handling credit card input in my project. Using the provided getter props, I can easily manage credit card inputs like this: <input {...getCardNumberProps()} />. However, when applying the same a ...

The module 'react' is not found in the directory '/react/node_modules/react-redux/lib/components'

Issue: Module react not found at path /home/react/node_modules/react-redux/lib/components While utilizing cypress for unit testing components, the tests are encountering the error mentioned above despite 'react' being present in the dependencies ...

Map failing to refresh

Having some trouble with the map function as it's not updating my select box with the new selected value. The issue occurs within a material UI dialog that appears when viewing a file. I notice that the values get updated only after closing and reopen ...

Iterate through a collection of objects and organize the data in a specific way

Within the data structure of my API response, I am attempting to iterate through an array of objects under the items key. Each value inside these objects needs to be formatted based on the corresponding format type specified in the header key. To assist wi ...

Is there a way to edit a cell in the MUI X Data Grid without having to double-click

Is there a way to change the MUI XData Grid cell editing behavior so that it always displays in edit mode or by hovering, rather than requiring a double click? ...

Transforming a stateful class component into a functional component using hooks

I've been struggling with converting a class component to a functional one. I've looked at various examples on how to accomplish this, but I still feel like I need a better understanding of the basics. How can I refactor my code to utilize useSta ...

When resizing the window, navigation items vanish

I've implemented the collapse feature using Bootstrap, but encountered an issue where my nav elements disappear when resizing the window. Do you have any suggestions on how to fix this? Here's a snippet of my code: Navb ...