我正在尝试将初始焦点设置在输入元素上
(defn initial-focus-wrapper [element]
(with-meta element
{:component-did-mount #(.focus (reagent/dom-node %))}))
(defn chat-input []
(fn []
[initial-focus-wrapper
[:input {:type "text"}]]))
虽然这对我不起作用。我在做什么错?
正如sbensu所说,with-meta
似乎仅在功能上起作用。这意味着它可以与identity
一起使用,以产生希望的可重复使用的包装器]
(def initial-focus-wrapper
(with-meta identity
{:component-did-mount #(.focus (reagent/dom-node %))}))
(defn chat-input []
(fn []
[initial-focus-wrapper
[:input {:type "text"}]]))
我认为with-meta
应该以函数作为参数。从文档:
设置给定组件焦点的另一种方法是使用“:auto-focus true”属性: