Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

ReactJS DropZone browser attempts to open file on drop

Trying to implement the Dropzone component but not have much luck. Am I missing something here?

import { useState } from 'react';
import { useDropzone } from 'react-dropzone';
import styled from 'styled-components';

export const FilDataForm = (props) => {
    const [files, setFiles] = useState([])
    const getColor = (props) => {
        if (props.isDragAccept) return '#00e676';
        if (props.isDragReject) return '#ff1744';
        if (props.isDragActive) return '#2196f3';
        return '#eeeeee';
    }
    const onDrop = (file) => {
        console.log('HERE!!!!!')
        let nf = files;
        nf.push(file)
        setFiles(nf)
    }
    const Container = styled.div`
        flex:1;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 20px;
        border-width: 2px;
        border-radius: 2px;
        border-color: ${props => getColor(props)};
        border-style: dashed;
        background-color: #fafafa;
        color: #bdbdbd;
        outline: none;
        transition: border .24s ease-in-out;
    `
    const { getRootProps, getInputProps, isDragActive, isDragAccept, isDragReject } = useDropzone(onDrop);
    return (
        <div className="modal">
            <div className="dialog" style={{ width: "25%", marginBottom: "50px" }}>
                <div className="header"><h2>File Uploader</h2></div>
                <div className="content">
                    <Container {...getRootProps({ isDragActive, isDragAccept, isDragReject })}>
                        <input {...getInputProps()} />
                        <p>Drag 'n' drop some files here, or click to select files</p>
                    </Container>
                    <div className="grid-container" style={{ marginTop: "20px", height: "250px" }}></div>
                </div>
            </div>
        </div>
    )
}

Dragging the file(s) into the drop area causes the browser to launch a new tab attempting to open the file. Any help is appreciated.

EDIT Clicking in the Dropzone does not open the file dialog either.

question from:https://stackoverflow.com/questions/65909170/reactjs-dropzone-browser-attempts-to-open-file-on-drop

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...