HeinrichApfelmus / threepenny-gui

GUI framework that uses the web browser as a display.
https://heinrichapfelmus.github.io/threepenny-gui/
Other
437 stars 77 forks source link

`on UI.valueChange` not triggered until ESC pressed #171

Open jerbaroo opened 7 years ago

jerbaroo commented 7 years ago

Here is the code for the problem described below.

main :: IO ()
main = do
  startGUI defaultConfig setup

setup :: Window -> UI ()
setup window = do
  (event, handler) <- liftIO $ newEvent
  behavior         <- stepper "No file selected." event
  text             <- UI.div # sink UI.text behavior
  input            <- UI.input # set UI.type_ "file"
  -- input            <- UI.button # set UI.text "file"
  getBody window #+ map element [text, input]
  on UI.valueChange input $ const $ do
    liftIO $ handler "File selected."

Problem

Reproduce

System

Additional notes:

jerbaroo commented 7 years ago

Fix

A fix for this was not to use UI.valueChange which uses the DOM keydown event, but instead use a new event function which uses the DOM change event:

...
  on change input $ const $ do
    liftIO $ handler "File selected."

-- |change event.
change :: Element -> Event ()
change = void . domEvent "change"

The documentation for the DOM change event is very similar to that of UI.valueChange:

UI.valueChange:

Event that occurs when the user changes the value of the input element.

change:

The change event is fired for \, \