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

Expose action list builder methods #2187

Merged
merged 6 commits into from
Aug 2, 2023

Conversation

camertron
Copy link
Contributor

What are you trying to accomplish?

In a recent PR, I added a special with_avatar_item slot that renders an item with a leading avatar visual, respecting the accessibility feedback we've received for displaying avatars and their associated labels. During dotcom integration, I encountered a use-case where we need to render individual items outside the context of a list. Specifically, the use-case requires rendering additional items fetched in a secondary HTTP request and appending them to an existing list. At the moment, this is possible but awkward:

<% dummy_list = Primer::Alpha::NavList::Group.new %>
<%= render Primer::Alpha::NavList::Item.new(list: dummy_list, ...) %>

Unfortunately due to the way NavList and ActionList work internally, each item must have a reference to its parent list, so dummy_list is required. However, I don't like that the user has to know to pass it in via the list: argument. There are also a number of niceties you get by calling with_item instead of constructing the Item instance yourself.

Integration

This change itself does not require any changes in production.

Risk Assessment

  • Low risk the change is small, highly observable, and easily rolled back.
  • Medium risk changes that are isolated, reduced in scope or could impact few users. The change will not impact library availability.
  • High risk changes are those that could impact customers and SLOs, low or no test coverage, low observability, or slow to rollback.

What approach did you choose and why?

ActionList has two methods, #build_item and the companion #build_avatar_item, that construct and return instances of ActionList::Item. They exist to facilitate overriding item construction in NavList and other subclasses. Until now, they've been private. This PR exposes them externally and makes them part of the official API. Users can now call #build_item, for example, in templates and render the result. Note that the dummy list is still required:

<% Primer::Alpha::NavList::Group.new.tap do |group| %>
  <%= render(
    group.build_avatar_item(
      src: repo.owner.primary_avatar_url,
      username: repo.name_with_display_owner,
      href: repository_path(repo),
      test_selector: "side-panel-item"
    )
  ) %>
<% end %>

Accessibility

  • No new axe scan violation - This change does not introduce any new axe scan violations.

Merge checklist

  • Added/updated documentation

@changeset-bot
Copy link

changeset-bot bot commented Aug 2, 2023

🦋 Changeset detected

Latest commit: 099590f

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 Minor

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 Aug 2, 2023
@camertron camertron temporarily deployed to preview August 2, 2023 18:10 — with GitHub Actions Inactive
@camertron camertron temporarily deployed to github-pages August 2, 2023 18:14 — with GitHub Actions Inactive
@camertron camertron merged commit ce2011e into main Aug 2, 2023
29 checks passed
@camertron camertron deleted the expose_action_list_builder_methods branch August 2, 2023 20:07
@primer-css primer-css mentioned this pull request Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor release ruby Pull requests that update Ruby code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants