Skip to content

Add loading support to ActionList.TrailingAction component #6239

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

liuliu-dev
Copy link
Contributor

@liuliu-dev liuliu-dev commented Jun 25, 2025

Closes 5346

Changelog

New

Changed

Removed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

@Copilot Copilot AI review requested due to automatic review settings June 25, 2025 22:51
@liuliu-dev liuliu-dev requested a review from a team as a code owner June 25, 2025 22:51
@liuliu-dev liuliu-dev requested a review from joshblack June 25, 2025 22:51
Copy link

changeset-bot bot commented Jun 25, 2025

🦋 Changeset detected

Latest commit: 804b7d3

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

This PR includes changesets to release 1 package
Name Type
@primer/react 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 integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Jun 25, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a loading state to the ActionList.TrailingAction component so that consumers can show a spinner in place of the icon when an action is in progress.

  • Introduces an optional loading prop in the component’s TypeScript interface
  • Passes the loading prop down to the StyledButton instances
  • Updates the JSON docs and changelog entry

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/react/src/ActionList/TrailingAction.tsx Added loading?: boolean to props and forwarded it to the button
packages/react/src/ActionList/ActionList.docs.json Documented the new loading prop with its default value and description
.changeset/calm-hoops-tie.md Added a minor release changelog entry for loading support
Comments suppressed due to low confidence (2)

packages/react/src/ActionList/TrailingAction.tsx:25

  • Add unit tests to cover the loading prop in TrailingAction. For example, assert that when loading is true, the spinner is rendered instead of the icon and the button is disabled if that’s part of the contract.
  loading?: boolean

packages/react/src/ActionList/TrailingAction.tsx:29

  • [nitpick] Consider adding a Storybook story or preview showcasing the loading state of TrailingAction, so consumers can visually verify spinner behavior and layout.
  ({as = 'button', icon, label, href = null, className, loading, ...props}, forwardedRef) => {

Copy link
Contributor

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 92.39 KB (-0.31% 🔽)
packages/react/dist/browser.umd.js 92.56 KB (+0.03% 🔺)

Copy link
Member

@TylerJDev TylerJDev left a comment

Choose a reason for hiding this comment

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

Looks great so far! Left some comments, let me know what you think!

@@ -44,6 +49,7 @@ export const TrailingAction = forwardRef(
variant="invisible"
as={as}
href={href}
loading={loading}
Copy link
Member

Choose a reason for hiding this comment

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

I noticed when using loading without an Icon (e.g. ActionList.TrailingAction as="a" href="#" label="Some action 1" loading />) the TrailingAction takes the full width of the inner contents when loading. I'm wondering if we should add some sort of conditional or style so that the width remains consistent when loading is true.

Example:

Trailing action within ActionList, that is currently in a loading state. The action itself has a large width, due to the inner text being only visibly hidden via `visibility: hidden` rather than `display: none`

What we might want:

Trailing Action with a smaller width due to the inner contents being removed.

@@ -44,6 +49,7 @@ export const TrailingAction = forwardRef(
variant="invisible"
as={as}
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking: I'm wondering if we'd want to convert this to a button when loading state is true (e.g. as={loading ? undefined : as}). Mainly because we can't disable a link (aria-disabled is added to the loading states of IconButton). There are some accessibility considerations, such as if it's confusing to go from a button to a link once the loading state is finished. We'd also need to ensure focus remained on the element once the loading state resolves. An alternative is to only allow loading states for button trailing actions.

I'm indifferent on this though. Curious what you and @joshblack think!

/**
* Specify whether the action is in a loading state
*/
loading?: boolean
Copy link
Member

Choose a reason for hiding this comment

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

I think we should be able to uncomment the existing WithTrailingAction story. We can adding the loading prop to one of the TrailingAction implementations in that story 😁

@TylerJDev TylerJDev requested a review from mperrotti June 26, 2025 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants