Created
March 8, 2019 03:25
-
-
Save ali-abrar/a9221b24b1b1a7ba75be4cdb392c1f23 to your computer and use it in GitHub Desktop.
Link with prevent default on click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
import Control.Lens ((&), (%~), (.~)) | |
import Data.Proxy | |
import Reflex.Dom | |
main :: IO () | |
main = mainWidget $ do | |
(click, ()) <- linkPreventDefault $ text "O.S." | |
display =<< count click | |
linkPreventDefault :: forall t m a. DomBuilder t m => m a -> m (Event t (), a) | |
linkPreventDefault c = do | |
let cfg = (def :: ElementConfig EventResult t (DomBuilderSpace m)) | |
& elementConfig_initialAttributes .~ ("href" =: "https://obsidian.systems") | |
& elementConfig_eventSpec %~ addEventSpecFlags (Proxy :: Proxy (DomBuilderSpace m)) Click (const preventDefault) | |
(link, a) <- element "a" cfg c | |
return (domEvent Click link, a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment