Skip to content
Page

Tooltip

Short hint on hover or focus.

import { Tooltip } from "@pelagornis/page/components";

The preview above renders this file. Copy it into src/components/ to start from it.

src/components/TooltipExample.tsx
import { Button, Stack, Tooltip } from "@pelagornis/page/components";
export default function TooltipDemo() {
return (
<Stack direction="row" gap="sizeSmall" wrap>
<Tooltip trigger={<Button variant="outline">Top</Button>} content="Shown above" position="Top" />
<Tooltip trigger={<Button variant="outline">Bottom</Button>} content="Shown below" position="Bottom" />
<Tooltip trigger={<Button variant="outline">Right</Button>} content="Shown on the right" position="Right" />
</Stack>
);
}

Tooltip is composed from parts that share React state. Children written in MDX are rendered as separate islands, so the parts can’t reach each other. Put the composition in a .tsx file, like the example above, and import that file instead.

src/content/docs/example.mdx
---
title: Example
---
import TooltipExample from "../../components/TooltipExample";
<TooltipExample client:load />

client:load hydrates the island on page load. Use client:visible for content far down the page.

Markdoc tags render Astro components, and this one needs client state. Wrap the example in an .astro file that hydrates it, then register that file as a tag.

src/components/markdoc/TooltipExample.astro
---
import TooltipExample from "../TooltipExample";
---
<TooltipExample client:load />
markdoc.config.mjs
import { component, defineMarkdocConfig } from "@astrojs/markdoc/config";
import starlightMarkdoc from "@astrojs/starlight-markdoc";
import pageMarkdoc from "@pelagornis/page/markdoc";
export default defineMarkdocConfig({
extends: [starlightMarkdoc(), pageMarkdoc()],
tags: {
"tooltip-example": {
render: component("./src/components/markdoc/TooltipExample.astro"),
selfClosing: true,
},
},
});
src/content/docs/example.mdoc
{% tooltip-example /%}

Parts of the component and the data-refineui role each one renders.

PartRole
roottooltip

Keys the component handles when it has focus.

KeyAction
Escapeclose