How to handle file drop?
jkleiser opened this issue · comments
Jon Kleiser commented
I'm trying to implement a simple JSON file drop in my SPA. I have tried both the $ondrop="ondrop"
and the $ondrop={ondrop}
way, but the e.preventDefault()
does not seem to have any effect as my JSON data just replaces my SPA component when I drop the file. Is there a simple fix for this?
// Hello World ($on)
const state = '';
const view = state => <>
<h1 $ondrop={ondrop}>Hello {state}</h1>
<input $oninput={oninput}/>
</>;
const oninput = (_, e) => e.target.value;
const ondrop = (_, e) => {
e.preventDefault();
return e.toString();
}
app.start(document.body, state, view);
Jon Kleiser commented
It seems the fix was to include a $ondragover="nodrag"
and do a e.preventDefault()
in that handler as well.