Skip to content

[ActionList] Prevent title="[object Object]" when Description has non-string children #6223

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 10 commits into
base: main
Choose a base branch
from

Conversation

liuliu-dev
Copy link

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

Closes #4400

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 19, 2025 23:37
@liuliu-dev liuliu-dev requested a review from a team as a code owner June 19, 2025 23:37
@liuliu-dev liuliu-dev requested a review from joshblack June 19, 2025 23:37
Copy link

changeset-bot bot commented Jun 19, 2025

🦋 Changeset detected

Latest commit: 4be97cb

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 19, 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!

@liuliu-dev liuliu-dev marked this pull request as draft June 19, 2025 23:38
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 enhances the ActionList.Description component by adding a title prop and automatically applying a tooltip for truncated text when the content is a string.

  • Introduces a new title prop and computes an effectiveTitle fallback for string children
  • Renders the title attribute on the truncated (<Truncate>) variant using effectiveTitle
  • Adds tests and a story example to validate the new tooltip behavior

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

File Description
packages/react/src/ActionList/Description.tsx Added title prop, effectiveTitle logic, and updated truncated render
packages/react/src/ActionList/ActionList.test.tsx New tests verifying title attribute for string, complex, and custom cases
packages/react/src/ActionList/ActionList.features.stories.tsx Storybook example illustrating the title prop on truncated content
.changeset/brown-rules-taste.md Recorded patch release changelog
Comments suppressed due to low confidence (1)

packages/react/src/ActionList/ActionList.test.tsx:178

  • Add a test case for when title="" is provided on a truncated string child to ensure that an explicit empty title is preserved and not overridden by the auto-fallback logic.
  it('sets title correctly for Description component', () => {

Copy link
Contributor

github-actions bot commented Jun 20, 2025

size-limit report 📦

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

@primer-integration
Copy link

🟢 golden-jobs completed with status success.

@github-actions github-actions bot added integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Jun 20, 2025
@liuliu-dev liuliu-dev marked this pull request as ready for review June 23, 2025 17:33
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.

Awesome work! Left some comments, let me know what you think, or if you have questions!

Comment on lines 23 to 26
/**
* The title attribute for the truncated text tooltip.
* If not provided and children is a string, it will be set automatically.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Can we add an additional note here for accessibility? The title attribute is a tricky one since it's not really accessible, but since we're utilizing it anyways, we can try suggest only utilizing it when it's truly needed 🤔

Suggested change
/**
* The title attribute for the truncated text tooltip.
* If not provided and children is a string, it will be set automatically.
*/
/**
* The title attribute for the truncated text tooltip.
* If not provided and children is a string, it will be set automatically.
*
* `title` should be used sparingly, as it may be inaccessible to some users.
*/

...props
}) => {
const {blockDescriptionId, inlineDescriptionId} = React.useContext(ItemContext)
const effectiveTitle = title || (typeof props.children === 'string' ? props.children : '')
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Should we add additional types so that title can only be used when variant !== 'block' or truncate === true? Something like this:

type VariantTypes =
  | {
      variant: 'block'
      title: never
    }
  | {
      /**
       * Secondary text style variations.
       *
       * - `"inline"` - Secondary text is positioned beside primary text.
       * - `"block"` - Secondary text is positioned below primary text.
       */
      variant?: 'inline'
      /**
       * The title attribute for the truncated text tooltip.
       * If not provided and children is a string, it will be set automatically.
       *
       * `title` should be used sparingly, as it may be inaccessible to some users.
       */
      title?: string
    }

export type ActionListDescriptionProps = VariantTypes & { ... }

Not a blocker, just an idea! 😁 Let me know what you think!

Copy link
Author

Choose a reason for hiding this comment

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

Great suggestion! 🎉 I've added the DescriptionVariantTypes.

@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 24, 2025
Copy link
Contributor

👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks!

Copy link
Contributor

👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks!

Copy link
Contributor

👋 Hi, there are new commits since the last successful integration test. We recommend running the integration workflow once more, unless you are sure the new changes do not affect github/github. Thanks!

Comment on lines +189 to +191
<ActionList.Description truncate title="Custom title">
<span>Complex</span> content
</ActionList.Description>
Copy link
Member

Choose a reason for hiding this comment

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

@TylerJDev would this be considered failing: https://dequeuniversity.com/rules/axe/4.7/label-content-name-mismatch ? 🤔 I don't think axe flags it but was curious if that was the case.

If so, it would be great to derive title from props.children instead of having it be explicit just to avoid the mismatch here when using downstream. In the props.children is not a string case, maybe we could use the text content from the rendered content? Just thinking out loud, curious what you think @liuliu-dev and @TylerJDev 👀

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 as long as the text is provided, title will default to the description, rather than accessible name. If we were able to utilize Tooltip instead of rely on the title "tooltip", it would be best, but that'd be harder to implement 😅

In the props.children is not a string case, maybe we could use the text content from the rendered content?

For this, would we need to grab the text after it was rendered? (e.g. accessing the DOM element's text content within the description container)

@github-actions github-actions bot removed the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Jun 24, 2025
@primer-integration
Copy link

👋 Hi from github/github! Your integration PR is ready: https://github.com/github/github/pull/386228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants