@@ -156,10 +156,6 @@ import Html as Html
156156import Html.Attributes exposing (id , selected , tabindex )
157157
158158
159- type alias TabSettings =
160- { id : String , controls : List String , selected : Bool }
161-
162-
163159{- | All inputs must be associated with a `label`.
164160
165161 labelBefore [] viewLabel viewInput
@@ -286,45 +282,11 @@ checkbox value_ maybeChecked attributes =
286282
287283{- | Create a tablist. This is the outer container for a list of tabs.
288284-}
289- tabList : List (Attribute Never ) -> List (Html msg ) -> Html msg
290- tabList attributes =
291- Html . div ( Role . tabList :: nonInteractive attributes)
292-
293-
294- {- | Create a tab. This is the part that you select in order to change panel views.
295-
296- You'll want to listen for click events **and** for keyboard events: when users hit
297- the right and left keys on their keyboards, they expect for the selected tab to change.
298-
299- tab { id = "tab-1", controls = [ "element-1" ], selected = True } [] [ Html.p [] [ Html.text "Hello 1" ] ]
300-
301- -}
302- tab : TabSettings -> List (Html .Attribute msg ) -> List (Html msg ) -> Html msg
303- tab settings attributes =
304- Html . div
305- ( Role . tab
306- :: Key . tabbable True
307- :: id settings. id
308- :: Aria . controls settings. controls
309- :: selected settings. selected
310- :: Aria . selected settings. selected
311- :: attributes
312- )
313-
314-
315- {- | Create a tab panel.
316-
317- tabpanel []
318- [ ( { id = "tab-1", controls = [ "element-1" ], selected = True }, Html.p [] [ Html.text "Hello 1" ] )
319- , ( { id = "tab-2", controls = [ "element-2" ], selected = False }, Html.p [] [ Html.text "Hello 2" ] )
320- ]
321-
322- -}
323- tabPanel : List (Attribute Never ) -> List ( TabSettings , Html msg ) -> Html msg
324- tabPanel attributes childrenWithSettings =
285+ tabList : List (Attribute Never ) -> List ( { id : String , controls : List String , selected : Bool }, Html msg ) -> Html msg
286+ tabList attributes childrenWithSettings =
325287 let
326288 {-
327- Only 0 or 1 children of a tab panel can ever be selected at any time.
289+ Only 0 or 1 children of a tabs can ever be selected at any time.
328290 -}
329291 validChildren : Bool
330292 validChildren =
@@ -333,7 +295,7 @@ tabPanel attributes childrenWithSettings =
333295 |> List . length
334296 |> flip List . member [ 0 , 1 ]
335297
336- toTab : ( TabSettings , Html msg ) -> Html msg
298+ toTab : ( { id : String , controls : List String , selected : Bool } , Html msg ) -> Html msg
337299 toTab ( settings, el ) =
338300 tab settings
339301 [ tabindex
@@ -347,7 +309,7 @@ tabPanel attributes childrenWithSettings =
347309 ]
348310 [ el ]
349311
350- correctChildrenSelectionStates : ( TabSettings , Html msg ) -> ( List ( TabSettings , Html msg ) , Bool ) -> ( List ( TabSettings , Html msg ) , Bool )
312+ correctChildrenSelectionStates : ( { id : String , controls : List String , selected : Bool }, Html msg ) -> ( List ( { id : String , controls : List String , selected : Bool }, Html msg ) , Bool ) -> ( List ( { id : String , controls : List String , selected : Bool } , Html msg ) , Bool )
351313 correctChildrenSelectionStates ( settings, element ) ( elements, hasSelectedEl ) =
352314 if not hasSelectedEl && settings. selected then
353315 ( List . append elements [ ( settings, element ) ], True )
@@ -357,14 +319,45 @@ tabPanel attributes childrenWithSettings =
357319 in
358320 if validChildren then
359321 Html . div
360- ( Role . tabPanel :: nonInteractive attributes)
322+ ( Role . tabList :: nonInteractive attributes)
361323 ( List . map toTab childrenWithSettings)
362324
363325 else
364- -- In the case that multiple tabs are selected, only allow the first one to actually be and reset the others to have a selected state of False.
365326 Html . div
366- ( Role . tabPanel :: nonInteractive attributes)
367- ( childrenWithSettings |> List . foldl correctChildrenSelectionStates ( [], False ) |> Tuple . first |> List . map toTab)
327+ ( Role . tabList :: nonInteractive attributes)
328+ ( childrenWithSettings
329+ |> List . foldl correctChildrenSelectionStates ( [], False )
330+ |> Tuple . first
331+ |> List . map toTab
332+ )
333+
334+
335+ {- | Create a tab. This is the part that you select in order to change panel views.
336+
337+ You'll want to listen for click events **and** for keyboard events: when users hit
338+ the right and left keys on their keyboards, they expect for the selected tab to change.
339+
340+ tab { id = "tab-1", controls = [ "element-1" ], selected = True } [] [ Html.p [] [ Html.text "Hello 1" ] ]
341+
342+ -}
343+ tab : { id : String , controls : List String , selected : Bool } -> List (Html .Attribute msg ) -> List (Html msg ) -> Html msg
344+ tab settings attributes =
345+ Html . div
346+ ( Role . tab
347+ :: Key . tabbable True
348+ :: id settings. id
349+ :: Aria . controls settings. controls
350+ :: selected settings. selected
351+ :: Aria . selected settings. selected
352+ :: attributes
353+ )
354+
355+
356+ {- | Create a tab panel.
357+ -}
358+ tabPanel : List (Attribute Never ) -> List (Html msg ) -> Html msg
359+ tabPanel attributes =
360+ Html . div ( Role . tabPanel :: nonInteractive attributes)
368361
369362
370363
0 commit comments