From 365d625ccafcd2a8001ab0ab3b43ea6458aa61c8 Mon Sep 17 00:00:00 2001 From: Juan Edi Date: Tue, 8 Sep 2020 15:26:06 -0300 Subject: [PATCH] don't case now that we use a single constructor --- src/Nri/Ui/FocusTrap/V1.elm | 48 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/Nri/Ui/FocusTrap/V1.elm b/src/Nri/Ui/FocusTrap/V1.elm index 16322926..1a850600 100644 --- a/src/Nri/Ui/FocusTrap/V1.elm +++ b/src/Nri/Ui/FocusTrap/V1.elm @@ -32,36 +32,34 @@ type FocusTrap {-| Attach this attribute to add a focus trap to an HTML element. -} toAttribute : (String -> msg) -> FocusTrap -> Html.Attribute msg -toAttribute focus trap = +toAttribute focus (FocusTrap { firstId, lastId }) = onTab <| \elementId shiftKey -> - case trap of - FocusTrap { firstId, lastId } -> - -- if the user tabs back while on the first id, - -- we want to wrap around to the last id. - if elementId == firstId && shiftKey then - Decode.succeed - { message = focus lastId - , preventDefault = True - , stopPropagation = False - } + -- if the user tabs back while on the first id, + -- we want to wrap around to the last id. + if elementId == firstId && shiftKey then + Decode.succeed + { message = focus lastId + , preventDefault = True + , stopPropagation = False + } - else if elementId == lastId && not shiftKey then - -- if the user tabs forward while on the last id, - -- we want to wrap around to the first id. - Decode.succeed - { message = focus firstId + else if elementId == lastId && not shiftKey then + -- if the user tabs forward while on the last id, + -- we want to wrap around to the first id. + Decode.succeed + { message = focus firstId - -- Will this preventDefault break anything - -- if the element is an input - -- or dropdown (if the element has key-based - -- behavior already)? - , preventDefault = True - , stopPropagation = False - } + -- Will this preventDefault break anything + -- if the element is an input + -- or dropdown (if the element has key-based + -- behavior already)? + , preventDefault = True + , stopPropagation = False + } - else - Decode.fail "No need to intercept the key press" + else + Decode.fail "No need to intercept the key press" onTab do =