Expose action list builder methods #2187
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:Unfortunately due to the way
NavList
andActionList
work internally, each item must have a reference to its parent list, sodummy_list
is required. However, I don't like that the user has to know to pass it in via thelist:
argument. There are also a number of niceties you get by callingwith_item
instead of constructing theItem
instance yourself.Integration
This change itself does not require any changes in production.
Risk Assessment
What approach did you choose and why?
ActionList
has two methods,#build_item
and the companion#build_avatar_item
, that construct and return instances ofActionList::Item
. They exist to facilitate overriding item construction inNavList
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:Accessibility
Merge checklist