Skip to content

Commit

Permalink
Merge pull request #2924 from projectblacklight/alert-button
Browse files Browse the repository at this point in the history
Don't display an extra X on dismiss button
  • Loading branch information
thatbudakguy committed Dec 7, 2022
2 parents 511deaf + 8a9e550 commit d4990bf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<div class="alert <%= @classes %>">
<%= message %>
<a class="btn-close close" data-dismiss="alert" data-bs-dismiss="alert" href="#">&times;</a>
<%= tag.button_tag button_contents, type: "button", class: "btn-close",
data: { dismiss: "alert", bs_dismiss: "alert" },
aria: { label: "Close" } %>
</div>
9 changes: 9 additions & 0 deletions app/components/blacklight/system/flash_message_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def before_render
message { @message } if @message
end

# Bootstrap 4 requires the span, but Bootstrap 5 should not have it.
# See https://getbootstrap.com/docs/4.6/components/alerts/#dismissing
# https://getbootstrap.com/docs/5.1/components/alerts/#dismissing
def button_contents
return if helpers.controller.blacklight_config.bootstrap_version == 5

tag.span '&times;'.html_safe, aria: { hidden: true }
end

def alert_class(type)
case type.to_s
when 'success' then "alert-success"
Expand Down
4 changes: 4 additions & 0 deletions lib/blacklight/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def initialized_default_configuration?
property :logo_link, default: nil
property :header_component, default: Blacklight::HeaderComponent

# bootstrap_version may be set to 4 or 5
bootstrap_version = ENV['BOOTSTRAP_VERSION'].presence || "5"
property :bootstrap_version, default: /(\d)(?:\.\d){0,2}/.match(bootstrap_version)[1].to_i

# === Search request configuration

# @!attribute http_method
Expand Down
3 changes: 3 additions & 0 deletions lib/generators/blacklight/templates/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class <%= controller_name.classify %>Controller < ApplicationController
# rescue_from Blacklight::Exceptions::InvalidRequest, with: :my_handling_method
configure_blacklight do |config|
## Specify the style of markup to be generated (may be 4 or 5)
# config.bootstrap_version = 5
#
## Class for sending and receiving requests from a search index
# config.repository_class = Blacklight::Solr::Repository
#
Expand Down

0 comments on commit d4990bf

Please sign in to comment.