Skip to content

Commit

Permalink
add focus on click version
Browse files Browse the repository at this point in the history
  • Loading branch information
wintvelt committed Nov 26, 2016
1 parent c4f3cbc commit a77a1f8
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/dropdown-2.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ main =
-- our main model, which will change as we use the app
type alias Model =
{ pickedFruit : Maybe Fruit
, focusedId : Maybe DomID
, focusedId : Maybe NodeID
}

-- simple types so we can read the code better
type alias Fruit = String
type alias DomID = String
type alias NodeID = String

-- global constants/ config
assortment : List String
Expand All @@ -40,6 +40,7 @@ assortment =
init : ( Model, Cmd Msg )
init =
{ pickedFruit = Nothing
, focusedId = Nothing
} ! []


Expand All @@ -49,13 +50,17 @@ init =

type Msg
= FruitPicked Fruit
| FocusOn NodeID


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
FruitPicked fruit ->
{ model | pickedFruit = Just fruit } ! []
{ model | pickedFruit = Just fruit } ! []

FocusOn nodeID ->
{ model | focusedId = Just nodeID } ! []



Expand All @@ -80,10 +85,19 @@ view model =
|> Maybe.withDefault "-- pick a fruit --"
|> flip String.append ""

displayStyle =
case model.focusedId of
Just "myDropdown" ->
style [("display", "block")]

_ ->
style [("display", "none")]

in
div []
[ p [] [ text <| itemText ]
, ul []
[ p [ onClick <| FocusOn "myDropdown" ]
[ text <| itemText ]
, ul [ displayStyle ]
(List.map viewFruit assortment)
]

Expand Down

0 comments on commit a77a1f8

Please sign in to comment.