Require an id

I think, since we should label our selects, that it's not unreasonable to require an id
This commit is contained in:
Tessa Kelly 2020-01-16 11:56:17 -08:00
parent 44bbf5272a
commit c2f0f883bd
2 changed files with 5 additions and 8 deletions

View File

@ -31,7 +31,7 @@ type alias Choice a =
view :
{ choices : List (Choice a)
, current : Maybe a
, id : Maybe String
, id : String
, valueToString : a -> String
, defaultDisplayText : Maybe String
}
@ -64,11 +64,6 @@ view config =
|> Maybe.map (viewDefaultChoice config.current >> List.singleton)
|> Maybe.withDefault []
extraAttrs =
config.id
|> Maybe.map (\id -> [ Attributes.id id ])
|> Maybe.withDefault []
currentVal =
if config.current == Nothing && config.defaultDisplayText == Nothing then
config.choices
@ -92,7 +87,9 @@ view config =
, Css.height (Css.px 45)
, Css.width (Css.pct 100)
]
([ onSelectHandler ] ++ extraAttrs)
[ onSelectHandler
, Attributes.id config.id
]
viewDefaultChoice : Maybe a -> String -> Html a

View File

@ -39,7 +39,7 @@ example parentMessage state =
, { label = "Burritos", value = "Burritos" }
, { label = "Enchiladas", value = "Enchiladas" }
]
, id = Just "tortilla-selector"
, id = "tortilla-selector"
, valueToString = identity
, defaultDisplayText = Just "Select a tasty tortilla based treat!"
}