Skip to content

Commit

Permalink
Replace use of datalist with ul
Browse files Browse the repository at this point in the history
Datalist was nice for spike, but it behaves strangely in our usecase
when it's dynamically generated based on typeahead search — correct
results were shown after putting one additional character than
required.

It also can't be styled.

Current solution doesn't have keyboard support, but it will be added
eventually.
  • Loading branch information
fidel committed Mar 22, 2024
1 parent 5a8b468 commit 1227afe
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions ruby_event_store-browser/elm/src/Search.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Search exposing (..)

import FeatherIcons
import Html exposing (..)
import Html.Attributes exposing (autofocus, class, id, list, placeholder, value)
import Html.Attributes exposing (autofocus, class, href, placeholder, value)
import Html.Events exposing (onInput, onSubmit)
import List
import Task
Expand Down Expand Up @@ -84,18 +84,37 @@ view model =
, value model.value
, onInput StreamChanged
, placeholder "Quick search…"
, list "streams"
, autofocus True
]
[]
, span [ class "absolute top-0 h-full flex items-center right-3 text-[.5rem] pointer-events-none" ]
[ span [ class "text-gray-500 bg-gray-50 font-bold block p-1 border border-gray-300 rounded " ] [ text "ESC" ]
]
]
, datalist
[ id "streams", class "appearance-none" ]
, if model |> streamsPresent then
viewList model

else
text ""
]


viewList : Model a -> Html Msg
viewList model =
div
[]
[ ul [ class "mt-4 h-80 overflow-auto space-y-2 w-full" ]
(List.map
(\stream -> option [] [ text stream ])
(\stream ->
li []
[ a [ class "p-3 block rounded hover:bg-red-200 w-full bg-gray-100 break-words text-xs font-bold font-mono", href ("/streams/" ++ stream) ] [ text stream ]
]
)
model.streams
)
]


streamsPresent : Model a -> Bool
streamsPresent { streams } =
not <| List.isEmpty streams

0 comments on commit 1227afe

Please sign in to comment.