Skip to content

Commit

Permalink
Click outside modal
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Nov 30, 2023
1 parent 3c75143 commit f35719c
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/UI/Modal.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module UI.Modal exposing

import Html exposing (Attribute, Html, a, div, footer, h2, header, section, text)
import Html.Attributes as Attributes exposing (class, classList, id, tabindex)
import Html.Events exposing (on, onClick)
import Json.Decode as Decode
import Html.Events exposing (onClick)
import Lib.OnClickOutside exposing (onClickOutside)
import UI
import UI.Button as Button exposing (Button)
import UI.Icon as Icon
Expand Down Expand Up @@ -209,9 +209,11 @@ view_ closeMsg attrs content_ =
( modalContent, onEsc ) =
case closeMsg of
Just closeMsg_ ->
-- TODO: this should be OnClickOutside instead?
( div [ id overlayId, on "click" (decodeOverlayClick closeMsg_) ]
[ div (tabindex 0 :: class "modal" :: attrs) content_
( div [ id overlayId ]
[ onClickOutside closeMsg_
(div (tabindex 0 :: class "modal" :: attrs)
content_
)
]
, Just closeMsg_
)
Expand All @@ -229,16 +231,3 @@ view_ closeMsg attrs content_ =
overlayId : String
overlayId =
"modal-overlay"


decodeOverlayClick : msg -> Decode.Decoder msg
decodeOverlayClick closeMsg =
Decode.at [ "target", "id" ] Decode.string
|> Decode.andThen
(\c ->
if String.contains overlayId c then
Decode.succeed closeMsg

else
Decode.fail "ignoring"
)

0 comments on commit f35719c

Please sign in to comment.