Skip to content

Commit

Permalink
Open filter if open-on-load present
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-kirwan committed Aug 11, 2023
1 parent 71d6dc1 commit eb40ce9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/assets/javascripts/modules/mobile-filters-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
this.triggerElement.addEventListener('click', this.module.toggle)
this.triggerElement.setAttribute('aria-controls', this.module.id)
this.triggerElement.setAttribute('aria-expanded', 'false')
// Open filter on page load if data attribute "open_on_load" is present
if (this.triggerElement.getAttribute('data-open-on-load') === 'true') {
this.triggerElement.click()
}
}

if (this.clearFiltersTrigger) {
Expand Down
4 changes: 4 additions & 0 deletions app/models/content_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def filter
content_item_hash.dig("details", "filter") || {}
end

def open_on_load
content_item_hash.dig("details", "open_on_load") || ""
end

def reject
content_item_hash.dig("details", "reject") || {}
end
Expand Down
1 change: 1 addition & 0 deletions app/views/finders/_filter_button.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
data-track-label=""
data-module="ga4-event-tracker"
data-ga4-expandable=""
data-open-on-load="<%= @content_item.open_on_load %>"
>
Filter <span class="govuk-visually-hidden"> results</span>
<span class="js-selected-filter-count"><%= sanitize facet_tags.display_total_selected_filters %></span>
Expand Down

0 comments on commit eb40ce9

Please sign in to comment.