-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent ActionMenu's show_button slot from rendering its content more than once #2538
Conversation
🦋 Changeset detectedLatest commit: 76f261f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -241,7 +241,9 @@ def initialize( | |||
# | |||
# @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::Overlay) %>'s `show_button` slot. | |||
def with_show_button(**system_arguments, &block) | |||
@overlay.with_show_button(**system_arguments, id: "#{@menu_id}-button", controls: "#{@menu_id}-list", &block) | |||
@overlay.with_show_button(**system_arguments, id: "#{@menu_id}-button", controls: "#{@menu_id}-list") do |button| | |||
evaluate_block(button, &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wild
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah yeah, all credit to @BlakeWilliams for figuring out the block.binding.receiver
fix (which is what evaluate_block
uses to work its magic).
What are you trying to accomplish?
Providing content to
ActionMenu
'swith_show_button
slot causes a double render.Integration
No changes necessary in production.
Risk Assessment
What approach did you choose and why?
The issue is that the block provided to
with_show_button
is forwarded toOverlay
and ultimately evaluated inOverlay
's view context. I made use of our shiny newevaluate_block
method that evaluates blocks in their receiver's view context (i.e. the receiver of the block's binding).Anything you want to highlight for special attention from reviewers?
I wasn't able to write a viable test using
render_inline
since I needed to actually run everything through the Rails render stack. I ended up adding a test helper calledrender_inline_erb
. Would love some 👀 on it.Accessibility
Merge checklist
- [ ] Added/updated documentation- [ ] Added/updated previews (Lookbook)- [ ] Tested in Chrome- [ ] Tested in Firefox- [ ] Tested in Safari- [ ] Tested in Edge