Skip to content

Commit

Permalink
🧹 Fix CollapsableSectionPresenter override
Browse files Browse the repository at this point in the history
The override was causing issues not passing the nav-link class into the
anchor tags.  This fix specifically passes the title attribute in vs the
previous implementation of trying to pass all html options in.
  • Loading branch information
kirkkwang committed Dec 18, 2023
1 parent 67f3163 commit 8ac6d41
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
27 changes: 14 additions & 13 deletions app/presenters/hyku/collapsable_section_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
# frozen_string_literal: true

module Hyku
# Draws a collapsable list widget using the Bootstrap 3 / Collapse.js plugin
# Draws a collapsable list widget using the Bootstrap 4 / Collapse.js plugin
class CollapsableSectionPresenter < Hyrax::CollapsableSectionPresenter
# Override Hyrax 3.5.0 to pass in html_options
# Override Hyrax v5.0.0rc2 to pass in the title attribute
# rubocop:disable Metrics/ParameterLists
def initialize(view_context:, text:, id:, icon_class:, open:, html_options: {})
def initialize(view_context:, text:, id:, icon_class:, open:, title: nil)
# rubocop:enable Metrics/ParameterLists
super(view_context: view_context, text: text, id: id, icon_class: icon_class, open: open)
@html_options = html_options
super(view_context:, text:, id:, icon_class:, open:)
@title = title
end

attr_reader :html_options
attr_reader :title

private

def button_tag
tag.a({ role: 'button',
class: "#{button_class}collapse-toggle",
data: { toggle: 'collapse' },
href: "##{id}",
onclick: "toggleCollapse(this)",
'aria-expanded' => open,
'aria-controls' => id }.merge(html_options)) do
tag.a(role: 'button',
class: "#{button_class}collapse-toggle nav-link",
data: { toggle: 'collapse' },
href: "##{id}",
onclick: "toggleCollapse(this)",
'aria-expanded' => open,
'aria-controls' => id,
title:) do
safe_join([tag.span('', class: icon_class, 'aria-hidden': true),
tag.span(text)], ' ')
end
Expand Down
16 changes: 8 additions & 8 deletions app/presenters/hyku/menu_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ def show_task?
end

# Draw a collaspable menu section. The passed block should contain <li> items.
# Override Hyrax 3.5.0 to pass in html_options
# Override Hyrax v5.0.0rc2 to pass in title attribute
# rubocop:disable Metrics/ParameterLists
def collapsable_section(text, id:, icon_class:, open:, **html_options, &block)
def collapsable_section(text, id:, icon_class:, title:, open:, &block)
# rubocop:enable Metrics/ParameterLists
CollapsableSectionPresenter.new(view_context: view_context,
text: text,
id: id,
icon_class: icon_class,
open: open,
html_options: html_options).render(&block)
CollapsableSectionPresenter.new(view_context:,
text:,
id:,
icon_class:,
title:,
open:).render(&block)
end
end
end

0 comments on commit 8ac6d41

Please sign in to comment.