【问题标题】:Programmatically set focus on a style-element in Elm [duplicate]以编程方式将焦点设置在 Elm 中的样式元素上 [重复]
【发布时间】:2018-10-01 09:42:38
【问题描述】:

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

【问题讨论】:

    标签: elm setfocus


    【解决方案1】:

    在 elm-package.json 中需要 "elm-lang/dom": "1.1.1

    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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-04
      • 1970-01-01
      • 2014-10-25
      • 2020-02-15
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多