Skip to content

feat(tooltip): simplify implementation#3368

Draft
jpzwarte wants to merge 49 commits into
mainfrom
feature/3344-tooltip-property-on-button
Draft

feat(tooltip): simplify implementation#3368
jpzwarte wants to merge 49 commits into
mainfrom
feature/3344-tooltip-property-on-button

Conversation

@jpzwarte
Copy link
Copy Markdown
Member

@jpzwarte jpzwarte commented May 21, 2026

Closes #3344

The new sl-tooltip

The sl-tooltip component has been rewritten from ~1 300 lines down to ~390 lines. The new implementation is built entirely on platform primitives:

  • Popover API (popover="manual") for show/hide lifecycle and light-dismiss behaviour.
  • CSS Anchor Positioning (anchor-name / position-anchor) for layout — the tooltip positions itself relative to its anchor with zero JavaScript.
  • ARIA Element Reflection (ariaLabelledByElements / ariaDescribedByElements) for cross-shadow-boundary ARIA relationships.

Note

CSS Anchor Positioning is not yet supported in all browsers. You may need to include the CSS Anchor Positioning polyfill in your application.

The anchor is referenced by ID through the for attribute. The type property ('label' | 'description') determines which ARIA relation is established. The trigger property ('focus', 'hover', 'click', 'manual') controls which interactions open and close the tooltip.

<sl-tooltip for="save-btn">Save the current document</sl-tooltip>
<sl-button id="save-btn">Save</sl-button>

What has been removed

  • lazy() static factory — components now render tooltips declaratively using for="…" instead of imperatively creating them at runtime.
  • AnchorController and EventsController dependencies — anchor tracking and event wiring are now handled directly in the component.
  • position and offset properties — replaced by CSS position-area and position-try-fallbacks in the stylesheet.
  • The arrow element and arrowPadding — the new design does not use an arrow.
  • TooltipOptions interface and the sl-close event.
  • The ShadowRoot.createElement type workaround that was required for scoped-elements compatibility.

New tooltip property on components

The following components now expose a tooltip property that renders an <sl-tooltip> in their shadow DOM and wires up ARIA automatically:

Component Type Notes
sl-button string Icon-only → ariaLabelledByElements; text button → ariaDescribedByElements
sl-toggle-button string Same ARIA logic as sl-button
sl-menu-button string Forwarded to the inner sl-button
sl-tag boolean | string true shows a tooltip with the truncated label; a string overrides the text

Components migrated to the new tooltip

These components have been migrated from the old lazy() API to declarative <sl-tooltip> rendering:

  • sl-avatar — shows a tooltip with the display name when it overflows, using for.
  • sl-breadcrumbs — tooltips for truncated breadcrumb links now use for instead of manual cleanup functions.
  • sl-calendar (month-view) — day-indicator tooltips use for instead of per-day id + aria-describedby.
  • sl-ellipsize-text — shows a tooltip with the full text when it overflows, using for.
  • sl-grid — the "cancel selection" button uses the new tooltip property; column-header tooltips use for instead of id + aria-describedby.
  • sl-tag-list — the overflow group button uses the new tooltip property instead of a manually managed <sl-tooltip>.

Other changes

Bug fixes

  • sl-menu-button: Fix clicking the button a second time not dismissing the menu. The menu would immediately reopen because the button click fired after the popover's toggle event. Fixed by tracking a #popoverJustClosed flag via beforetoggle.
  • sl-button-bar: Fix not giving buttons enough time to set the icon-only state.

Accessibility

  • sl-menu-button, sl-toggle-button: Expose aria-disabled="true" on disabled items so assistive technologies announce them as unavailable while keeping them focusable.
  • sl-tool-bar: Overflow menu items now preserve disabled semantics with aria-disabled instead of rendering hard-disabled menu items.
  • sl-grid: Added aria-expanded to the toggle group button in the group header.

ForwardAriaMixin (sl-shared)

ForwardAriaMixin no longer overrides any existing ariaDescribedByElements or ariaLabelledByElements values. This allows components that use the mixin to maintain their own ARIA relationships without interference while still forwarding additional ARIA attributes.

Copilot AI review requested due to automatic review settings May 21, 2026 09:54
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: 7db9e85

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

This PR includes changesets to release 42 packages
Name Type
@sl-design-system/button Minor
@sl-design-system/menu Minor
@sl-design-system/tag Minor
@sl-design-system/toggle-button Minor
@sl-design-system/shared Minor
@sl-design-system/button-bar Patch
@sl-design-system/angular Minor
@sl-design-system/avatar Minor
@sl-design-system/calendar Minor
@sl-design-system/ellipsize-text Minor
@sl-design-system/grid Minor
@sl-design-system/breadcrumbs Minor
@sl-design-system/tooltip Major
@sl-design-system/paginator Patch
@sl-design-system/tabs Patch
@sl-design-system/tool-bar Patch
@sl-design-system/combobox Patch
@sl-design-system/toggle-group Patch
@sl-design-system/accordion Patch
@sl-design-system/announcer Patch
@sl-design-system/callout Patch
@sl-design-system/checkbox Patch
@sl-design-system/data-source Patch
@sl-design-system/date-field Patch
@sl-design-system/dialog Patch
@sl-design-system/editor Patch
@sl-design-system/emoji Patch
@sl-design-system/form Patch
@sl-design-system/format-date Patch
@sl-design-system/format-number Patch
@sl-design-system/inline-message Patch
@sl-design-system/number-field Patch
@sl-design-system/panel Patch
@sl-design-system/popover Patch
@sl-design-system/radio-group Patch
@sl-design-system/search-field Patch
@sl-design-system/select Patch
@sl-design-system/switch Patch
@sl-design-system/text-area Patch
@sl-design-system/text-field Patch
@sl-design-system/tree Patch
@sl-design-system/virtual-list Patch

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

@jpzwarte jpzwarte changed the title Add tooltip property to sl-button feat(button): support tooltip directly on button May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

🕸 Storybook preview

You can view a preview here (commit 61d6159bf7142fa105109895293540a073a5220d).

Copy link
Copy Markdown
Contributor

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 tooltip property to @sl-design-system/button (<sl-button>) so consumers can attach an <sl-tooltip> directly to the button and have ARIA relationships applied automatically, improving ergonomics especially for icon-only buttons.

Changes:

  • Added a new tooltip property to sl-button and render an internal <sl-tooltip> via scoped elements.
  • Wired tooltip-based ARIA (aria-describedby for text buttons, aria-labelledby for icon-only buttons) and added logic to merge forwarded aria-labelledby elements.
  • Added Storybook and unit test updates plus a changeset for a minor release.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
yarn.lock Updates workspace dependency metadata for the button package (adds tooltip/scoped-elements/lit entries).
packages/components/button/src/button.ts Implements the tooltip property, internal tooltip rendering, and ARIA wiring/merging logic.
packages/components/button/src/button.stories.ts Updates stories to demonstrate tooltip usage, including icon-only example.
packages/components/button/src/button.spec.ts Adds unit tests for tooltip rendering and ARIA behavior.
packages/components/button/package.json Adds @sl-design-system/tooltip dependency and declares scoped-elements/lit peer/dev dependencies.
.changeset/afraid-parents-nail.md Declares a minor release for the new tooltip API.

Comment thread packages/components/button/src/button.ts
Comment thread packages/components/button/src/button.ts
Comment thread packages/components/button/src/button.ts Outdated
Comment thread packages/components/button/src/button.stories.ts
@jpzwarte jpzwarte marked this pull request as draft May 21, 2026 13:36
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

🕸 Website preview

You can view a preview here (commit 36c87aea2608a2e2aa0e7d66a52e56f8c26fc873).

Copilot AI review requested due to automatic review settings May 21, 2026 13:45
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.

Comment thread packages/components/button/src/button.ts
Comment thread packages/components/button/src/button.spec.ts Outdated
Comment thread packages/components/tooltip/src/tooltip2.ts Outdated
Comment thread packages/components/tooltip/src/tooltip2.ts Outdated
Comment thread packages/components/tooltip/src/tooltip2.ts Outdated
Copilot AI review requested due to automatic review settings May 21, 2026 15:38
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 9 out of 10 changed files in this pull request and generated 5 comments.

Comment thread packages/components/button/src/button.ts
Comment thread packages/components/tooltip/src/tooltip2.ts Outdated
Comment thread packages/components/tooltip/src/tooltip2.ts Outdated
Comment thread packages/components/tooltip/src/tooltip2.ts Outdated
Comment thread packages/components/tooltip/src/tooltip2.ts Outdated
Copilot AI review requested due to automatic review settings May 26, 2026 07:23
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 109 out of 110 changed files in this pull request and generated 5 comments.

Comment thread packages/components/shared/src/mixins/forward-aria-mixin.ts
Comment thread packages/components/breadcrumbs/src/breadcrumbs.ts
Comment thread packages/components/breadcrumbs/src/breadcrumbs.ts Outdated
Comment thread packages/components/tag/src/tag.ts
Comment thread packages/components/toggle-button/src/toggle-button.ts
Copilot AI review requested due to automatic review settings June 3, 2026 07:00
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 114 out of 115 changed files in this pull request and generated 4 comments.

Comment thread packages/components/breadcrumbs/src/breadcrumbs.ts Outdated
Comment thread packages/components/shared/src/mixins/forward-aria-mixin.ts
Comment thread tools/eslint-plugin-slds/lib/rules/button-has-label.js
Comment thread .changeset/violet-baboons-crash.md
Copilot AI review requested due to automatic review settings June 3, 2026 10:58
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 119 out of 120 changed files in this pull request and generated 5 comments.

Comment thread packages/components/shared/src/mixins/forward-aria-mixin.ts
Comment thread packages/components/breadcrumbs/src/breadcrumbs.ts
Comment thread packages/components/toggle-group/src/toggle-group.ts
Comment thread .changeset/violet-baboons-crash.md
Comment thread tools/eslint-plugin-slds/lib/rules/button-has-label.js
Copilot AI review requested due to automatic review settings June 3, 2026 11:16
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 119 out of 120 changed files in this pull request and generated 6 comments.

Comment thread packages/components/menu/src/menu-button.ts
Comment thread packages/components/toggle-group/src/toggle-group.ts
Comment thread packages/components/breadcrumbs/src/breadcrumbs.spec.ts Outdated
Comment thread packages/components/breadcrumbs/src/breadcrumbs.spec.ts Outdated
Comment thread packages/components/shared/src/mixins/forward-aria-mixin.ts
Comment thread packages/components/tag/src/tag.ts
Copilot AI review requested due to automatic review settings June 3, 2026 11:31
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 119 out of 120 changed files in this pull request and generated 4 comments.

Comment thread packages/components/breadcrumbs/src/breadcrumbs.ts
Comment thread packages/components/breadcrumbs/src/breadcrumbs.ts
Comment thread packages/components/avatar/src/avatar.ts
Comment thread packages/components/avatar/src/avatar.ts
Copilot AI review requested due to automatic review settings June 3, 2026 11:58
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.

[Button] add a tooltip property to button

3 participants