Skip to content

Extract Toast::CloseButton component and add button slot - #144

Merged
koppen merged 2 commits into
mainfrom
close-button-options
Oct 23, 2026
Merged

koppen merged 2 commits into
mainfrom
close-button-options

Conversation

@RasmusDWN

@RasmusDWN RasmusDWN commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Flowbite::Toast renders a close button but gives no way to customize it, so apps can't wire up dismissal (or anything else) without overriding the template.

This extracts the button into a Flowbite::Toast::CloseButton component and adds a button slot, following the pattern Card uses for its title:

  • Toast::CloseButton holds the button's classes, type, aria-label and icon. Options passed to it are merged over the defaults, like Card::Title.
  • Toast gets renders_one :button. When the slot isn't used, it falls back to default_button, rendered with the options from button: {options: {...}}.

Passing options to the default button:

Flowbite::Toast.new(message: "Saved", button: {options: {data: {action: "toast#dismiss"}}})

Rendering your own button:

<%= render(Flowbite::Toast.new(message: "Saved")) do |toast| %>
  <% toast.with_button do %>
    <%= render(Flowbite::Toast::CloseButton.new(data: {action: "toast#dismiss"})) %>
  <% end %>
<% end %>

Copilot AI balanced review requested due to automatic review settings October 23, 2026 09:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Flat aria-label options produce duplicate attributes rather than reliably overriding the default accessible label.

1 open issue
What changed in this PR

This PR lets applications customize the Toast close button without overriding its template, using the nested options pattern already used by InputField.

Changes:

  • Adds close_button: {options: {...}}, merging HTML options with defaults and appending custom classes.
  • Renders the button through Rails’ tag helper.
  • Adds customization tests and documents the new option.
File Description
test/​components/​flowbite/​toast_test.rb Tests custom classes, data attributes, and nested ARIA labels.
CHANGELOG.md Documents close-button HTML options.
app/​components/​flowbite/​toast/​toast.html.erb Renders the close button with merged options.
app/​components/​flowbite/​toast.rb Adds close-button configuration, default classes, and option merging.

Review effort: Balanced

Comment thread app/components/flowbite/toast.rb Outdated
@RasmusDWN RasmusDWN changed the title Allow passing HTML options to Toast close button Extract Toast::CloseButton component and add close_button slot Oct 23, 2026
Copilot AI balanced review requested due to automatic review settings October 23, 2026 11:24
@RasmusDWN
RasmusDWN force-pushed the close-button-options branch from 28edb92 to 10d74b5 Compare October 23, 2026 11:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Option merging can remove the button’s accessible name, and class replacement conflicts with the stated append behavior.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread app/components/flowbite/toast/close_button.rb
Comment thread app/components/flowbite/toast/close_button.rb
Copilot AI balanced review requested due to automatic review settings October 23, 2026 11:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Custom ARIA options can remove the icon-only close button’s default accessible name.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@RasmusDWN
RasmusDWN requested a review from koppen October 23, 2026 11:40
Comment thread app/components/flowbite/toast.rb Outdated
# @see https://flowbite.com/docs/components/toast/
# @lookbook_embed ToastPreview
class Toast < ViewComponent::Base
renders_one :close_button

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we don't really know what the button is used for (since we aren't the ones adding behavior to it), perhaps the slot should just be called button? The default button could still be a CloseButton, though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have renamed the slot and argument to button, so now it's more generic. CloseButton is still the default.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 11:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The advertised public API and examples must be reconciled with the implemented keyword and slot names.

1 open issue

Review effort: Balanced

Comment thread app/components/flowbite/toast.rb
@RasmusDWN RasmusDWN changed the title Extract Toast::CloseButton component and add close_button slot Extract Toast::CloseButton component and add button slot Oct 23, 2026
@RasmusDWN RasmusDWN removed their assignment Oct 23, 2026
@RasmusDWN
RasmusDWN requested a review from koppen October 23, 2026 12:05

@koppen koppen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤘

@koppen
koppen merged commit f51fd4f into main Oct 23, 2026
10 checks passed
@koppen
koppen deleted the close-button-options branch October 23, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants