Skip to content

Commit

Permalink
docs(drop-container): prevent default browser drag and drop behavior (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
emyarod authored Apr 2, 2020
1 parent 6068604 commit 9c1896a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"carbon-components": "latest",
"carbon-components-react": "latest",
"carbon-icons": "latest",
"react": "16.10.2",
"react-dom": "16.10.2",
"react-scripts": "3.2.0"
Expand Down
16 changes: 15 additions & 1 deletion packages/react/examples/drag-and-drop-file-uploader/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React, { useState, useCallback } from 'react';
import React, { useState, useCallback, useEffect } from 'react';
import { render } from 'react-dom';
import { settings } from 'carbon-components';
import {
Expand All @@ -24,6 +24,20 @@ const { prefix } = settings;

function ExampleDropContainerApp(props) {
const [files, setFiles] = useState([]);
const handleDrop = e => {
e.preventDefault();
};
const handleDragover = e => {
e.preventDefault();
};
useEffect(() => {
document.addEventListener('drop', handleDrop);
document.addEventListener('dragover', handleDragover);
return () => {
document.removeEventListener('drop', handleDrop);
document.removeEventListener('dragover', handleDragover);
};
}, []);
const uploadFile = async fileToUpload => {
// file size validation
if (fileToUpload.filesize > 512000) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import React, { useState, useCallback } from 'react';
import React, { useState, useCallback, useEffect } from 'react';
import { settings } from 'carbon-components';
import FileUploaderItem from '../FileUploaderItem';
import FileUploaderDropContainer from '../FileUploaderDropContainer';
Expand All @@ -16,6 +16,20 @@ const { prefix } = settings;

function ExampleDropContainerApp(props) {
const [files, setFiles] = useState([]);
const handleDrop = e => {
e.preventDefault();
};
const handleDragover = e => {
e.preventDefault();
};
useEffect(() => {
document.addEventListener('drop', handleDrop);
document.addEventListener('dragover', handleDragover);
return () => {
document.removeEventListener('drop', handleDrop);
document.removeEventListener('dragover', handleDragover);
};
}, []);
const uploadFile = async fileToUpload => {
// file size validation
if (fileToUpload.filesize > 512000) {
Expand Down

0 comments on commit 9c1896a

Please sign in to comment.