Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cfdf3e8
feat(tour): render the tour panel in React, with a ReactNode body
galangel Nov 26, 2026
c8f1747
fix(tour): render the panel for a step whose only feature is a title
galangel Nov 26, 2026
6f93f2f
fix(tour): take the panel down when the component running the tour un…
galangel Nov 26, 2026
fa3a341
feat(tour): scroll a tall panel body and keep the panel in the viewport
galangel Nov 26, 2026
5167382
docs(tour): document `body`, React-rendered panels and the scrolling …
galangel Nov 26, 2026
ccb6b6d
chore(release): 1.4.0
galangel Nov 26, 2026
61d7c48
fix(tour): render the panel for every `body` step
galangel Nov 26, 2026
3af0832
fix(tour): inject `content` as HTML on a step that renders no panel
galangel Nov 26, 2026
84f2262
fix(tour): update a running step's panel in place when its steps change
galangel Nov 26, 2026
ae8df60
fix(tour): keep a running tour open through StrictMode's simulated un…
galangel Nov 26, 2026
dc67857
fix(tour): write the muted attribute on a muted native video
galangel Nov 26, 2026
0784f72
fix(types): require a `body` step to have a body
galangel Nov 26, 2026
cd8d0f3
fix(tour): drop the outer margins of the message's first and last child
galangel Nov 26, 2026
4425bcf
docs: add 1.4 upgrade notes, and describe how each step body renders
galangel Nov 26, 2026
a815221
fix(tour): give each shown step a panel store of its own
galangel Nov 26, 2026
136d2a4
fix(tour): follow the step on screen by its target when steps change
galangel Nov 26, 2026
ac885c6
fix(tour): release only the tooltip and flow a tour still owns on unm…
galangel Nov 26, 2026
f453a0f
fix(tour): ignore a target that unmounts along with the touring compo…
galangel Nov 26, 2026
719816c
fix(tour): treat a body that renders nothing as no body
galangel Nov 26, 2026
34bd177
fix(tour): respect an explicit html: false on a content step without …
galangel Nov 26, 2026
6ee3c75
fix(tour): drop the muted attribute when a shown video is unmuted
galangel Nov 26, 2026
0a3ebef
docs: say tour panels are keyed per presented step, not by index
galangel Nov 26, 2026
6248963
fix(tour): find the step on screen by id, and never guess between sha…
galangel Nov 26, 2026
45b0c48
fix(tour): tell tours apart by a token minted per show, not by content
galangel Nov 26, 2026
193f7b8
fix(tour): name an untitled panel by its message, and the iframe and …
galangel Nov 26, 2026
76236a1
fix(tour): apply changed tooltip options in place, and keep the helpe…
galangel Nov 26, 2026
fa025c9
fix(tour): do not start a tour whose first step has nothing to show
galangel Nov 26, 2026
a0ec35b
docs: list the 1.4 type changes and the remaining behavior changes
galangel Nov 26, 2026
4aa54bd
docs(storybook): list The Tourtip after The TipAdvisor in the sidebar
galangel Nov 26, 2026
913ac83
docs(storybook): move the autoFocus and React body stories into Flow …
galangel Nov 26, 2026
122275f
feat(tour): open a step without a target centered in the viewport
galangel Nov 26, 2026
da61c0b
docs(storybook): give the React Body story an image and announcement …
galangel Nov 26, 2026
7f6f365
docs(storybook): add an Announcement story for a centered step
galangel Nov 26, 2026
ad71c33
feat(tour): size a centered panel by its media, and cap it at 80% of …
galangel Nov 26, 2026
f9dce5a
docs(storybook): let the Announcement story compare image sizes
galangel Nov 26, 2026
feda468
feat(tour): allow a step that is only its image or video
galangel Nov 26, 2026
ced86f1
docs(storybook): add a Video Announcement story, and focus "Got it" i…
galangel Nov 26, 2026
55ec354
fix(tour): give a panel that is only media the same padding on every …
galangel Nov 26, 2026
581c287
fix(tour): stop a squeezed anchored panel's media spilling out of it
galangel Nov 26, 2026
d1c177c
fix(tour): let an anchored panel's body shrink again, with a floor fo…
galangel Nov 26, 2026
8d102f4
feat(tour): place a step's media to the left or right of its text
galangel Nov 26, 2026
a209455
docs(storybook): add Top / Left / Right placement buttons to the Anno…
galangel Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const preview: Preview = {
options: {
// Sort stories with Welcome first
storySort: {
order: ['Welcome', 'The Tooltip', 'The Tourtip', 'The TipAdvisor', 'Tooltip', '*'],
order: ['Welcome', 'The Tooltip', 'The TipAdvisor', 'The Tourtip', 'Tooltip', '*'],
},
},
},
Expand Down
101 changes: 91 additions & 10 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ npm run build # library (dist/index.mjs, .cjs, styles.css)
| -------------------------- | ------------------------------------------------------------------------------------------------------------- |
| `src/components/` | React components. `Tooltip` renders the single tooltip; the rest are internals mounted by `TipMagicProvider`. |
| `src/hooks/` | Public hooks and the API objects behind `useTipMagic()`. |
| `src/hooks/useTour/` | `useTour`, and `TourPanel`, the React component it passes to the tooltip as content. |
| `src/hooks/useTour/utils/` | Tour helpers: DOM managers (classes) and pure functions. |
| `src/utils/` | Pure helpers shared across components. Tests in `__tests__/` beside them. |
| `src/types/` | All public types. `tour.ts` re-exports through `index.ts`. |
Expand Down Expand Up @@ -49,9 +50,10 @@ on the next push rather than stranding the bump.

**`dangerouslySetInnerHTML` is re-applied on every render.** React rewrites the subtree
even when the html string is byte-identical. Anything focused inside it is dropped to
`<body>`, an `<img>` or autoplaying `<video>` is recreated and restarts, and a tour
panel's markup is re-parsed for nothing on every position or visibility update. This is
why `Tooltip` renders html through a memoised `HtmlContent`. Don't inline it back.
`<body>`, an `<img>` or autoplaying `<video>` is recreated and restarts, and the markup
is re-parsed for nothing on every position or visibility update. This is why `Tooltip`
renders html through a memoised `HtmlContent`, and `TourPanel` its HTML message and
custom progress through a memoised `RawHtml`. Don't inline either back.

**`Node.contains` includes the node itself.** `panel.contains(document.activeElement)` is
true when the panel holds focus, so a containment check can never decide whether to focus
Expand Down Expand Up @@ -81,14 +83,93 @@ button - `autoFocus: 'primary'` would put Enter on "end the tour". With `showCon
off, Close is the panel's only button, which is why the fallback is _marked primary →
panel_ and never "first focusable".

**Tour step `content` is injected as HTML.** `useTour` forces `html: true` whenever a step
has navigation features, and `showClose` defaults to true, so in practice every step goes
through `dangerouslySetInnerHTML`. Escape interpolations with the exported `escapeHtml`,
or use `TourStep.text`, which the library escapes.
**Tour step `content` is injected as HTML; `text` and `body` never are.** The panel is a
React element (`TourPanel`), so its title, labels and `text` are escaped by React. A
`content` string is the one thing it injects, scoped to the message element. A `text` or
`content` step with no panel features passes its body to the tooltip as-is, so `useTour`
sets `html` from the body's kind there: `false` for `text`, whatever the consumer's
`tooltipOptions.html` says, and `true` for `content` unless the step or tour explicitly set
`html: false` - which 1.3 consumers use to show untrusted strings as text. A `body` step
always renders the panel: a plain tooltip ignores the pointer and cannot scroll.

**Each tour step mounts a new panel.** `useTour` gives every presented step's
`LiveTourPanel` a key of its own - a counter, not the step index, which can move under a
running step when `steps` change. Focus inside the old panel drops to `<body>` and
`autoFocus` resolves afresh - without the key,
React reuses the Next button as the next step's Finish, focus stays on it, and `'panel'`
never moves focus to the new step's dialog. It also stops a `body` component's state
leaking from one step into the next.

**The tour panel reads its props from a store, not from the tooltip's state.** The
element `useTour` hands the tooltip is a `LiveTourPanel` that subscribes to a
`TourPanelStore`, so a running step can follow new `steps` (a body whose data arrived
after `start()`) in place. Routing that update through `tooltip.show` instead would
re-render every `useTipMagic` consumer - the component that called `useTour` among them,
whose inline `steps` would then update again, forever - and would re-run the tooltip's
`autoFocus` effect, which keys on its content.

Each shown step gets a store of its own. A store update re-renders synchronously while the
tooltip's dispatch may not (a navigation inside `startTransition`), so with one shared
store the outgoing panel rendered the next step's `body` before it was replaced.

**A `body` renders in the provider's tree, not the caller's.** The element is created in
the component that called `useTour` but rendered by `Tooltip`, under `TipMagicProvider`,
so it sees only the context providers above the provider.

**Unmounting the component that called `useTour` ends a running tour silently, a
microtask later.** The unmount cleanup tears it down - panel, backdrop, highlight, helper
flow - without `onExit` or `onEnd`. It is deferred and skipped if the hook has mounted
again, because `StrictMode`'s simulated unmount remounts within the same task: tearing
down there closed a tour started from a guarded mount effect, for good. A test has to
`await act(async () => ...)` the unmount to see the teardown.

Two consequences of the deferral. The cleanup is a layout effect that clears `mountedRef`
during the unmount commit, and `handleTargetLost` ignores a lost target once it is clear:
a target rendered inside the unmounting component detaches in the same commit, and the
`MutationObserver` would otherwise end the tour with `onTargetMissing`, `onExit` and
`onEnd` before the teardown ran. And the teardown releases the tooltip and helper flow only
while this tour still owns them (`HIDE_TOOLTIP` / `END_FLOW` with `onlyIfOwner` /
`onlyIfSteps`): by the time it runs, the component that replaced this one may have started
its own tour - from a layout effect, before the teardown. Ownership is a token minted per
show (`TooltipShowOptions.owner`), never the content: two plain-text steps with the same
string would compare equal.

**A centered step is shown against `document.body`.** `tooltip.show` needs an element, so
a step without a target passes `document.body` with `centered: true`; the target only
identifies the tooltip there, it never positions it. `Tooltip` then swaps its middleware
for `centerInViewport` and Floating UI's strategy for `fixed`, and never animates a move
between centered and anchored - the two strategies are different coordinate systems, so
the transform would slide from the wrong place. `size()` does not run for it; the
stylesheet caps a centered panel at the viewport instead.

**A centered panel's media sets its width in CSS, which only works without percentages.**
The panel is `width: fit-content`, everything but the media is `contain: inline-size` (so
text wraps instead of widening it), and the media is `width: auto` with `max-width` /
`max-height` in viewport units - a replaced element scaled by both keeps its aspect ratio.
A percentage `max-width` on the media would make its min-content contribution zero
("compressible" replaced element) and the panel would collapse to its minimum width. The
tooltip's own `max-width` is lifted with `maxWidth: 'none'` for such a step, since the
default 300px would clip it. The panel is hidden (`data-tip-magic-media-loading`, read by a
`:has()` rule) until the media's size is known; without `:has()` it opens at the minimum
width and widens on load.

**A squeezed panel has to overflow for `flip()` to move it.** `size()` caps the panel at
the room beside its target, and `flip()` measures the panel as it is - so a panel shrunk to
fit never flips. The cap therefore never drops below `--tip-magic-tour-min-height`.
`min-height: min-content` looks like the answer and is not: a scroll container's min-content
height is its whole content, so the body stops shrinking at all.

**Media beside the text is a grid, and its parts keep their DOM order.** The header, media,
body and footer are placed with `grid-template-areas`, so the header's `:has(+ media)` margin
rule (meant for media below it) is undone there, and the close button is positioned at the
panel's corner. The 640px fallback is a media query: a custom property cannot hold a
breakpoint.

**`onStepChange` fires before the panel exists on the first step.** It is called from
inside `start()`, so a consumer cannot use it to reach into the rendered panel.

**jsdom cannot answer two things**, so don't claim them from a passing test: it runs no
transitions (`transitionBehavior: 'move'` timing) and has no `:focus-visible` heuristic
(whether a programmatic focus draws a ring). Both need a browser.
**jsdom cannot answer three things**, so don't claim them from a passing test: it runs no
transitions (`transitionBehavior: 'move'` timing), has no `:focus-visible` heuristic
(whether a programmatic focus draws a ring), and has no layout, so the size()
middleware's `--tip-magic-available-height` is meaningless and whether a tall tour panel
fits the viewport with a scrolling body is unknowable. All three need a browser.
62 changes: 56 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,47 @@ const tour = useTour({ steps });
}
```

### Step content is HTML
### Step content: `text`, `body` or `content`

Step `content` is injected as HTML so that titles, media and controls work. Use `text` instead when the value is plain text the library should escape for you:
Each step takes at most one of them, and a step with none must have an `image` or `video` — a step with nothing to show, or with two bodies, won't compile.

```tsx
// Plain text, rendered as text
{ target: 'profile', text: `Signed in as ${user.name}` }
```

Exactly one of `content` or `text` is required — a step with neither, or with both, won't compile. For markup with an interpolated value, keep `content` and escape the value with the exported `escapeHtml`:
// Any React node (or a function of the current step returning one)
{ target: 'whats-new', title: "What's new", body: <Markdown source={releaseNotes} /> }

```tsx
// Raw HTML, injected as-is - escape interpolations
import { escapeHtml } from '@galangel/react-tip-magic';

{ target: 'profile', content: `Signed in as <b>${escapeHtml(user.name)}</b>` }
```

The panel itself is rendered by React, so titles, button labels and `text` are escaped for you. Only `content` is injected as HTML: escape any interpolated value with the exported `escapeHtml`.

A `body` renders inside `TipMagicProvider`, not inside the component that called `useTour`, so it sees only the context providers above `TipMagicProvider`. Re-render with new `steps` while the tour runs — data that arrived after `start()` — and the panel on screen updates in place. The step on screen is found again by its `id`, or by its `target` when no other step shares it — so give steps an `id` (or unique targets) if `steps` can change while the tour runs. If it is removed, or cannot be told apart, the tour moves on to the step now at its place, or ends. A long body scrolls once it reaches `--tip-magic-tour-body-max-height` (`60vh` by default), and the panel keeps itself within the viewport.

### Announcements: a step without a target

A step without a `target` opens centered in the viewport, with no arrow and the focus backdrop on (`focus: false` turns it off). It is the same panel as any other step, so a one-step announcement is just:

```tsx
const announcement = useTour({
steps: [{ title: "What's new", body: <Markdown source={releaseNotes} /> }],
navigation: { showControls: true, finishLabel: 'Got it' },
});
```

A centered panel is at most 80% of the viewport's height (`--tip-magic-tour-centered-max-height`), and its `image` (or native `video`) sets its width: the media's natural width, capped at 70% of the viewport (`--tip-magic-tour-centered-max-width`, and an explicit `tooltipOptions.maxWidth`), never cropped and scaled down uniformly when it would crowd out the text. The panel is never narrower than 280px (`--tip-magic-tour-min-width`); a smaller image is centered at its natural size.

A step can be only its media — `{ video: { src, title } }` — in which case the panel is named by `video.title`. Pass `navigation.autoFocus: 'primary'` to put focus on a "Got it" button so Enter dismisses the announcement.

Centered and anchored steps mix in one tour. With no target there is nothing to highlight, scroll to or watch, and `onTargetMissing` never fires for it.

### Media beside the text

`mediaPlacement: 'left' | 'right'` (tour-level, overridable per step) puts a step's image or video in a column beside its text, instead of above it (`'top'`, the default). The text column is 280–400px, its body scrolls, and its buttons sit at the bottom; the media keeps its aspect ratio. Below a 640px viewport it falls back to `'top'`.

### When a target isn't there

`start()` returns `false` and changes nothing—no `onStart`, no `onStepChange`—if no step's target is in the DOM, so a tour that can't render never reports itself as shown. Supply `onTargetMissing` to handle it yourself (and to keep the library off `console.warn`):
Expand Down Expand Up @@ -196,6 +221,31 @@ const tour = useTour({

Tours also support progress indicators, keyboard support, and backdrop highlighting (`focus: true`, or `focus: { dismissOnClick: true }` to let a click on the backdrop end the tour)—all configurable to fit your needs.

### Upgrading to 1.4

The tour panel is now rendered by React instead of injected as an HTML string. Things you can observe:

- `useTipMagic().tooltip.content` is `null` while a tour panel is showing. It used to hold the panel's HTML; it still returns string content for plain tooltips.
- A custom `progress.render` is wrapped in a `<div style="display: contents">` inside `.tip-magic-tour-footer`, so a `.tip-magic-tour-footer > .your-class` selector no longer matches. Layout is unchanged.
- A step whose only feature is a `title` now renders the panel (a `role="dialog"`) instead of dropping the title.
- A `content` step with no panel features is injected as HTML, as documented, without `tooltipOptions.html: true`. An explicit `html: false` (tour or step) still shows it as text.
- `text` is rendered once-escaped everywhere, and button labels as text rather than markup.
- Unmounting the component that called `useTour` takes a running tour down without calling `onEnd`.
- `CurrentTourStep.content` (in `currentStep`, `onStepChange`, `onTargetMissing`) is `''` for a `body` step: React content has no HTML form.
- A panel without a `title` is labelled by its message, so `aria-labelledby` is now always set on a tour dialog.
- `start()` also returns `false` when the first step has nothing to show (an empty body and no panel features).
- A step may be only its `image` or `video`, with no `text`, `body` or `content`; the video's type is exported as `TourVideo`, and `video.title` now names native videos too.
- `mediaPlacement` (`TourOptions` and `TourStep`, type `TourMediaPlacement`) is new and defaults to `'top'`, the existing layout.
- An anchored panel's height cap never drops below `--tip-magic-tour-min-height` (240px): with less room beside its target it flips to another side.
- `TourStep.target` is optional: a step without one opens centered. `CurrentTourStep.target` is `undefined` for such a step, so code that reads it as a `string` must handle that.

Type changes, for code that uses the exported context (`useTipMagicContext`, `TipMagicState`, `TipMagicAction`):

- `TooltipState.content` and the `SHOW_TOOLTIP` / `MOVE_TOOLTIP` payloads' `content` widened from `string` to `ReactNode`. Writing a string still works; code that reads one and annotates it as `string` must widen or narrow with `typeof`.
- `UPDATE_TOOLTIP_CONTENT` and `tooltip.updateContent` still take a `string`. Called while a tour runs, they replace the tour panel with that string.
- `HIDE_TOOLTIP` and `END_FLOW` accept an optional `payload` (`onlyIfOwner`, `onlyIfSteps`), and `TooltipShowOptions` gains `owner` and `centered`; all additive.
- `TooltipShowOptions.maxWidth` and `ParsedTooltipData.maxWidth` also accept `'none'` (let the content decide), which a centered step with an image uses. Code that reads `parsedData.maxWidth` as a `number` must handle it.

---

## Tip Advisor
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@galangel/react-tip-magic",
"version": "1.3.0",
"version": "1.4.0",
"description": "A sophisticated, elegant, and performant tooltip library for React with an intelligent floating helper system.",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
Loading