How can I ensure only one component remains highlighted at a time in Elm 0 17

0 votes
can someone help me with How can I ensure only one component remains highlighted at a time in Elm 0.17?
Feb 21 in Web Development by Nidhi
• 12,580 points
54 views

1 answer to this question.

0 votes

In Elm 0.17, ensure only one component remains highlighted by maintaining a single highlightedId in your model. Update this ID on user actions, and use it to conditionally apply the highlight style in your view function.

type alias Model = { highlightedId : Maybe Int }

view : Model -> Html Msg
view model =
    div []
        [ button [ style (if model.highlightedId == Just 1 then highlightStyle else []) ] [ text "Button 1" ]
        , button [ style (if model.highlightedId == Just 2 then highlightStyle else []) ] [ text "Button 2" ]
        ]

NoteU: pdate highlightedId in your update function based on user interaction.

answered Feb 21 by Kavya

Related Questions In Web Development

0 votes
1 answer

How can I give a component a template dynamically?

Angular offers three primary approaches to dynamically ...READ MORE

answered Oct 25, 2024 in Web Development by kavya
200 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
0 answers

Create a react app react 18 with typescript

I am trying to create react 18 ...READ MORE

Jul 5, 2022 in TypeSript by Logan
• 2,140 points
976 views
0 votes
1 answer
0 votes
1 answer

How can props be passed using Link in React Router?

In React Router, you can pass data ...READ MORE

answered Feb 21 in Node-js by kavya
74 views
0 votes
1 answer

How can updated props be received in React JS?

Components receive data through props, which are ...READ MORE

answered Feb 21 in Node-js by kavya
65 views
0 votes
1 answer

In DFS, how many times is a node visited?

In Depth-First Search (DFS), each node is ...READ MORE

answered Nov 13, 2024 in Web Development by kavya
194 views
0 votes
1 answer

In BFS, how many times is a node visited?

In Breadth-First Search (BFS), each node is ...READ MORE

answered Nov 13, 2024 in Web Development by kavya
181 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP