TabsInternal.V2 supports a disabled attribute

Disabled tabs can't be selected and will be skipped when navigating tabs
with the keyboard.
This commit is contained in:
Juan Edi 2021-05-25 18:11:11 -03:00
parent e7c4d8d3bf
commit 346550f96f
2 changed files with 11 additions and 1 deletions

View File

@ -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 } =

View File

@ -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 )