Skip to content
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

Allow ActionList dividers to be added manually #1875

Merged
merged 5 commits into from
Mar 10, 2023

Conversation

camertron
Copy link
Contributor

@camertron camertron commented Mar 9, 2023

Description

Dividers in an ActionList can currently only be added by passing show_dividers: true, which will add a divider between each list item:

image

I'm working on integrating ActionList inside ActionMenu (currently an experimental component in dotcom) that needs to be able to insert dividers manually at user-defined positions within the list. This PR introduces the #with_divider method which offers such functionality. Here's an example:

image

Why not use polymorphic slots?

This is a use-case tailor-made for polymorphic slots, but using them would necessitate a painful API change. Fortunately custom polymorphic slot names are on the horizon, but until then I've added a bit of a hacky workaround in the form of a #with_divider method that appends to the existing items slot using ViewComponent's private #set_slot method.

Integration

Does this change require any updates to code in production?

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews

@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2023

🦋 Changeset detected

Latest commit: 530218b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Patch

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

@github-actions github-actions bot added the ruby Pull requests that update Ruby code label Mar 9, 2023
@camertron camertron temporarily deployed to preview March 9, 2023 05:26 — with GitHub Actions Inactive
@camertron camertron temporarily deployed to github-pages March 9, 2023 05:30 — with GitHub Actions Inactive
@camertron camertron temporarily deployed to github-pages March 9, 2023 22:04 — with GitHub Actions Inactive
@camertron camertron marked this pull request as ready for review March 9, 2023 22:06
@camertron camertron requested review from a team and keithamus March 9, 2023 22:06
@camertron camertron temporarily deployed to preview March 9, 2023 22:09 — with GitHub Actions Inactive
@camertron camertron temporarily deployed to github-pages March 9, 2023 22:14 — with GitHub Actions Inactive
# @param system_arguments [Hash] The arguments accepted by <%= link_to_component(Primer::Alpha::ActionList::Divider) %>.
def with_divider(**system_arguments, &block)
# This is a giant hack that should be removed when :items can be converted into a polymorphic slot.
# This feature needs to land in view_component first: https://github.com/ViewComponent/view_component/pull/1652
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻 A pretty wild hack

@camertron camertron merged commit 8bbeb72 into main Mar 10, 2023
@camertron camertron deleted the action_list_manual_dividers branch March 10, 2023 00:29
@primer-css primer-css mentioned this pull request Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch release ruby Pull requests that update Ruby code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants