Caution: React is unable to identify the `PaperComponent` prop on a DOM element

Trying to create a draggable modal using Material UI's 'Modal' component. I want users to be able to move the modal around by dragging it, so I decided to use 'Draggable' from react-draggable library. However, I encountered this error message: Warning: React does not recognize the PaperComponent prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase papercomponent instead. If you accidentally passed it from a parent component, remove it from the DOM element.

Any idea what mistake I might be making?

CodeSandbox Link: https://codesandbox.io/s/draggabledialog-material-demo-forked-srw9yn?file=/demo.js

Below is the code snippet:

import * as React from "react";
import Button from "@mui/material/Button";
import { Modal, Box } from "@material-ui/core";
import { Close } from "@material-ui/icons";

import Paper from "@mui/material/Paper";
import Draggable from "react-draggable";

export default function DraggableDialog() {
  const [open, setOpen] = React.useState(false);

  function PaperComponent(props) {
    return (
      <Draggable
        handle="#draggable-dialog-title"
        cancel={'[class*="MuiDialogContent-root"]'}
      >
        <Paper {...props} />
      </Draggable>
    );
  }

  const handleClickOpen = () => {
    setOpen(true);
  };

  const handleClose = () => {
    setOpen(false);
  };

  return (
    <div>
      <Button variant="outlined" onClick={handleClickOpen}>
        Open draggable dialog
      </Button>
      <Modal
        open={open}
        onClose={handleClose}
        PaperComponent={PaperComponent}
        // aria-labelledby="modal-modal-title"
        aria-describedby="modal-modal-description"
        aria-labelledby="draggable-dialog-title"
      >
        <div>
          <form
            style={{
              width: "360px",
              color: "white",
              display: "flex",
              flexDirection: "column",
              backgroundColor: "#1E2328"
            }}
          >
            <div
              style={{
                backgroundColor: "black",
                margin: "0",
                display: "flex",
                alignItems: "center",
                height: "56px",
                width: "360px",
                color: "white",
                justifyContent: "space-between"
              }}
              m={2}
            >
              <Box
                style={{
                  color: "#E9ECEC",
                  fontSize: "21px"
                }}
              >
                Countries{" "}
              </Box>
              <button
                style={{ color: "white" }}
                onClick={handleClose}
                aria-label="close-settings-popup"
              >
                <Close />
              </button>
            </div>
            <div style={{ height: "100%" }}>
              <div>
                Country Name
                <p>Germany</p>
                <p>France</p>
              </div>
            </div>
          </form>
        </div>
      </Modal>
    </div>
  );
}

Answer №1

Issue with Modal Component and PaperComponent Prop

If you only want the modal to be draggable, here's how you can modify your code:

import * as React from "react";
import Button from "@mui/material/Button";
import { Modal, Box } from "@material-ui/core";
import { Close } from "@material-ui/icons";

import Paper from "@mui/material/Paper";
import Draggable from "react-draggable";

export default function DraggableDialog() {
  const [open, setOpen] = React.useState(false);

  

  const handleClickOpen = () => {
    setOpen(true);
  };

  const handleClose = () => {
    setOpen(false);
  };

  return (
    <div>
      <Button variant="outlined" onClick={handleClickOpen}>
        Open draggable dialog
      </Button>
      <Modal
        open={open}
        onClose={handleClose}
        // aria-labelledby="modal-modal-title"
        aria-describedby="modal-modal-description"
        aria-labelledby="draggable-dialog-title"
      >
       <Draggable>
        <div>
          <form
            style={{
              width: "360px",
              color: "white",
              display: "flex",
              flexDirection: "column",
              backgroundColor: "#1E2328"
            }}
          >
            <div
              style={{
                backgroundColor: "black",
                margin: "0",
                display: "flex",
                alignItems: "center",
                height: "56px",
                width: "360px",
                color: "white",
                justifyContent: "space-between"
              }}
              m={2}
            >
              <Box
                style={{
                  color: "#E9ECEC",
                  fontSize: "21px"
                }}
              >
                Countries{" "}
              </Box>
              <button
                style={{ color: "white" }}
                onClick={handleClose}
                aria-label="close-settings-popup"
              >
                <Close />
              </button>
            </div>
            <div style={{ height: "100%" }}>
              <div>
                Country Name
                <p>Germany</p>
                <p>France</p>
              </div>
            </div>
          </form>
        </div>
      </Draggable>
      </Modal>
    </div>
  );
}

View Demo Here

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

Is there a way to verify if an element possesses a specific style, and if so, alter the style of a different element accordingly?

Could you assist me in achieving a similar effect as demonstrated below: I have two menus (http://osiyo-nur.uz/osiyo-nur.uz/test6/), one of which is initially invisible. When I hover over the first menu, the second menu becomes visible with an overlay eff ...

Obtaining specific data from the forEach iteration, post-click event with JavaScript

Trying to access the value from a Tree-structured Array of Objects stored in Local Storage, Created a function that retrieves values from local storage using forEach and displays them on the screen. Clicking on the Yes/No button triggers the same functio ...

calling object functions using additional parentheses

After reviewing the passport.js documentation, I came across this piece of code: app.get('/login', function(req, res, next) { passport.authenticate('local', function(err, user, info) { if (err) { return next(err); } if (!u ...

Whenever a new entry is made into the textfield, the onChange feature triggers a reset on the content within the textfield

I'm experiencing an issue while creating a SignUp authentication page with Firebase. Every time I try to input text in the text field, it gets reset automatically. I have been unable to identify the root cause of this problem. It seems to be related t ...

Can we dynamically adjust font size based on the width of a div using CSS?

My div is set to 70% width and I have a specific goal in mind: To fill that div with text To adjust the font size so that it takes up the entire width of the div https://i.stack.imgur.com/goVuj.png Would it be possible to achieve this using only CSS? B ...

Generate an asynchronous boolean promise when calling the isPresent function in Protractor

I'm currently working on a function that checks the presence of an element and returns a boolean value accordingly. However, I am facing an issue where the response includes unnecessary information. the output displays: false How can I adjust my cod ...

What is the best way to show the Logout button on the main UI after successfully logging in?

I am currently working on implementing a new feature in my React JS application. The idea is that upon successful login, the UI should display a Logout button in the navbar. However, clicking on this button should log the user out and redirect them to the ...

How to align radio_button_tag and label_tag side by side in Rails using Twitter Bootstrap 2?

Struggling to align the radio_button_tag horizontally with its label_tag. (Utilizing HAML) =radio_button_tag(:animal, "dog") =label_tag(:animal, "Dog") Which classes should I use for these form helpers to have them positioned side by side as shown below: ...

Changes to a key value are not reflected in the array of objects

When making changes to input fields within an array of records that include Date and Text fields in a table, the data is not updating as expected. I am encountering issues where changing the Date input results in undefined Text values, and vice versa. My g ...

What is the best way to direct to the user dashboard in React from Express once authentication is successfully completed with Passport?

I am currently developing an application utilizing the MERN stack. For authentication, I am employing Passport-local and back-end using Express router with front-end using React router. React is running on port 3000 while express is running on port 5000. A ...

Angular 4's Mddialog experiencing intermittent display problem

While using MDDialog in my Angular app, I've encountered a couple of issues. Whenever a user clicks on the div, flickering occurs. Additionally, if the user then clicks on one of the buttons, the afterclose event is not triggered. Can anyone provide ...

Regular expression: subpattern without immediate subsequent character

Consider a regular expression that needs to return true for any string containing the substring hello, followed by any string that does not start with ! or multiple instances of !. Here are some examples to clarify: var regExp = /someExpression/; regExp ...

Using Node.js Express to serve a React build version

When I try to serve my react application with an Express server, I run into a problem. I have set up the react application to make API requests via a proxy, but now that I am serving the build using Node.js, all API routes are returning a 404 error. &quo ...

Displaying a progress bar while fetching data in Vue: A step-by-step guide

I am working on developing a progress bar using vue js and bootstrap for my desktop application. Within the template, I have the code that will generate the necessary markup: <div class="container-fluid p-0 vh-100" v-if="isLoading&quo ...

Is randomly pairing 2 datapairs after slicing a JSON array easy or challenging?

There is a JSON file containing an unlimited number of users [{ "fname": "Hubert", "lname": "Maier", "email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bd ...

import a function from jQuery that has been defined in an external JavaScript file

Whenever I attempt to execute this action, I encounter an error stating that the function is undefined $(function () { function Example(){ Example1(); } Example1(); }); external.js $(function () { function Example1(){ alert("Hello"); } }); ...

Receiving an issue while trying to launch a React application using npm start

Every time I try to create a new React folder using npx create-react-app test, I encounter an issue where npm start does not function properly and displays the following error message in the terminal: > <a href="/cdn-cgi/l/email-protection" class="_ ...

An unexpected error occurred: ReferenceError - document is undefined

Error Alert: Unhandled Runtime Error ReferenceError: doc is not defined Source of Issue components\Modal.js (42:18) @ updateDoc 40 | await uploadString(imageRef, selectedFile, "data_url").then(async (snapshot) => { 41 | const do ...

Executing a Drupal rule using JavaScript: A step-by-step guide

I'm facing a challenge when trying to activate a Drupal rule using JavaScript code. lowerLayer[image.feature_nid].on("dragend", function() { var position = kineticImage.getPosition(); var layerPosition = this.getPo ...

Challenges related to using the require() method in JavaScript

I've been encountering an issue while trying to run the JavaScript client for the Tumblr API from their Github repository. The error message I keep getting is "require not defined" which has led me on a hunt across various forums and websites, includi ...