Skip to content

Instantly share code, notes, and snippets.

@roSievers
Created October 23, 2016 18:13
Show Gist options
  • Save roSievers/78f0a533b047d295d549453ae3db49d5 to your computer and use it in GitHub Desktop.
Save roSievers/78f0a533b047d295d549453ae3db49d5 to your computer and use it in GitHub Desktop.
OnRightClick can't be implemented using onWithOptions.
import Html exposing (div, button, text)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick, onWithOptions)
import Json.Decode as Json
main =
beginnerProgram { model = 0, view = view, update = update }
view model =
div []
[ button [ onRightClick Decrement ] [ text "-" ]
, div [] [ text (toString model) ]
, button [ onClick Increment ] [ text "+" ]
]
onRightClick message =
onWithOptions
"oncontextmenu"
{ stopPropagation = True
, preventDefault = True
}
(Json.succeed message)
type Msg = Increment | Decrement
update msg model =
case msg of
Increment ->
model + 1
Decrement ->
model - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment