(defn- menu-item
[value-fn label-fn state lang index item]
(let [value (value-fn item)
label (label-fn item lang)]
^{:key index}
[:> m/MenuItem {:value value
:data-cy (-> (str value) (str/lower-case) (str/replace " " "-") (str "-menu-item"))}
[:> m/Checkbox {:checked (= (value-fn state) value)}]
[:> m/Typography {} label]
]))
(defn select
[{:keys [data state-fn disabled? label value-fn label-fn data-cy variant]}]
(let [rf-lang (rf/subscribe [:current-language])
label-fn1 (or label-fn (fn [item lang] (value-fn item)))]
(fn [{:keys [data state-fn disabled? label value-fn data-cy variant]}]
(let [lang @rf-lang
state (state-fn)
props (cond->
{:select true
:full-width true
:SelectProps {:MenuProps {:getContentAnchorEl nil}
:render-value (fn [items]
(if label-fn
(label-fn state lang)
(map identity items)))
:data-cy data-cy}
:value (or (value-fn state) "")
:on-change (fn [e]
(let [selected (.. e -target -value)]
(state-fn (first (filter #(= selected (value-fn %)) data)))))
:label (i18n/translation label lang)
:disabled disabled?}
variant (assoc :variant variant))]
[:> m/TextField props (map-indexed (partial menu-item value-fn label-fn1 state lang) data)]))))
我有一段代码用于创建带有旁边复选框的项的下拉列表。问题是复选框不能被移除。当用户点击一个已经选中的复选框时,没有任何动态出现。在这种情况下,它应该变为取消选择状态。