Skip to content

Commit

Permalink
Use title attribute for delete_button tooltip
Browse files Browse the repository at this point in the history
If a `title` is passed as `html_options` to `delete_button` helper
we use that to create a `sl-tooltip`. This way we can progresivly
enhance Alchemy extensions and modules to use the new UI
Tooltips instead of titles but keep downwards compatibility.
  • Loading branch information
tvdeyen committed Jan 12, 2024
1 parent d476d0f commit 3f4ba75
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
16 changes: 11 additions & 5 deletions app/helpers/alchemy/admin/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,22 @@ def delete_button(url, options = {}, html_options = {})
message: Alchemy.t("Are you sure?"),
icon: "delete-bin-2"
}.merge(options)
button_with_confirm(

if html_options[:title]
tooltip = html_options.delete(:title)
end
button = button_with_confirm(
render_icon(options[:icon]),
url, {
message: options[:message]
}, {
url, options, {
method: "delete",
title: options[:title],
class: "icon_button #{html_options.delete(:class)}".strip
}.merge(html_options)
)
if tooltip
content_tag("sl-tooltip", button, content: tooltip)
else
button
end
end

# (internal) Renders translated Module Names for html title element.
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/resources_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
second_event
visit "/admin/events"
within("tr", text: "My second Event") do
click_on "Delete"
click_button_with_tooltip "Delete"
end
end

Expand Down
22 changes: 22 additions & 0 deletions spec/helpers/alchemy/admin/base_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,28 @@ module Alchemy
it "returns a form tag with method=delete" do
is_expected.to have_selector('form input[name="_method"][value="delete"]')
end

context "with title in html options" do
subject(:button) do
delete_button("/admin/pages", {}, {title: "Open Me"})
end

it "passes html title to sl-tooltip" do
expect(button).to have_css("sl-tooltip[content='Open Me']")
expect(button).to_not have_css("button[title='Open Me']")
end
end

context "without title in html options" do
subject(:button) do
delete_button("/admin/pages", {}, {})
end

it "has no sl-toolip" do
expect(button).to_not have_css("sl-tooltip")
expect(button).to_not have_css("button[title]")
end
end
end

describe "#alchemy_datepicker" do
Expand Down

0 comments on commit 3f4ba75

Please sign in to comment.