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

TextInput: Update TextInput.Action internal component to use Tooltip v2 #4097

Merged
merged 8 commits into from
Mar 4, 2024

Conversation

broccolinisoup
Copy link
Member

@broccolinisoup broccolinisoup commented Dec 21, 2023

Closes #4091

Changelog

New

Changed

  • Update to use the new tooltip for TextInput's trailing action
  • Update the default direction of tooltipDirection prop to s because it is what is defaulted in Tooltip

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

Changes can be tested in the storybook

Merge checklist

Copy link

changeset-bot bot commented Dec 21, 2023

🦋 Changeset detected

Latest commit: c24979c

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

@broccolinisoup broccolinisoup changed the title y TextInput: Update TextInput.Action internal component to use Tooltip v2 Dec 21, 2023
Copy link
Contributor

github-actions bot commented Dec 21, 2023

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 113.57 KB (+0.12% 🔺)
packages/react/dist/browser.umd.js 114.22 KB (+0.12% 🔺)

@@ -93,7 +93,7 @@ const TextInputAction = forwardRef<HTMLButtonElement, TextInputActionProps>(
return (
<Box as="span" className="TextInput-action" marginLeft={1} marginRight={1} lineHeight="0">
{icon && !children ? (
<Tooltip direction={tooltipDirection} aria-label={ariaLabel}>
<Tooltip direction={tooltipDirection} text={ariaLabel as unknown as string} type="label">
Copy link
Member Author

Choose a reason for hiding this comment

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

text={ariaLabel as unknown as string} this is not great but some sort of type conversion or "hack" is needed here because text is a required prop for Tooltip but I see we can't make ariaLabel required for TextInput's trailing action because it could be an icon button or a text button. I am open to feedback if we want to handle this in another way

Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be a little easier to read/understand?

text={ariaLabel || ''}

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that reads better. Thank you. Although both options will end up rendering an empty tooltip. I wonder if we should conditionally render the tooltip for icon button too? Though this solution will only work until we bring the tooltip to icon buttons by default #2008. What are your thoughts on that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok. Yea, I think we can keep what you have then.

@github-actions github-actions bot temporarily deployed to storybook-preview-4097 December 21, 2023 01:16 Inactive
@broccolinisoup broccolinisoup marked this pull request as ready for review December 21, 2023 01:21
@@ -93,7 +93,7 @@ const TextInputAction = forwardRef<HTMLButtonElement, TextInputActionProps>(
return (
<Box as="span" className="TextInput-action" marginLeft={1} marginRight={1} lineHeight="0">
{icon && !children ? (
<Tooltip direction={tooltipDirection} aria-label={ariaLabel}>
<Tooltip direction={tooltipDirection ?? 's'} text={ariaLabel ?? ''} type="label">
Copy link
Member

Choose a reason for hiding this comment

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

Would this be something that we'd want to restrict in v37 so that aria-label is a required prop? I think this is fine since it mirrors the current behavior but in a future major release it'd be great to have this required so we don't have a non-descriptive tooltip

Copy link
Member Author

Choose a reason for hiding this comment

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

Would this be something that we'd want to restrict in v37 so that aria-label is a required prop?

I think we could. The only thing I can think of a bit of a blocker is that the TextInput.Action also accepts children and if children is passed, the tooltip becomes optional. (Based on just reading the code). I guess the case would be a text button as trailing action that doesn't need a tooltip. (related additional comment)

Just looking at the current use cases at dotcom, all seem to have icons. I wonder if it would make sense to re-visit the text button use case? 🤔 Or do we have clear uses cases for this? @mperrotti

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think trailing actions need to accept text, just the trailing visuals. For example: we may use trailing visual text to convey units like "minutes". See the timeout settings in https://github.com/settings/codespaces for an example.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is great. We can then refactor this conditional tooltip and make aria-label mandatory in the next major. I'll add this to the v37 issue.

@broccolinisoup broccolinisoup added this pull request to the merge queue Mar 4, 2024
Merged via the queue into main with commit 9c535e8 Mar 4, 2024
30 checks passed
@broccolinisoup broccolinisoup deleted the bs/textinput-tooltip2 branch March 4, 2024 01:35
@primer primer bot mentioned this pull request Mar 4, 2024
lukasoppermann pushed a commit that referenced this pull request Apr 16, 2024
…v2 (#4097)

* Use Tooltip 2 for TextInput.Action

* add changeset

* snaps and update default direction

* update tooltip direction and type casting

* accidently removed - bring it back

---------

Co-authored-by: Mike Perrotti <mperrotti@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TextInput.Action tooltip is clipped
3 participants