Salt la conținutul principal

Prezentare generală

Folosiți Tooltip pentru o explicație scurtă a unui element de control sau a textului trunchiat. Păstrați informațiile esențiale vizibile, oferiți elementelor de control un nume accesibil și folosiți Fereastră contextuală atunci când conținutul conține linkuri, butoane sau alte elemente de control.

Utilizare

Componenta de conveniență acceptă un element declanșator ca children. Elementele native primesc direct atributele declanșatorului, gestionarele de evenimente și referința. Componentele declanșatoare personalizate trebuie să le redirecționeze pe toate. Un element învăluitor funcționează și cu o componentă care nu redirecționează fiecare proprietate a declanșatorului. Trecerea cursorului deschide tooltipul după delay milisecunde, care are implicit valoarea 600. Focalizarea de la tastatură îl deschide imediat. closeDelay are implicit valoarea 0; trecerea cursorului peste fereastra pop-up o menține deschisă, cu excepția cazului în care este setat disableHoverablePopup. Tasta Escape îl închide.

Stare controlată

Utilizați împreună open și onOpenChange când aplicația controlează vizibilitatea. Utilizați defaultOpen numai pentru a seta vizibilitatea inițială a unui tooltip necontrolat.

Conținut îmbogățit și compoziție

Forma prescurtată acceptă description și startIcon pe lângă content. Conținutul nodului personalizat este redat așa cum este furnizat, cu excepția cazului în care o descriere sau o pictogramă solicită aspectul titlului.
Utilizarea compusă expune fiecare parte Base UI instalată și structura opțională Tooltip.Body. Asamblați explicit portalul, poziționarea, fereastra pop-up și săgeata opțională. Popup redă elementele sale copil așa cum sunt furnizate; Body oferă aceeași structură de titlu, descriere și pictogramă decorativă ca forma prescurtată.
Tooltip.Body acceptă elemente copil title opționale, noduri description și startIcon. Titlurile folosesc grosime medie; descrierile folosesc culoarea secundară a tooltipului, păstrează întreruperile de linie și încadrează textul lung. Omiteți elementele copil title pentru un tooltip care conține doar o descriere. Pictograma este decorativă și apare doar împreună cu un titlu. Body nu adaugă niciun rol de tooltip, stilizare de popup, dimensionare sau poziționare. Conținutul Popup arbitrar rămâne acceptat. Importați TooltipBodyProps din twenty-ui/primitives/surfaces când tipizați un wrapper. Fiecare parte DOM acceptă proprietăți native, referințe și compoziție render cu element sau funcție de apel invers. Proprietățile native de nivel superior ale formei prescurtate, render și referința vizează Popup. Utilizați triggerProps, positionerProps și portalProps pentru a personaliza celelalte ținte; acestea suprascriu valorile implicite ale formei prescurtate. Elementele copil furnizează elementul implicit de redare a declanșatorului. Ambele forme păstrează starea Root controlată/necontrolată și detaliile evenimentelor de apel invers Base UI, inclusiv anularea, motivul, evenimentul original și declanșatorul activ. Tooltip.createHandle\<TPayload>() conectează declanșatoarele detașate la oricare dintre forme prin handle. Elementele copil ale Root compus sau content al formei prescurtate pot fi o funcție care primește încărcătura utilă activă tipizată. Tooltip.Handle și tipul public TooltipHandle expun contractul handle instalat. Handle-urile acceptă apelurile imperative open(triggerId) și close() cât timp Root-ul lor este montat.

Migrare

Înlocuiți content={<Tooltip.Content description={description} startIcon={icon}>title</Tooltip.Content>} cu content={title} description={description} startIcon={icon}. În utilizarea compusă, folosiți Tooltip.Body pentru aspectul comun al titlului și al descrierii sau compuneți propriul conținut. Tooltip.Content și TooltipContentProps sunt eliminate. Proprietățile existente de poziționare Popup compus se mută la Positioner. Înfășurați-l în Portal, mutați container și keepMounted în Portal, păstrați maxWidth în Popup și înlocuiți arrow cu un copil Arrow. Păstrați explicit spațierea anterioară cu sideOffset={10} atunci când este necesar. Compound Positioner păstrează sideOffset={0} din Base UI. Ambele forme limitează implicit Popup la 300 de pixeli.

Comenzi dezactivate

Butoanele native dezactivate nu pot primi focalizare de la tastatură. Înfășurați unul într-un declanșator focalizabil, astfel încât utilizatorii să poată afla de ce acțiunea nu este disponibilă.
Setarea disabled pe forma prescurtată sau pe Root suprimă tooltipul propriu-zis. disabled al declanșatorului suprimă interacțiunea cu tooltipul acelui declanșator. Dezactivați controlul nativ prin propriile sale proprietăți sau prin elementul de redare al Trigger.

Plasare și text care depășește spațiul disponibil

Forma prescurtată are implicit side="top", align="center" și sideOffset={10}. Atât descrierile scurte, cât și cele complexe au o lățime maximă de 300 de pixeli, limitată de spațiul disponibil de lângă ancoră. Transmiteți maxWidth către descrierea scurtă sau către Tooltip.Popup pentru a alege o altă valoare maximă, inclusiv previzualizări mai late. Stilurile native de ferestre pop-up rămân disponibile pentru dimensionare personalizată. Plasarea se ajustează la spațiul disponibil. Un tooltip deschis se ascunde când ancora sa este derulată în afara vizualizării, inclusiv în afara unui container de derulare. Utilizați arrow pentru o săgeată și container pentru a suprascrie destinația portalului temei; consultați tematizarea. Utilizați OverflowingTextWithTooltip când o etichetă text trebuie să-și afișeze valoarea completă numai atunci când este trunchiată. Proprietățile sale existente text, tooltipContent și tooltipPlace rămân disponibile.

Proprietăți

Referința este generată din tipurile de componente publice. Sunt acceptate și atributele native ale ferestrei pop-up, precum și gestionarele de evenimente.
RefObject<TooltipRootActions | null>
A ref to imperative actions.
  • unmount: Ends the closing phase of the tooltip after an externally controlled closing animation finishes. Call preventUnmountOnClose() in onOpenChange first, otherwise the tooltip completes closing on its own. Whether it leaves the DOM is decided by keepMounted on the portal.
  • close: Closes the tooltip imperatively when called.
"center" | "end" | "start"
implicit:"center"
Alignment relative to the trigger. Defaults to center.
number | OffsetFunction
implicit:"0"
Offset along the alignment axis in pixels.
Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null) | null
An explicit positioning anchor for the popup.
boolean
Displays an arrow pointing to the trigger. Defaults to false.
number
implicit:"5"
Minimum distance from the arrow to the popup edges.
ReactElement<unknown, string | JSXElementConstructor<any>>
obligatoriu
A single trigger element. Custom components must forward their ref, native attributes, and event handlers.
string | ((state: TooltipPopupState) => string | undefined)
Additional CSS class for the popup.
number
implicit:"0"
Delay in milliseconds before closing after hover ends. Defaults to 0.
boolean
implicit:"true"
Whether the tooltip should close when this trigger is clicked.
CollisionAvoidance
Determines how to handle collisions when positioning the popup.side controls overflow on the preferred placement axis (top/bottom or left/right):
  • 'flip': keep the requested side when it fits; otherwise try the opposite side (top and bottom, or left and right).
  • 'shift': never change side; keep the requested side and move the popup within the clipping boundary so it stays visible.
  • 'none': do not correct side-axis overflow.
align controls overflow on the alignment axis (start/center/end):
  • 'flip': keep side, but swap start and end when the requested alignment overflows.
  • 'shift': keep side and requested alignment, then nudge the popup along the alignment axis to fit.
  • 'none': do not correct alignment-axis overflow.
fallbackAxisSide controls fallback behavior on the perpendicular axis when the preferred axis cannot fit:
  • 'start': allow perpendicular fallback and try the logical start side first (top before bottom, or left before right in LTR).
  • 'end': allow perpendicular fallback and try the logical end side first (bottom before top, or right before left in LTR).
  • 'none': do not fallback to the perpendicular axis.
When side is 'shift', explicitly setting align only supports 'shift' or 'none'. If align is omitted, it defaults to 'flip'.
Boundary
implicit:"clipping-ancestors"
An element or a rectangle that delimits the area that the popup is confined to.
Padding
implicit:"5"
Additional space to maintain from the edge of the collision boundary.
HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null
Portal destination. Defaults to the current theme container.
ReactNode | PayloadChildRenderFunction<TPayload>
obligatoriu
Supplementary content, or a function receiving the active trigger payload. Strings and numbers use the shorthand title layout.
boolean
implicit:"false"
Initial visibility when the tooltip manages its own state.
string | null
ID of the trigger that the tooltip is associated with. This is useful in conjunction with the defaultOpen prop to create an initially open tooltip.
number
implicit:"600"
Delay in milliseconds before opening on hover. Defaults to 600.
ReactNode
Optional secondary text below the shorthand title.
boolean
implicit:"false"
Whether to disable the popup from tracking any layout shift of its positioning anchor.
boolean
implicit:"false"
Prevents the tooltip from opening.
boolean
implicit:"false"
Prevents hovering over the popup from keeping it open.
TooltipHandle<TPayload>
Connects detached triggers and preserves their typed payloads.
boolean
Keeps the popup mounted while closed.
MaxWidth<string | number>
Maximum popup width. Defaults to 300 pixels and is capped by the space available beside the anchor.
((open: boolean, eventDetails: TooltipRootChangeEventDetails) => void)
Receives the requested open state and unchanged Base UI event details, including reason, event, trigger and cancel().
((open: boolean) => void)
Event handler called after any animations complete when the tooltip is opened or closed.
boolean
Controlled visibility of the tooltip.
TooltipPortalProps
Full Portal props, including native props, ref and render. Overrides shorthand portal defaults.
TooltipPositionerProps
Full Positioner props, including native props, ref and render. Overrides shorthand placement defaults.
"absolute" | "fixed"
implicit:"absolute"
CSS positioning method for the popup.
Ref<HTMLDivElement>
Ref forwarded to the popup element.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TooltipPopupState>
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.
"bottom" | "inline-end" | "inline-start" | "left" | "right" | "top"
implicit:"top"
Preferred side of the trigger. Defaults to top and may change to avoid collisions.
number | OffsetFunction
implicit:"10"
Distance from the trigger in pixels. Defaults to 10.
ReactNode
Optional node before the shorthand title.
boolean
implicit:"false"
Whether to maintain the popup in the viewport after the anchor element was scrolled out of view.
CSSProperties | ((state: TooltipPopupState) => CSSProperties | undefined)
Inline styles for the popup.
"both" | "none" | "x" | "y"
implicit:"none"
Determines which axis the tooltip should track the cursor on.
string | null
ID of the trigger that the tooltip is associated with. This is useful in conjunction with the open prop to create a controlled tooltip. There’s no need to specify this prop when the tooltip is uncontrolled (that is, when the open prop is not set).
TooltipTriggerProps<TPayload>
Full Trigger props, including native props, ref, render and payload. Overrides the shorthand trigger defaults.
boolean
Fades and slides the popup out when it closes instead of hiding it at once.

Tooltip.Root

RefObject<TooltipRootActions | null>
A ref to imperative actions.
  • unmount: Ends the closing phase of the tooltip after an externally controlled closing animation finishes. Call preventUnmountOnClose() in onOpenChange first, otherwise the tooltip completes closing on its own. Whether it leaves the DOM is decided by keepMounted on the portal.
  • close: Closes the tooltip imperatively when called.
ReactNode | PayloadChildRenderFunction<Payload>
Parts or a render function receiving the active trigger payload. Root renders no DOM node.
boolean
implicit:"false"
Whether the tooltip is initially open.To render a controlled tooltip, use the open prop instead.
string | null
ID of the trigger that the tooltip is associated with. This is useful in conjunction with the defaultOpen prop to create an initially open tooltip.
boolean
implicit:"false"
Whether the tooltip is disabled.
boolean
implicit:"false"
Whether the tooltip contents can be hovered without closing the tooltip.
TooltipHandle<Payload>
Connects detached triggers and imperative open/close actions.
((open: boolean, eventDetails: TooltipRootChangeEventDetails) => void)
Receives the requested open state and unchanged Base UI event details, including reason, event, trigger and cancel().
((open: boolean) => void)
Event handler called after any animations complete when the tooltip is opened or closed.
boolean
Whether the tooltip is currently open.
"both" | "none" | "x" | "y"
implicit:"none"
Determines which axis the tooltip should track the cursor on.
string | null
ID of the trigger that the tooltip is associated with. This is useful in conjunction with the open prop to create a controlled tooltip. There’s no need to specify this prop when the tooltip is uncontrolled (that is, when the open prop is not set).

Tooltip.Trigger

string | ((state: TooltipTriggerState) => string | undefined)
CSS class applied to the element, or a function that returns a class based on the component’s state.
number
implicit:"0"
How long to wait before closing the tooltip. Specified in milliseconds.
boolean
implicit:"true"
Whether the tooltip should close when this trigger is clicked.
number
implicit:"600"
How long to wait before opening the tooltip on hover. Specified in milliseconds.
boolean
implicit:"false"
Disables tooltip interaction for this trigger without disabling its native element.
TooltipHandle<Payload>
A handle to associate the trigger with a tooltip.
Payload
A payload to pass to the tooltip when it is opened.
((((instance: HTMLButtonElement | null) => void | (() => VoidOrUndefinedOnly)) | RefObject<HTMLButtonElement | null>) & (((instance: HTMLElement | null) => void | (() => VoidOrUndefinedOnly)) | RefObject<...>)) | null
Ref to the rendered trigger element, a button by default.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TooltipTriggerState>
Composes a native element or a component that forwards attributes, handlers and ref.
CSSProperties | ((state: TooltipTriggerState) => CSSProperties | undefined)
Style applied to the element, or a function that returns a style object based on the component’s state.

Tooltip.Portal

string | ((state: TooltipPortalState) => string | undefined)
CSS class applied to the element, or a function that returns a class based on the component’s state.
HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null
Portal destination. Defaults to the current theme container, then the document body.
boolean
implicit:"false"
Whether to keep the portal mounted in the DOM while the popup is hidden.
Ref<HTMLDivElement>
Ref to the portal div.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TooltipPortalState>
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.
CSSProperties | ((state: TooltipPortalState) => CSSProperties | undefined)
Style applied to the element, or a function that returns a style object based on the component’s state.

Tooltip.Positioner

"center" | "end" | "start"
implicit:"center"
How to align the popup relative to the specified side.
number | OffsetFunction
implicit:"0"
Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment.The function takes a data object parameter with the following properties:
  • data.anchor: the dimensions of the anchor element with properties width and height.
  • data.positioner: the dimensions of the positioner element with properties width and height.
  • data.side: which side of the anchor element the positioner is aligned against.
  • data.align: how the positioner is aligned relative to the specified side.
Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null) | null
An element to position the popup against. By default, the popup will be positioned against the trigger.
number
implicit:"5"
Minimum distance to maintain between the arrow and the edges of the popup.Use it to prevent the arrow element from hanging out of the rounded corners of a popup.
string | ((state: TooltipPositionerState) => string | undefined)
CSS class applied to the element, or a function that returns a class based on the component’s state.
CollisionAvoidance
Determines how to handle collisions when positioning the popup.side controls overflow on the preferred placement axis (top/bottom or left/right):
  • 'flip': keep the requested side when it fits; otherwise try the opposite side (top and bottom, or left and right).
  • 'shift': never change side; keep the requested side and move the popup within the clipping boundary so it stays visible.
  • 'none': do not correct side-axis overflow.
align controls overflow on the alignment axis (start/center/end):
  • 'flip': keep side, but swap start and end when the requested alignment overflows.
  • 'shift': keep side and requested alignment, then nudge the popup along the alignment axis to fit.
  • 'none': do not correct alignment-axis overflow.
fallbackAxisSide controls fallback behavior on the perpendicular axis when the preferred axis cannot fit:
  • 'start': allow perpendicular fallback and try the logical start side first (top before bottom, or left before right in LTR).
  • 'end': allow perpendicular fallback and try the logical end side first (bottom before top, or right before left in LTR).
  • 'none': do not fallback to the perpendicular axis.
When side is 'shift', explicitly setting align only supports 'shift' or 'none'. If align is omitted, it defaults to 'flip'.
Boundary
implicit:"clipping-ancestors"
An element or a rectangle that delimits the area that the popup is confined to.
Padding
implicit:"5"
Additional space to maintain from the edge of the collision boundary.
boolean
implicit:"false"
Whether to disable the popup from tracking any layout shift of its positioning anchor.
"absolute" | "fixed"
implicit:"absolute"
Determines which CSS position property to use.
Ref<HTMLDivElement>
Ref to the positioning div. Native props, styles and render target this element.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TooltipPositionerState>
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.
"bottom" | "inline-end" | "inline-start" | "left" | "right" | "top"
implicit:"top"
Preferred physical or logical side of the anchor. Defaults to top.
number | OffsetFunction
implicit:"0"
Distance from the anchor. Defaults to 0 in compound usage. Accepts a number or positioning function.
boolean
implicit:"false"
Whether to maintain the popup in the viewport after the anchor element was scrolled out of view.
CSSProperties | ((state: TooltipPositionerState) => CSSProperties | undefined)
Style applied to the element, or a function that returns a style object based on the component’s state.

Tooltip.Popup

ReactNode
Content rendered as supplied. Does not create a portal, positioner, title layout or arrow.
string | ((state: TooltipPopupState) => string | undefined)
CSS class applied to the element, or a function that returns a class based on the component’s state.
MaxWidth<string | number>
Maximum popup width. Defaults to 300 pixels and is capped by the space available beside the anchor.
Ref<HTMLDivElement>
Ref to the popup div. Native props, styles and render target this element.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TooltipPopupState>
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.
CSSProperties | ((state: TooltipPopupState) => CSSProperties | undefined)
Style applied to the element, or a function that returns a style object based on the component’s state.
boolean
implicit:"false"
Enables the optional Twenty exit transition.

Tooltip.Body

ReactNode
Optional title content, displayed with medium weight. Omit it for a description-only tooltip.
ReactNode
Optional secondary content. Preserves line breaks and wraps long text.
Ref<HTMLDivElement>
Ref to the body div. Native props, styles and render target this element.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>
Composes the body root through an element or render callback while preserving its layout and content.
ReactNode
Optional decorative node before the title. Omitted when the title is empty.

Tooltip.Arrow

string | ((state: TooltipArrowState) => string | undefined)
CSS class applied to the element, or a function that returns a class based on the component’s state.
Ref<HTMLDivElement>
Ref to the arrow div. Compose inside Popup.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TooltipArrowState>
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.
CSSProperties | ((state: TooltipArrowState) => CSSProperties | undefined)
Style applied to the element, or a function that returns a style object based on the component’s state.

Tooltip.Viewport

ReactNode
The content to render inside the transition container.
string | ((state: TooltipViewportState) => string | undefined)
CSS class applied to the element, or a function that returns a class based on the component’s state.
Ref<HTMLDivElement>
Ref to the content-transition div. Useful when several triggers share changing content.
ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, TooltipViewportState>
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.
CSSProperties | ((state: TooltipViewportState) => CSSProperties | undefined)
Style applied to the element, or a function that returns a style object based on the component’s state.

Tooltip.Provider

ReactNode
Tooltips sharing delay, closeDelay and timeout configuration. Provider renders no DOM node.
number
How long to wait before closing a tooltip. Specified in milliseconds.
number
How long to wait before opening the tooltip on hover. Specified in milliseconds.
number
implicit:"400"
Another tooltip will open instantly if the previous tooltip is closed within this timeout. Specified in milliseconds.