InputField not receiving focus

I have a strange problem just cropped up where my input fields won’t receive focus when clicking them with the mouse.

I’m using ElmUI, but have also replaced the ElmUI fields with Html.input fields, and I get the same behaviour.

If I hover the mouse over the fields the mouse cursor changes to the vertical carat bar as would be expected.

If I add code to change styling on mouseOver, the styling changes as expected.

If I Browser.Dom.setFocus, then the fields receive focus, and will accept text typed by the user.

If I Tab between the fields, they receive focus, and will accept text typed by the user.

But the one thing they won’t do is receive focus when clicked on :man_shrugging:

Has anyone come across this sort of problem before? Any ideas on where I start?

Many thanks

Edit: Once the field has been given focus with setFocus, clicking outside the field does not cause it to lose focus as would be expected.

Edit: This is an SPA that originally followed the elm-spa example with the Model as a Type that has branches for each page. I’ve just refactored it to use a flat model instead, and this is where this problem has arisen. So it appears that I’ve done something during the refactoring to cause this, but I don’t see what I could have done to prevent an InputField from receiving focus when clicked on - I couldn’t test until it was all wired up again, and I haven’t touched any of the view code.

Losing focus can happen if the virtual DOM overwrites an input with a new one.

I don’t know if this is your problem, but it springs to mind as an obvious candidate. Without seeing your code, its just a guess though.

1 Like

It wasn’t my exact problem, but put me on the right path.

I have an Html.Events.Extra.Pointer.onMove event that should fire once on app start up, but it was firing all the time the mouse pointer moved. Fixing this fixed my problem.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.