yysun / apprun

AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.

Home Page:https://apprun.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to handle file drop?

jkleiser opened this issue · comments

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);

It seems the fix was to include a $ondragover="nodrag" and do a e.preventDefault() in that handler as well.