mirror of
https://github.com/NoRedInk/noredink-ui.git
synced 2024-09-21 20:27:36 +03:00
Improve the FocusLoop API a bit by making it more general
This commit is contained in:
parent
f0b6445e64
commit
2af38e858c
@ -274,8 +274,7 @@ view_ { entries, focus, leftId } =
|
||||
[ Html.Styled.Keyed.node "div"
|
||||
[]
|
||||
(FocusLoop.addEvents
|
||||
{ toId = \(AccordionEntry { headerId } _) -> headerId
|
||||
, focus = focus
|
||||
{ focus = \(AccordionEntry { headerId } _) -> focus headerId
|
||||
, leftRight = False
|
||||
, upDown = True
|
||||
}
|
||||
|
@ -11,8 +11,7 @@ import Accessibility.Styled.Key as Key exposing (Event)
|
||||
|
||||
{-| -}
|
||||
addEvents :
|
||||
{ toId : a -> String
|
||||
, focus : String -> msg
|
||||
{ focus : a -> msg
|
||||
, leftRight : Bool
|
||||
, upDown : Bool
|
||||
}
|
||||
@ -31,8 +30,7 @@ addEvents config items =
|
||||
|
||||
|
||||
addEvents_ :
|
||||
{ toId : a -> String
|
||||
, focus : String -> msg
|
||||
{ focus : a -> msg
|
||||
, leftRight : Bool
|
||||
, upDown : Bool
|
||||
}
|
||||
@ -40,21 +38,17 @@ addEvents_ :
|
||||
-> List ( a, List (Event msg) )
|
||||
addEvents_ config items =
|
||||
let
|
||||
ids : List String
|
||||
ids =
|
||||
List.map config.toId items
|
||||
|
||||
previousIds : List (Maybe String)
|
||||
previousIds : List (Maybe a)
|
||||
previousIds =
|
||||
finalId :: List.map Just ids
|
||||
finalId :: List.map Just items
|
||||
|
||||
firstId : Maybe String
|
||||
firstId : Maybe a
|
||||
firstId =
|
||||
List.head ids
|
||||
List.head items
|
||||
|
||||
finalId : Maybe String
|
||||
finalId : Maybe a
|
||||
finalId =
|
||||
List.head (List.reverse ids)
|
||||
List.head (List.reverse items)
|
||||
in
|
||||
List.map2 (\id nextItem -> ( id, nextItem )) previousIds items
|
||||
|> List.foldr
|
||||
@ -78,7 +72,7 @@ addEvents_ config items =
|
||||
else
|
||||
[]
|
||||
in
|
||||
( Just (config.toId item)
|
||||
( Just item
|
||||
, ( item, List.filterMap identity (leftRightEvents ++ upDownEvents) ) :: acc
|
||||
)
|
||||
)
|
||||
|
@ -19,6 +19,7 @@ import Html.Styled as Html exposing (Attribute, Html)
|
||||
import Html.Styled.Attributes as Attributes
|
||||
import Html.Styled.Events as Events
|
||||
import Html.Styled.Keyed as Keyed
|
||||
import Nri.Ui.FocusLoop.V1 as FocusLoop
|
||||
import Nri.Ui.FocusRing.V1 as FocusRing
|
||||
import Nri.Ui.Html.Attributes.V2 as AttributesExtra exposing (safeId, safeIdWithPrefix)
|
||||
import Nri.Ui.Tooltip.V3 as Tooltip
|
||||
|
@ -128,8 +128,7 @@ allCases startingList expected =
|
||||
[ test "without left/right or up/down events" <|
|
||||
\() ->
|
||||
FocusLoop.addEvents
|
||||
{ toId = identity
|
||||
, focus = identity
|
||||
{ focus = identity
|
||||
, leftRight = False
|
||||
, upDown = False
|
||||
}
|
||||
@ -138,8 +137,7 @@ allCases startingList expected =
|
||||
, test "with left/right and without up/down events" <|
|
||||
\() ->
|
||||
FocusLoop.addEvents
|
||||
{ toId = identity
|
||||
, focus = identity
|
||||
{ focus = identity
|
||||
, leftRight = True
|
||||
, upDown = False
|
||||
}
|
||||
@ -148,8 +146,7 @@ allCases startingList expected =
|
||||
, test "without left/right and with up/down events" <|
|
||||
\() ->
|
||||
FocusLoop.addEvents
|
||||
{ toId = identity
|
||||
, focus = identity
|
||||
{ focus = identity
|
||||
, leftRight = False
|
||||
, upDown = True
|
||||
}
|
||||
@ -158,8 +155,7 @@ allCases startingList expected =
|
||||
, test "with left/right and up/down events" <|
|
||||
\() ->
|
||||
FocusLoop.addEvents
|
||||
{ toId = identity
|
||||
, focus = identity
|
||||
{ focus = identity
|
||||
, leftRight = True
|
||||
, upDown = True
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user