@@ -18,12 +18,10 @@ import Halogen.HTML.Properties as HP
1818import Halogen.Query.EventSource as ES
1919import Web.DOM.Document as Document
2020import Web.DOM.ParentNode as ParentNode
21- import Web.HTML (window ) as Web
2221import Web.HTML as HTML
2322import Web.HTML.HTMLDocument as HTMLDocument
24- import Web.HTML.HTMLElement ( blur , focus ) as Web
23+ import Web.HTML.HTMLElement as HTMLElement
2524import Web.HTML.HTMLInputElement as HTMLInputElement
26- import Web.HTML.Window (document ) as Web
2725import Web.HTML.Window as Window
2826import Web.UIEvent.KeyboardEvent (KeyboardEvent )
2927import Web.UIEvent.KeyboardEvent as KE
@@ -78,7 +76,7 @@ handleAction = case _ of
7876
7977 InitKeyboardListener -> do
8078
81- document <- H .liftEffect $ Web .document =<< Web .window
79+ document <- H .liftEffect $ Window .document =<< HTML .window
8280 H .subscribe' \sid ->
8381 ES .eventListenerEventSource
8482 KET .keyup
@@ -92,14 +90,14 @@ handleAction = case _ of
9290 when (not state.focused) do
9391 H .liftEffect do
9492 withSearchField HTMLInputElement .select
95- withSearchField (HTMLInputElement .toHTMLElement >>> Web .focus)
93+ withSearchField (HTMLInputElement .toHTMLElement >>> HTMLElement .focus)
9694
9795 when (KE .code ev == " Escape" ) do
9896 state <- H .get
9997 if state.focused
10098 then do
10199 H .liftEffect do
102- withSearchField (HTMLInputElement .toHTMLElement >>> Web .blur)
100+ withSearchField (HTMLInputElement .toHTMLElement >>> HTMLElement .blur)
103101 else clearInput
104102
105103 InputAction input -> do
@@ -108,16 +106,22 @@ handleAction = case _ of
108106 EnterPressed -> do
109107 state <- H .get
110108 H .liftEffect do
111- withSearchField (HTMLInputElement .toHTMLElement >>> Web .blur)
109+ withSearchField (HTMLInputElement .toHTMLElement >>> HTMLElement .blur)
112110 H .liftEffect (URIHash .setInput state.input)
113111 H .raise $ InputUpdated state.input
114112
115- FocusChanged status -> do
116- H .modify_ (_ { focused = status })
113+ FocusChanged isFocused -> do
114+ H .modify_ (_ { focused = isFocused })
117115 H .raise
118- if status
116+ if isFocused
119117 then Focused
120118 else LostFocus
119+ when isFocused scrollToTop
120+
121+ scrollToTop :: H.HalogenM State Action () SearchFieldMessage Aff Unit
122+ scrollToTop = do
123+ H .liftEffect do
124+ HTML .window >>= Window .scroll 0 0
121125
122126clearInput :: H.HalogenM State Action () SearchFieldMessage Aff Unit
123127clearInput = do
0 commit comments