HelpButton
Info icon that opens an explanation on click, for a label that needs more than a label. Unlike a tooltip it stays open, so the text inside can hold a link.
Use this when / not when
- Use next to a field or a setting whose meaning is not obvious, for a sentence or two the user opens deliberately.
- Not for a hint on hover — that is
Tooltip, which this component uses underneath. - Not for a whole page of help. An explanation that long belongs in an
Asideor a link out. - Not as a form control's description. Text the user should read without asking belongs under
the field, in
FieldContainer.
Import
import { HelpButton } from "@onlyoffice/apps-ui-kit/components/help-button";
Also exported from the root barrel @onlyoffice/apps-ui-kit.
Needs ThemeProvider from @onlyoffice/apps-ui-kit/providers/theme for the icon and the
tooltip's colours. A string tooltip is shown by the shared tooltip, which means
RootTooltip has to be mounted somewhere in the application; a node is
shown by a tooltip this component renders itself and needs nothing.
Stories
Default
The info icon with a short explanation beside it; click the icon to open it, and change any other prop live in the Controls panel below.
Custom Style
An icon larger or in another colour stands out next to a heading rather than a field label. Click each icon to open its tooltip.
With Custom Content
An explanation that needs a heading or a list goes in as a React node, which opens in the component's own tooltip with no shared tooltip mounted.
Tooltip Positions
The side matters when the icon sits at the edge of a form or next to other controls. Click each icon to see its tooltip open on the side written under it.
With Text Content
Plain text needs no tooltip of its own: a string is shown by the application's shared tooltip, so it appears only where RootTooltip is mounted once, as it is here. Click the icon to open it.
With Custom Anchor
When the label itself should open the explanation, pass it as children in place of the icon. Click Storage to open a tooltip no wider than 240px (tooltipMaxWidth).
Opens On Hover
A one-line hint with nothing to click inside can open on hover instead (openOnClick={false}). Point at the icon to open it; the tooltip closes when the pointer leaves.
Css Customization
The tooltip's variables passed through tooltipStyle -- the variables are listed under CSS variables on this page. Click either icon to see the custom colours; the second tooltip's longer text wraps at 180px.
Minimal example
Give it an id: without one the anchor is renamed on every render.
import { HelpButton } from "@onlyoffice/apps-ui-kit/components/help-button";
import { Text } from "@onlyoffice/apps-ui-kit/components/text";
export function QuotaHelp() {
return (
<HelpButton
id="quota-help"
tooltipContent={
<Text fontSize="12px">
The room's quota counts every version of every file in it.
</Text>
}
/>
);
}
Props
Inherited from IconButtonProps
Declared by components/icon-button and accepted here too.
Recipes
Open and close, controlled
isOpen works only for the tooltip this component renders — that is, when the content is a
node rather than a string.
import { useState } from "react";
import { Button } from "@onlyoffice/apps-ui-kit/components/button";
import { HelpButton } from "@onlyoffice/apps-ui-kit/components/help-button";
import { Text } from "@onlyoffice/apps-ui-kit/components/text";
export function ControlledHelp() {
const [open, setOpen] = useState(false);
return (
<>
<Button label="Explain" onClick={() => setOpen(!open)} />
<HelpButton
id="explain-help"
isOpen={open}
afterHide={() => setOpen(false)}
tooltipContent={<Text fontSize="12px">Only owners may do this.</Text>}
/>
</>
);
}
An anchor of your own
children replaces the icon, and the whole element becomes what the tooltip opens from.
import { HelpButton } from "@onlyoffice/apps-ui-kit/components/help-button";
import { Text } from "@onlyoffice/apps-ui-kit/components/text";
export function LabelWithHelp() {
return (
<HelpButton
id="storage-help"
place="right"
tooltipMaxWidth="240px"
tooltipContent={
<Text fontSize="12px">Storage is counted across all your rooms.</Text>
}
>
<span style={{ textDecoration: "underline dotted" }}>Storage</span>
</HelpButton>
);
}
Behaviour the types don't state
- There are two tooltips, and the type of your content picks which. A string — from
tooltipContentor returned bygetContent— is handed to the sharedinfo-tooltipthrough data attributes, so nothing appears unlessRootTooltipis mounted. Anything else makes the component render its ownTooltip, which needs no such thing.isOpen,afterShow,afterHide,offsetandtooltipMaxWidthonly reach the second one. - Without an
idthe anchor changes on every render. The component falls back to a fresh generated id each time it renders, and the tooltip finds its anchor by a selector built from that id — so a button inside something that re-renders loses its tooltip. - It opens on click by default, not on hover, and the tooltip is
clickable, which is what lets a link inside it be reached. It stays open until the next click on the icon, Escape, a click elsewhere, a scroll or a window resize. WithopenOnClickoff it opens on hover and closes when the pointer leaves. placeis a preference: when that side has no room the tooltip flips to another one.- The icon is the kit's info glyph at 12px, in the theme's grey, unless you pass
iconNode, and it is anIconButton— a<div>, so not focusable and not activated by Enter.iconNameis ignored: the component always handsIconButtonaniconNode, its own glyph when you give none, andIconButtonreadsiconNameonly without one. tooltipId,tooltipProps,offsetTop,offsetRight,offsetBottomandoffsetLeftare declared and never read.- The component renders a wrapper
<div>of its own around the anchor, with no display or size of its own; put it in a flex row next to the label.
CSS variables
HelpButton has no stylesheet of its own; these belong to the Tooltip
it renders for node content. That tooltip lives in a portal, outside the HelpButton's wrapper,
so a value set around the component never reaches it: pass the variables in tooltipStyle,
which lands on the tooltip box itself, or set them on :root. A string tooltip is drawn by the
shared RootTooltip, which tooltipStyle does not reach.
The rest of the tooltip's variables are listed in its README. The icon's colour is not a
variable you can set from outside: IconButton writes --icon-button-color on the icon
element itself, so use the color prop.
Accessibility
- The anchor is an
IconButton, which renders a<div>with no role, no tab stop and no key handler. The explanation is unreachable from the keyboard and unannounced by a screen reader. - Give the wrapper a
tabIndexand aroleof your own, or put the same text in the page where it does not need opening, when the content matters. - Once open, the tooltip closes on Escape.
- The tooltip is not linked to anything by
aria-describedby; nothing here reaches the accessibility tree.
Test ids
The icon inside carries icon-button from IconButton.
Related
Tooltip— what this renders, andRootTooltip, which a string tooltip needs.IconButton— the icon itself, and the props inherited from it.FieldContainer— where a help button usually sits.