Improve selecting tags in the dropdown a bit

This is some low hanging fruit, related to #573, #960. At least we see
now the category and the filter is applied to it as well.
This commit is contained in:
eikek
2022-01-14 23:49:08 +01:00
parent 3841b4aadd
commit 348fd50297
2 changed files with 36 additions and 7 deletions

View File

@ -62,6 +62,7 @@ type alias Model a =
, menuOpen : Bool , menuOpen : Bool
, filterString : String , filterString : String
, searchable : Int -> Bool , searchable : Int -> Bool
, searchWithAdditional : Bool
} }
@ -77,6 +78,7 @@ makeModel input =
, available = [] , available = []
, menuOpen = False , menuOpen = False
, filterString = "" , filterString = ""
, searchWithAdditional = False
} }
@ -465,6 +467,29 @@ view2 cfg settings model =
viewSingle2 cfg settings model viewSingle2 cfg settings model
searchInValueOnly : ViewSettings a -> (a -> String)
searchInValueOnly cfg =
cfg.makeOption >> .text
searchInValueAdditional : ViewSettings a -> (a -> String)
searchInValueAdditional cfg =
let
combine item =
item.text ++ " " ++ item.additional |> String.trim
in
cfg.makeOption >> combine
searchIn : Model a -> ViewSettings a -> (a -> String)
searchIn model cfg =
if model.searchWithAdditional then
searchInValueAdditional cfg
else
searchInValueOnly cfg
viewSingle2 : ViewSettings a -> UiSettings -> Model a -> Html (Msg a) viewSingle2 : ViewSettings a -> UiSettings -> Model a -> Html (Msg a)
viewSingle2 cfg settings model = viewSingle2 cfg settings model =
let let
@ -527,7 +552,7 @@ viewSingle2 cfg settings model =
, input , input
[ type_ "text" [ type_ "text"
, placeholder cfg.placeholder , placeholder cfg.placeholder
, onInput (Filter (cfg.makeOption >> .text)) , onInput (Filter (searchIn model cfg))
, value model.filterString , value model.filterString
, class "inline-block border-0 px-0 w-full py-0 focus:ring-0 " , class "inline-block border-0 px-0 w-full py-0 focus:ring-0 "
, class cfg.style.input , class cfg.style.input
@ -603,7 +628,7 @@ viewMultiple2 cfg settings model =
, input , input
[ type_ "text" [ type_ "text"
, placeholder cfg.placeholder , placeholder cfg.placeholder
, onInput (Filter (cfg.makeOption >> .text)) , onInput (Filter (searchIn model cfg))
, value model.filterString , value model.filterString
, class "inline-flex w-16 border-0 px-0 focus:ring-0 h-6" , class "inline-flex w-16 border-0 px-0 focus:ring-0 h-6"
, class cfg.style.input , class cfg.style.input

View File

@ -22,15 +22,19 @@ import Util.List
makeDropdownModel : Comp.Dropdown.Model Tag makeDropdownModel : Comp.Dropdown.Model Tag
makeDropdownModel = makeDropdownModel =
let
init =
Comp.Dropdown.makeModel Comp.Dropdown.makeModel
{ multiple = True { multiple = True
, searchable = \n -> n > 0 , searchable = \n -> n > 0
} }
in
{ init | searchWithAdditional = True }
tagSettings : String -> DS.DropdownStyle -> Comp.Dropdown.ViewSettings Tag tagSettings : String -> DS.DropdownStyle -> Comp.Dropdown.ViewSettings Tag
tagSettings placeholder ds = tagSettings placeholder ds =
{ makeOption = \tag -> { text = tag.name, additional = "" } { makeOption = \tag -> { text = tag.name, additional = Maybe.withDefault "" tag.category }
, labelColor = , labelColor =
\tag -> \tag ->
\settings -> \settings ->