Skip to content

Docs: Add tooltips to buttons when <Example> is used, not just <Code> #41582

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

Merged
merged 3 commits into from
Aug 10, 2025

Conversation

louismaximepiton
Copy link
Member

@louismaximepiton louismaximepiton commented Jul 1, 2025

Description

I've updated the Example in order to use our Code component.
I've updated Code to be embedded inside other components.
We add a new empty div and a div without any class, but it's better than nothing for now.

Motivation & Context

The issue comes from the fact that the Code component initiates the tooltip both for the clipboard and stackblitz button, but the Code component only embed the clipboard button. On the other side, the Code component is used by JsDocs, ScssDocs and by itself in the documentation (so via ``` and the help of <Content components={{ pre: Code }} /> inside `[...slug].astro`) but not by the Example component.

Previously, it used to work because most pages have either a ``` or a ScssDocs or JsDocs inside the page. Since Astro bundle the JS and clean the bundled JS, if at least one occurrence was present in the page, the Code component JS was interpreted on the whole page and only once. We have the issue on Button Group since we don't have any Code component reference inside.

So here the quick fix is only to use Code whenever it's possible (So in Example component) to add the JS everywhere it's needed. It's not ideal but a quick fix. If you have a better solution to introduce the requested JS everywhere, feel free to change it.

Since the default syntax highlighter is Prism (in astro.config.ts) we can't see any difference on the doc.

With special thanks to @MaxLardenois.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would change existing functionality)

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (using npm run lint)
  • My change introduces changes to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Live previews

Related issues

Closes #41579

@louismaximepiton louismaximepiton changed the title fix(docs): Add a tooltip on buttons whenever <Example> is called d not only <Code> fix(docs): Add a tooltip on buttons whenever <Example> is called and not only <Code> Jul 1, 2025
@louismaximepiton louismaximepiton marked this pull request as ready for review July 1, 2025 13:28
@julien-deramond julien-deramond changed the title fix(docs): Add a tooltip on buttons whenever <Example> is called and not only <Code> Docs: Add tooltips to buttons when <Example> is used, not just <Code> Jul 1, 2025
@julien-deramond julien-deramond self-requested a review August 10, 2025 17:28
Copy link
Member

@julien-deramond julien-deramond left a comment

Choose a reason for hiding this comment

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

Good catch, @hannahiss, and thanks for the fix, @louismaximepiton and @MaxLardenois!

The quick fix here is to use Code whenever possible (e.g., in the Example component) so the JS is included wherever needed. It’s not ideal, but it works for now. If you have a better approach to inject the required JS globally, feel free to propose it.

While there might be a cleaner long-term solution, your fix is well-scoped and easy to follow. Let’s move forward with it for now.

I checked a good portion of the docs, and it fixes issues in "Buttons group", several "Helpers" pages like "Color & background", "Colored links", "Stretched link", and more.

@julien-deramond julien-deramond merged commit 6d3345b into main Aug 10, 2025
14 checks passed
@julien-deramond julien-deramond deleted the main-lmp-tooltip-example-fix branch August 10, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tooltips not working on "Try it on Stackblitz" and "Copy code" buttons of the examples in the doc (Astro)
2 participants