From 346550f96f4a93d8ebcb54a609a2af323c09be96 Mon Sep 17 00:00:00 2001 From: Juan Edi Date: Tue, 25 May 2021 18:11:11 -0300 Subject: [PATCH] TabsInternal.V2 supports a `disabled` attribute Disabled tabs can't be selected and will be skipped when navigating tabs with the keyboard. --- src/Nri/Ui/SegmentedControl/V14.elm | 1 + src/TabsInternal/V2.elm | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Nri/Ui/SegmentedControl/V14.elm b/src/Nri/Ui/SegmentedControl/V14.elm index 585120a3..9e1e57ac 100644 --- a/src/Nri/Ui/SegmentedControl/V14.elm +++ b/src/Nri/Ui/SegmentedControl/V14.elm @@ -206,6 +206,7 @@ view config = , tabView = [ viewIcon option.icon, option.label ] , panelView = option.content , spaHref = Maybe.map (\toUrl -> toUrl option.value) config.toUrl + , disabled = False } { tabList, tabPanels } = diff --git a/src/TabsInternal/V2.elm b/src/TabsInternal/V2.elm index 7c834f01..9af14867 100644 --- a/src/TabsInternal/V2.elm +++ b/src/TabsInternal/V2.elm @@ -44,6 +44,7 @@ type alias Tab id msg = , tabView : List (Html msg) , panelView : Html msg , spaHref : Maybe String + , disabled : Bool } @@ -59,6 +60,7 @@ fromList { id, idString } attributes = , tabView = [] , panelView = Html.text "" , spaHref = Nothing + , disabled = False } in List.foldl (\applyAttr acc -> applyAttr acc) defaults attributes @@ -125,6 +127,7 @@ viewTab_ config index tab = ++ tagSpecificAttributes ++ tab.tabAttributes ++ [ Attributes.tabindex tabIndex + , Attributes.disabled tab.disabled , Widget.selected isSelected , Role.tab , Attributes.id (tabToId tab.idString) @@ -160,7 +163,13 @@ keyEvents { focusAndSelect, tabs } thisTab keyCode = acc ( True, Nothing ) -> - ( True, Just { select = tab.id, focus = Just (tabToId tab.idString) } ) + ( True + , if tab.disabled then + Just { select = tab.id, focus = Just (tabToId tab.idString) } + + else + Nothing + ) ( False, Nothing ) -> ( tab.id == thisTab.id, Nothing )