DEV Community

Discussion on: Elm DOM node decoder to detect click outside

Collapse
 
kutyel profile image
Flavio Corpa • Edited

Love this post, it has saved me a couple of times, thank you very much for putting it together!! 🙌

Just wanted to point that there is a slight mistake in the implementation of oustideTarget, you are not using the provided String param anywhere, and thus would have to duplicate the dropdown-id, a fix would be:

outsideTarget : String -> Decode.Decoder Msg
outsideTarget dropdownId =
    Decode.field "target" (isOutsideDropdown dropdownId)
        |> Decode.andThen
            (\isOutside ->
                if isOutside then
                    Decode.succeed Close

                else
                    Decode.fail "inside dropdown"
            )
Enter fullscreen mode Exit fullscreen mode