This is what I have:
(defn view [cursor owner]
(reify
om/IDidMount
(did-mount [_]
(-> (js/$ ".dropdown-toggle")
(.dropdown)))
om/IRender
(render [_]
(dom/div #js {:className "dropdown"}
(dom/button #js {:className "btn btn-default dropdown-toggle"
:type "button"
:id "dropdownMenu1"} "Dropdown" (dom/span #js {:className "caret"}))
(dom/ul #js {:className "dropdown-menu"
:role "menu"
:ariaLabelledby "dropdownMenu1"}
(dom/li #js {:role "presentation"}
(dom/a #js {:role "menuitem"
:tabIndex "-1"
:href "#"} "Action"))
(dom/li #js {:role "presentation"}
(dom/a #js {:role "menuitem"
:tabIndex "-1"
:href "#"} "Another action")))))))
The problem is that once the dropdown is opened, it does not hide anymore as it should be when one clicks on it or somewhere else. Also keystrokes don't work. I believe a missing something important here, what could it be? I'm using bootstrap 3.1.1 and jquery 1.11.0.
Thanks.
Basic Dropdown To open the dropdown menu, use a button or a link with a class of . dropdown-toggle and the data-toggle="dropdown" attribute. Add the . dropdown-menu class to a <div> element to actually build the dropdown menu.
Answer: Use the jQuery hover() method By default, to open or display the dropdown menu in Bootstrap you have to click on the trigger element. However, if you want to show the dropdown on mouseover instead of click you can do it with little customization using the CSS and jQuery.
Why is my drop down menu not working in bootstrap? Solution : The dropdown should be toggled via data attributes or using javascript. In the above program, we have forgotten to add a data attribute so the dropdown is not working. So add data-bs-toggle="dropdown" to toggle the dropdown.
Removing the data attribute data-toggle="dropdown" and implementing the open/close of the dropdown can be a solution. Save this answer.
Here's what I do to create a dropdown component:
(defn dropdown [cursor owner {:keys [id text values]}]
(om/component
(html
[:div.dropdown
[:button {:type "button"
:class "btn dropdown-toggle"
:data-toggle "dropdown"
:id id}
text
[:span {:class "caret"}]]
[:ul {:class "dropdown-menu" :role "menu" :aria-labelledby id}
[:li {:role "presentation"}
(for [v values]
[:a {:role "menuitem" :tabIndex "-1" :href "#"} v])]]])))
It hides when it should. I use jQuery 1.11.1, Bootstrap 3.2.0 and sablono for clarity but that doesn't affect anything. I don't think you should be using IDidMount for jQuery as all interaction is handled via bootstrap's dropdown JavaScript plugin (which is included in Bootstrap library).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With