From 4c0ef73fa899c9d7c66b14084375dc1f513f61a2 Mon Sep 17 00:00:00 2001 From: Tessa Kelly Date: Wed, 2 Sep 2020 11:02:24 -0700 Subject: [PATCH] Switch to prevent default keydown event --- src/Nri/Ui/Modal/V11.elm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Nri/Ui/Modal/V11.elm b/src/Nri/Ui/Modal/V11.elm index 06ed2488..9df5a0fa 100644 --- a/src/Nri/Ui/Modal/V11.elm +++ b/src/Nri/Ui/Modal/V11.elm @@ -64,7 +64,8 @@ import Css exposing (..) import Css.Transitions import Html.Styled as Root import Html.Styled.Attributes as Attrs exposing (id) -import Html.Styled.Events exposing (onClick) +import Html.Styled.Events as Events exposing (onClick) +import Json.Decode as Decode exposing (Decoder) import Nri.Ui.Colors.Extra import Nri.Ui.Colors.V1 as Colors import Nri.Ui.Fonts.V1 as Fonts @@ -438,7 +439,7 @@ viewModal config styles = toContentAndFooter { onlyFocusableElement = List.map (Attrs.map config.wrapMsg) - [ Key.onKeyDown + [ onKeyDownPreventDefault [ Key.tabBack (Focus autofocusId) , Key.tab (Focus autofocusId) ] @@ -451,12 +452,16 @@ viewModal config styles = toContentAndFooter { firstFocusableElement = List.map (Attrs.map config.wrapMsg) - [ Key.onKeyDown [ Key.tabBack (Focus lastId) ] + [ onKeyDownPreventDefault + [ Key.tabBack (Focus lastId) + ] , id firstId ] , lastFocusableElement = List.map (Attrs.map config.wrapMsg) - [ Key.onKeyDown [ Key.tab (Focus firstId) ] + [ onKeyDownPreventDefault + [ Key.tab (Focus firstId) + ] , id lastId ] , autofocusElement = @@ -466,6 +471,12 @@ viewModal config styles = ] +onKeyDownPreventDefault : List (Decoder msg) -> Html.Attribute msg +onKeyDownPreventDefault decoders = + Events.preventDefaultOn "keydown" + (Decode.oneOf (List.map (Decode.map (\msg -> ( msg, True ))) decoders)) + + {-| -} viewContent : Bool -> { content : List (Html msg), footer : List (Html msg) } -> Html msg viewContent visibleTitle { content, footer } =