Skip to content

Meta: add tooltipped and addToolTip helpers#9449

Merged
fregante merged 13 commits into
mainfrom
copilot/add-helper-for-tool-tip-element
May 13, 2026
Merged

Meta: add tooltipped and addToolTip helpers#9449
fregante merged 13 commits into
mainfrom
copilot/add-helper-for-tool-tip-element

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 13, 2026

Replaces repetitive manual UUID wiring + <tool-tip> JSX boilerplate with two focused utility functions. Previously each usage required two crypto.randomUUID() calls, manual id/for/aria-labelledby linking, and ~12 lines of JSX per tooltip.

New helpers: source/helpers/tooltip.tsx

tooltipped(content, element) — for building JSX trees with new elements. Returns [element, tooltip] as a tuple for direct inline embedding:

return <div>{tooltipped('Does something', <button type="button"></button>)}</div>;

// With options:
return <div>{tooltipped({ label: 'Does something', shortcut: 'g b', direction: 'n' }, <button type="button"></button>)}</div>;

// Inline ternary:
return <div>{shouldHaveTooltip ? tooltipped('Label', button) : button}</div>;

addToolTip(content, element) — for elements already in the DOM. Inserts the tooltip immediately after the element and returns void. Throws if the element has no parent node (use tooltipped instead):

addToolTip('Does something', button);
addToolTip({ label: 'Does something', shortcut: 'g b', direction: 'n' }, button);

Both helpers:

  • Auto-assign an id to the element if absent
  • Set aria-labelledby on the element pointing to the tooltip
  • Render shortcut keys as <kbd> elements ('g b'<kbd>g</kbd> <kbd>b</kbd>)

Refactored

  • update-pr-from-base-branch.tsx<button> inlined directly into tooltipped(), no intermediate const
  • table-input.tsx<summary> inlined directly into tooltipped() inside the <details> JSX tree
  • unwrap-unnecessary-dropdowns.tsxtooltipped used inline via ternary expression

Type

  • globals.d.ts: added for?: string to tool-tip JSX intrinsic type

Test URLs

Screenshot

AI GOT NO EYES

Copilot AI linked an issue May 13, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add helper to use the new tool-tip element Add addToolTip helper for the tool-tip custom element May 13, 2026
Copilot AI requested a review from fregante May 13, 2026 10:48
Comment thread source/features/update-pr-from-base-branch.tsx Outdated
Comment thread source/helpers/tooltip.tsx Outdated
Copilot AI changed the title Add addToolTip helper for the tool-tip custom element Add tooltipped and addToolTip helpers for the tool-tip custom element May 13, 2026
Copilot AI requested a review from fregante May 13, 2026 12:37
Comment thread source/features/table-input.tsx Outdated
Comment thread source/features/unwrap-unnecessary-dropdowns.tsx Outdated
Comment thread source/features/update-pr-from-base-branch.tsx Outdated
Copilot AI requested a review from fregante May 13, 2026 12:45
@github-actions github-actions Bot added the meta Related to Refined GitHub itself label May 13, 2026
@fregante fregante changed the title Add tooltipped and addToolTip helpers for the tool-tip custom element Meta: add tooltipped and addToolTip helper May 13, 2026
@fregante fregante changed the title Meta: add tooltipped and addToolTip helper Meta: add tooltipped and addToolTip helpers May 13, 2026
Comment thread source/helpers/tooltip.tsx
Comment thread source/helpers/tooltip.tsx
Copy link
Copy Markdown
Member

@fregante fregante left a comment

Choose a reason for hiding this comment

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

Adding tooltips is now much quicker:

Image

I'll ask to use this for other features like unread-anywhere in a followup PR

@fregante fregante requested a review from SunsetTechuila May 13, 2026 13:03
@fregante fregante marked this pull request as ready for review May 13, 2026 13:03
Copilot AI requested a review from fregante May 13, 2026 13:06
element.id ||= crypto.randomUUID();

const tooltipId = crypto.randomUUID();
element.setAttribute('aria-labelledby', tooltipId);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure we always want that, but ok for now

Comment thread source/helpers/tooltip.tsx
Comment thread source/features/unwrap-unnecessary-dropdowns.tsx Outdated
Comment thread source/helpers/tooltip.tsx Outdated
@SunsetTechuila
Copy link
Copy Markdown
Member

SunsetTechuila commented May 13, 2026

Before After
image image

Reference:

image

SunsetTechuila and others added 2 commits May 13, 2026 20:04
Co-authored-by: Grigory <grigory.orlov.set@gmail.com>
Comment thread source/refined-github.css Outdated
Comment on lines +282 to +284
padding: var(--base-size-2, 0.125rem);
line-height: var(--base-size-8, 0.5rem);
min-width: var(--base-size-16, 1rem);
Copy link
Copy Markdown
Member

@SunsetTechuila SunsetTechuila May 13, 2026

Choose a reason for hiding this comment

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

I don't think we should use fuchsia-like fallbacks here. If our styles are automatically adapted, good. If not, that's fine too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Only because it's a lot of values and it's easier to just keep the whole block in sync.

But in practice fuchsia is exactly the notification we need to force us to update the whole rule when it becomes outdated.

@fregante
Copy link
Copy Markdown
Member

Good changes 👌

Comment thread source/refined-github.css Outdated
Comment thread source/refined-github.css Outdated
Comment on lines +282 to +284
padding: var(--base-size-2, 0.125rem);
line-height: var(--base-size-8, 0.5rem);
min-width: var(--base-size-16, 1rem);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Only because it's a lot of values and it's easier to just keep the whole block in sync.

But in practice fuchsia is exactly the notification we need to force us to update the whole rule when it becomes outdated.

@fregante fregante merged commit 7061f6b into main May 13, 2026
10 checks passed
@fregante fregante deleted the copilot/add-helper-for-tool-tip-element branch May 13, 2026 15:35
@SunsetTechuila
Copy link
Copy Markdown
Member

SunsetTechuila commented May 13, 2026

Handy helpers: easy to use and make updates and migrations easier. Good job

@fregante
Copy link
Copy Markdown
Member

fregante commented May 13, 2026

🙌 there's a PR coming to attempt an automated upgrade. Let's see how that goes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meta Related to Refined GitHub itself

Development

Successfully merging this pull request may close these issues.

Add helper to use the new tool-tip element

3 participants