From 7c6d6f01fd0756c31a05a4d0a1c1d09745d21cc2 Mon Sep 17 00:00:00 2001 From: Michael Glass Date: Tue, 21 Aug 2018 16:28:03 -0700 Subject: [PATCH] Dry up toggleButton --- src/Nri/Ui/Button/V3.elm | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/Nri/Ui/Button/V3.elm b/src/Nri/Ui/Button/V3.elm index 0330d04a..a8c22bbc 100644 --- a/src/Nri/Ui/Button/V3.elm +++ b/src/Nri/Ui/Button/V3.elm @@ -330,25 +330,22 @@ toggleButton config = (buttonStyles Medium Nothing SecondaryColors Button ++ toggledStyles ) - (if config.pressed then - [ Events.onClick config.onDeselect - , Widget.pressed <| Just True + [ Events.onClick + (if config.pressed then + config.onDeselect + else + config.onSelect + ) + , Widget.pressed <| Just config.pressed - -- reference: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role#Labeling_buttons - , Role.button + -- reference: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role#Labeling_buttons + , Role.button - -- Note: setting type: 'button' removes the default behavior of submit - -- equivalent to preventDefaultBehavior = false - -- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-name - , Attributes.type_ "button" - ] - else - [ Events.onClick config.onSelect - , Widget.pressed <| Just False - , Role.button - , Attributes.type_ "button" - ] - ) + -- Note: setting type: 'button' removes the default behavior of submit + -- equivalent to preventDefaultBehavior = false + -- https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-name + , Attributes.type_ "button" + ] (viewLabel Nothing config.label)