The ‘or’ isn’t part of the code but the ‘new and improved’ (!!) discourse system won’t let me remove ‘pre-formatted’ from it without removing it from the actual code as well!
update : Msg → Model → ( Model, Cmd.Cmd Msg )
update msg model =
case msg of
FocusChange focusOrBlur →
Debug.log(Debug.toString focusOrBlur) -- <-- NO OUTPUT in Dev console
( { model | focusOrBlur = focusOrBlur }
, Cmd.none
)
Clicking between the app and another window has no effect.
Depending on which element you are registering the events on, you need to use focusin / focusout events instead of focus and blur. Thats because the focus and blur events dont bubble.
You can use Html.Events.on to build to build attributes for these events:
I added your code, and the equivalent for blur, to layout and got some strange results:
If I click on a non-button/non-active part of the app, and another window, I still get nothing.
If I click on a button which takes me to a new view, I get Focus immediately followed by Blur.
I assumed that the overall div withing a window had focus when it was clicked, or when the window was brought up, and lost focus when somewhere outside of it was clicked or when the window was dropped.
Perhaps describe what functionality you’re trying to achieve?
It sounds like maybe you’re trying to figure out when the app has focus, so that for example you can avoid doing things like downloading new data when the user is not actually using the app?
If so, it is perhaps Browser.Events.onVisibilityChange that you are looking for?
Update Ah never mind, I hadn’t read the next topic, so I see your general query is now solved.