An update, in case anyone is interested: I ended up using 
`Html.Attributes.property` to set a distinguished property (rather than an 
attribute) on any of the menu's focusable descendants and then checked for 
the existence of that property on the event's relatedTarget. So I was able 
to avoid traversing the tree, and my solution was similar to Eric's.

On Thursday, April 6, 2017 at 4:12:39 PM UTC-4, Jon Zeppieri wrote:
>
> Thanks for your response. I think our cases are a bit different -- the 
> element that you're putting a blur handler on has no children -- but I 
> might be able to use a similar approach, nevertheless. -J
>
>
> On Thursday, April 6, 2017 at 3:17:22 PM UTC-4, Eric G wrote:
>>
>> I did this by requiring an id for the menu element in config, and then 
>> checking the id of relatedTarget against this, on blur.
>>
>> See: 
>> https://github.com/ericgj/elm-autoinput/blob/master/src/Autoinput.elm#L357
>>
>> I'm not convinced it's the best way but it worked for me for the moment.
>>
>>
>> On Thursday, April 6, 2017 at 2:30:52 PM UTC-4, Jon Zeppieri wrote:
>>>
>>> I have a menu that, when it loses focus, needs to generate an update 
>>> message to close the menu. Of course the menu is composed, at the DOM 
>>> level, of several nodes. If I attach a blur or focusout handler at the 
>>> menu's root element, it is fired whenever that particular element loses 
>>> focus, even if one of its descendants gains it.  But in that case I do not 
>>> want to close the menu. There are a few ways to handle this in the DOM, 
>>> perhaps the best of which (as far as I know) is to use a focusout handler 
>>> at the root of the menu that looks to see if the event's relatedTarget is a 
>>> descendant of the root.
>>>
>>> In Elm, I can define a Json decoder that will climb the DOM tree, but 
>>> equality isn't defined over Json.Decoder.Value(s) (I think), which suggests 
>>> that the root node would need to be tagged in some way that a Json decoder 
>>> can see. And now we're getting into very hacky territory.
>>>
>>> So... is there a better way to accomplish this? (By the way, yes, I 
>>> really do want to know if the menu loses focus, not just if someone has 
>>> clicked outside of it.)
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to