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

Tips for utilizing the ternary operator with React table accessory

If my accessor value is 1 or 0, how can I change it to either Active or Inactive? { Header: 'isActive', accessor: 'isActive' } ...

What are the possible arguments for the event type onInput?

While diving into the world of html / javascript / vue, I stumbled upon the following code snippet. <input type="text" onInput="doAction(event);"> <script> var mesdata = { message: 'type your m ...

Two-column list using XSLT

I am seeking assistance with xsl transformation. The xml generated by SharePoint Server control is as follows: <rows> <row>A</row> <row>B</row> <row>C</row> <row>D</row> <row>E ...

Mastering the art of gracefully transitioning to a fallback option when CSS grid

When it comes to creating a simple grid of squares (3x3 at most, filling in top to bottom left to right), I have encountered challenges with both flexbox and grid. The DOM structure required for each method seems incompatible or too complex to support both ...

Tips for launching a fresh window and embedding HTML into it with jQuery?

I'm attempting to use JavaScript to open a new window, but the HTML content is not being added: var callScriptText = $('#callScriptText').html(); var url = '/Action/CallScript/?callScript='; // Open the current call script in a n ...

Node.js video tag requests minimal data transfer on mobile devices

After creating a node server for streaming mp4 videos from a Mongo database using gridfs, I encountered an issue. The videos stream perfectly to desktop browsers, but when attempting to stream to a mobile device, the video player shows up, but the video do ...

Angular restricts the use of the svg namespace in the $sce service for security reasons

I have a project in Angular Material where I am using an md-icon with a specific svg structure: <md-icon class="ic1" md-svg-src='data:image/svg+xml, <svg xmlns="https://www.w3.org/2000/svg" viewBox="0 0 32 32"> <ellipse ry="16" rx=" ...

Matching wildcard paths using Express

Seeking help with routing in Express. I am trying to have both /m/objectID and /m/someslug/ObjectID directed to the same function. My current setup is as follows: app.get("/m/:id", ...); app.get("/m/(.*)/:id", ...); The first route is working properly, b ...

Positioning the div in the center

Having trouble centering a div inside a 100% wide container. Here is the HTML code: <div id="body-outside"> <div id="body-inside"> content </div> </div> And here is the CSS: #body-outside{ width:100%; flo ...

What are the best ways to display nicely formatted JSON data in a text area using React JS?

I am new to React JS and encountered an issue with rendering the pretty JSON data inside a textarea. I'm unsure which part of my code is incorrect, but I want my pretty JSON to be displayed within the textarea as shown below. "email":"<a href="/cd ...

Combine the elements within the HEAD tag into a group

I am currently developing a dynamic page system using AJAX. Whenever a link is clicked, an AJAX call is made to retrieve data from the requested page. However, I have encountered an issue where certain data in the page file needs to be placed within the h ...

Issues with the functionality of the bootstrap modal jQuery function in Firefox, causing problems with scrollbars and dynamic modal height adjustments

My newly launched website is built using bootstrap v3 and modals to showcase detailed information about each game server that is queried. Each modal provides insights into the current players on the server, their score, and play time. While implementing ...

What is the best way to include several IDs in a discord.js verification process?

I am attempting to create a basic script that verifies if the user's ID matches the one specified in the code. However, I'm struggling to understand how to achieve this. Any assistance from you all would be greatly appreciated. if(message.autho ...

Cut off all information beyond null characters (0x00) in Internet Explorer AJAX responses

When using Internet Explorer (IE6, IE7, and IE8), null characters ("0x00") and any subsequent characters get removed from ajax responses. Here's the code snippet that showcases a loop of AJAX requests: var pages = 10; var nextnoteid = 0; for (isub ...

Issue with proxy arises only when the application is loaded within an iframe

Situation I have a React application running on localhost:3000 and an express server running on localhost:5001. Additionally, my package.json includes the following: "proxy": "http://localhost:5001", Upon initial load, my React app acc ...

Explore the differences between user input and JavaScript

There seems to be an issue with the second output result. var compareNumber = 3; // Code will be tested with: 3, 8, 42 var userNumber = '3'; // Code will be tested with: '3' 8, 'Hi' /* Enter your answer here*/ if (userNum ...

Angular protection filter

Every time I used Angular CLI to generate a new component, it would create the component with standard parameters: @Component({ selector: 'app-test1', templateUrl: './test1.component.html', styleUrls: ['./test1.component.css ...

Difficulty encountered while implementing the if-else statement in raycasting operations

Currently, I am experimenting with raycasting to determine if my mouse is pointing at an object. The function seems to be working fine when the object is not being touched - it correctly prints out "didnt touch". However, when the object is touched, it s ...

Encountering issues with multiple arguments in ajax within a C# MVC application - Further details included

There seems to be a missing piece in my code. Here's my controller method public void SubmitSweep(int personID, int DD, int MM, int YYYY, int hh, int mm, int dealId) Here's how I define my button <button id="submit@(person.Id)" clas ...

"Enhancing Functionality: A Detailed Guide on Callback Functions in Express

Currently, I am expanding my coding skills by learning express/Node, transitioning from C and PHP/MySQL. The MDN tutorial on express has been incredibly helpful in my learning journey, making everything straightforward. Thanks to the Mozilla teaching team, ...