on develop help sign in
add hasFocus to TextArea
commit13925827703274d717d5c0f252bd9b4780818d76 authorali abrar <aliabrar@gmail.com> dateMon 2 Mar 2015, 21:17 (12 years ago) parent3a9ee6e
1 file changed+11−1
src/Reflex/Dom/Widget/Input.hs+11−1
src/Reflex/Dom/Widget/Input.hs+11−1
@@ -110,14 +110,24 @@ textInputGetEnter i = fmapMaybe (\n -> if n == keycodeEnter then Just () else No
110110data TextArea t
111111 = TextArea { _textArea_value :: Dynamic t String
112112 , _textArea_element :: HTMLTextAreaElement
113+ , _textArea_hasFocus :: Dynamic t Bool
113114 }
114115
115116textArea :: MonadWidget t m => String -> Event t String -> Dynamic t (Map String String) -> m (TextArea t)
116117textArea initial eSet attrs = do
117118 e <- liftM castToHTMLTextAreaElement $ buildEmptyElement "textarea" attrs
119+ postGui <- askPostGui
120+ runWithActions <- askRunWithActions
121+ eChangeFocus <- newEventWithTrigger $ \eChangeFocusTrigger -> do
122+ unsubscribeOnblur <- liftIO $ elementOnblur e $ liftIO $ do
123+ postGui $ runWithActions [eChangeFocusTrigger :=> False]
124+ unsubscribeOnfocus <- liftIO $ elementOnfocus e $ liftIO $ do
125+ postGui $ runWithActions [eChangeFocusTrigger :=> True]
126+ return $ liftIO $ unsubscribeOnblur >> unsubscribeOnfocus
127+ f <- holdDyn False eChangeFocus
118128 ev <- wrapDomEvent e elementOninput $ liftIO $ htmlTextAreaElementGetValue e
119129 v <- holdDyn "" ev
120− return $ TextArea v e
130+ return $ TextArea v e f
121131
122132{-
123133type family Controller sm t a where