Adds clickablesvg click stop prop

This commit is contained in:
Tessa Kelly 2022-04-25 17:22:54 -07:00
parent 4e4a654d88
commit 1c524d9b91
3 changed files with 24 additions and 6 deletions

View File

@ -8,6 +8,7 @@ module ClickableAttributes exposing
, linkWithMethod , linkWithMethod
, linkWithTracking , linkWithTracking
, onClick , onClick
, onClickStopPropagation
, toButtonAttributes , toButtonAttributes
, toLinkAttributes , toLinkAttributes
) )
@ -28,6 +29,7 @@ type alias ClickableAttributes route msg =
, url : Maybe route , url : Maybe route
, urlString : Maybe String , urlString : Maybe String
, onClick : Maybe msg , onClick : Maybe msg
, stopPropagation : Bool
} }
@ -47,6 +49,7 @@ init =
, url = Nothing , url = Nothing
, urlString = Nothing , urlString = Nothing
, onClick = Nothing , onClick = Nothing
, stopPropagation = False
} }
@ -56,6 +59,12 @@ onClick msg clickableAttributes =
{ clickableAttributes | onClick = Just msg } { clickableAttributes | onClick = Just msg }
{-| -}
onClickStopPropagation : msg -> ClickableAttributes route msg -> ClickableAttributes route msg
onClickStopPropagation msg clickableAttributes =
{ clickableAttributes | onClick = Just msg, stopPropagation = True }
{-| -} {-| -}
href : route -> ClickableAttributes route msg -> ClickableAttributes route msg href : route -> ClickableAttributes route msg -> ClickableAttributes route msg
href url clickableAttributes = href url clickableAttributes =
@ -105,8 +114,12 @@ toButtonAttributes : ClickableAttributes route msg -> List (Attribute msg)
toButtonAttributes clickableAttributes = toButtonAttributes clickableAttributes =
case clickableAttributes.onClick of case clickableAttributes.onClick of
Just handler -> Just handler ->
if clickableAttributes.stopPropagation then
[ Events.onClick handler ] [ Events.onClick handler ]
else
[ EventExtras.onClickStopPropagation handler ]
Nothing -> Nothing ->
[] []

View File

@ -1,7 +1,7 @@
module Nri.Ui.ClickableSvg.V2 exposing module Nri.Ui.ClickableSvg.V2 exposing
( button, link ( button, link
, Attribute , Attribute
, onClick , onClick, onClickStopPropagation
, href, linkSpa, linkExternal, linkWithMethod, linkWithTracking, linkExternalWithTracking , href, linkSpa, linkExternal, linkWithMethod, linkWithTracking, linkExternalWithTracking
, exactSize, exactWidth, exactHeight , exactSize, exactWidth, exactHeight
, disabled , disabled
@ -28,7 +28,7 @@ module Nri.Ui.ClickableSvg.V2 exposing
## Behavior ## Behavior
@docs onClick @docs onClick, onClickStopPropagation
@docs href, linkSpa, linkExternal, linkWithMethod, linkWithTracking, linkExternalWithTracking @docs href, linkSpa, linkExternal, linkWithMethod, linkWithTracking, linkExternalWithTracking
@ -116,6 +116,12 @@ onClick msg =
setClickableAttributes (ClickableAttributes.onClick msg) setClickableAttributes (ClickableAttributes.onClick msg)
{-| -}
onClickStopPropagation : msg -> Attribute msg
onClickStopPropagation msg =
setClickableAttributes (ClickableAttributes.onClickStopPropagation msg)
{-| -} {-| -}
href : String -> Attribute msg href : String -> Attribute msg
href url = href url =

View File

@ -13,7 +13,6 @@ import Css
import Debug.Control as Control exposing (Control) import Debug.Control as Control exposing (Control)
import Debug.Control.Extra as ControlExtra import Debug.Control.Extra as ControlExtra
import Debug.Control.View as ControlView import Debug.Control.View as ControlView
import EventExtras
import Example exposing (Example) import Example exposing (Example)
import Html.Styled as Html exposing (Html) import Html.Styled as Html exposing (Html)
import Html.Styled.Attributes as Attributes import Html.Styled.Attributes as Attributes
@ -96,7 +95,7 @@ Tooltip.view
ClickableSvg.button "Preview" ClickableSvg.button "Preview"
UiIcon.preview UiIcon.preview
[ ClickableSvg.custom attrs, [ ClickableSvg.custom attrs,
, ClickableSvg.custom [ EventExtras.onClickStopPropagation (ShowItWorked "You clicked the preview button!") ] , ClickableSvg.onClickStopPropagation (ShowItWorked "You clicked the preview button!")
] ]
, id = "preview-tooltip" , id = "preview-tooltip"
} }
@ -115,7 +114,7 @@ Tooltip.view
ClickableSvg.button "Preview" ClickableSvg.button "Preview"
UiIcon.preview UiIcon.preview
[ ClickableSvg.custom attrs [ ClickableSvg.custom attrs
, ClickableSvg.custom [ EventExtras.onClickStopPropagation (ShowItWorked "You clicked the preview button!") ] , ClickableSvg.onClickStopPropagation (ShowItWorked "You clicked the preview button!")
] ]
, id = "preview-tooltip" , id = "preview-tooltip"
} }