Module: DropdownHelper
- Defined in:
- app/helpers/dropdown_helper.rb
Instance Method Summary collapse
- #dropdown(label:, title: nil) ⇒ Object
- #dropdown_for(items = [], label: nil, title: nil, &block) ⇒ Object
- #dropdown_option(option) ⇒ Object
Instance Method Details
#dropdown(label:, title: nil) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/dropdown_helper.rb', line 2 def dropdown(label:, title: nil) = { class: 'dropdown-menu' } if title.present? title_id = id_for(title) title_tag = content_tag(:h2, class: 'sr-only', id: title_id) { title } [:aria] = { labelledby: title_id } else title_tag = '' end = { aria: { expanded: false }, class: 'dropdown-toggle', data: { toggle: "dropdown" }, type: 'button' } toggle = content_tag(:button, ) { label } = content_tag(:ul, ) { block_given? ? yield : nil } title_tag + content_tag(:div, class: 'dropdown') { toggle + } end |
#dropdown_for(items = [], label: nil, title: nil, &block) ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/helpers/dropdown_helper.rb', line 32 def dropdown_for(items = [], label: nil, title: nil, &block) = items.map { |item| dropdown_option(item, &block) }.join.html_safe dropdown(label: label, title: title) { } end |
#dropdown_option(option) ⇒ Object
25 26 27 28 29 30 |
# File 'app/helpers/dropdown_helper.rb', line 25 def dropdown_option(option) = { class: 'dropdown-menu-item' } content_tag(:li, ) { block_given? ? yield(option) : option } end |