-
-
Save jaen/7123aa5f7e15dccbed28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn dropdown [{:keys [value] :as options} choices] | |
(reagent/create-class | |
{:component-did-mount | |
(fn [component] | |
(let [dom-node (reagent/dom-node component)] | |
(.dropdown (js/$ dom-node) #js {:match "text" | |
:onChange (fn [new-value] | |
(reset! value new-value))}))) | |
| |
:component-did-update | |
(fn [component] | |
(let [dom-node (reagent/dom-node component)] | |
(.dropdown (js/$ dom-node) "set selected" @value) | |
(.dropdown (js/$ dom-node) "refresh"))) | |
| |
:reagent-render | |
(fn [{:keys [value] :as options} _] | |
(let [value @value] | |
[:div.ui.fluid.search.selection.dropdown | |
[:input {:type "hidden" :name "choice" :value value}] | |
[:i.dropdown.icon] | |
[:div.default.text "Select choice"] | |
[:div.menu | |
(doall (for [{:keys [value text]} choices] | |
(conj | |
^{:key (str "choice-" value)} | |
[:div.item {:data-value value}] | |
text)))]]))})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment