以编程方式将焦点放在Elm中的style-element上

时间:2018-04-20 15:58:18

标签: elm setfocus

任何人都知道是否有一种方法可以使用Stylish-elephants(或style-element v5)以编程方式将焦点设置在Element.Input.text元素上?

1 个答案:

答案 0 :(得分:3)

elm-package.json中需要“elm-lang / dom”:“1.1.1< = v< 2.0.0”

import Dom exposing (focus)

update msg model =
  case msg of
    FocusOn id ->
        { model | current_focus_id = id } ! [ Task.attempt FocusResult (focus (id)) ]

    FocusResult result ->
        case result of
            Err (Dom.NotFound id) ->
                model ! [ YourMsg]

            Ok () ->
                model ! []

view model = Element.layout []  <| el [onClick <| (FocusOn "id01")] (text "click here")