Tooltip
A label that provides information on hover or focus.
A label that provides information on hover or focus.
To set up the tooltip correctly, you’ll need to understand its anatomy and how we name its parts.
Each part includes a
data-part
attribute to help identify them in the DOM.
Learn how to use the Tooltip
component in your project. Let’s take a look at
the most basic example:
import { Tooltip } from '@ark-ui/react'
const Basic = () => (
<Tooltip.Root lazyMount unmountOnExit>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
)
import { Tooltip } from '@ark-ui/solid'
import { Portal } from 'solid-js/web'
const Basic = () => (
<Tooltip.Root>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Portal>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Portal>
</Tooltip.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tooltip } from '@ark-ui/vue'
const isOpen = ref(false)
</script>
<template>
<Tooltip.Root>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
</template>
To create a controlled Tooltip component, manage the state of whether the
tooltip is open using the open
prop:
import { Tooltip } from '@ark-ui/react'
import { useState } from 'react'
const Controlled = () => {
const [isOpen, setIsOpen] = useState(false)
return (
<>
<button onClick={() => setIsOpen(!isOpen)}>Toggle</button>
<Tooltip.Root open={isOpen}>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
</>
)
}
import { Tooltip } from '@ark-ui/solid'
import { createSignal } from 'solid-js'
import { Portal } from 'solid-js/web'
const Controlled = () => {
const [isOpen, setIsOpen] = createSignal(false)
return (
<>
<button onClick={() => setIsOpen(!isOpen())}>Toggle</button>
<Tooltip.Root open={isOpen()}>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Portal>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Portal>
</Tooltip.Root>
</>
)
}
<script setup lang="ts">
import { ref } from 'vue'
import { Tooltip } from '@ark-ui/vue'
const isOpen = ref(false)
</script>
<template>
<button @click="isOpen = !isOpen">Toggle</button>
<Tooltip.Root :open="isOpen">
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
</template>
For more control over the Tooltip’s functionality, you can use a function as a child, which provides access to the Tooltip API:
import { Tooltip } from '@ark-ui/react'
const RenderFn = () => (
<Tooltip.Root>
{({ isOpen }) => (
<>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>This tooltip is open: {isOpen.toString()}</Tooltip.Content>
</Tooltip.Positioner>
</>
)}
</Tooltip.Root>
)
import { Tooltip } from '@ark-ui/solid'
import { Portal } from 'solid-js/web'
const RenderFn = () => (
<Tooltip.Root>
{(api) => (
<>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Portal>
<Tooltip.Positioner>
<Tooltip.Content>This tooltip is open: {api().isOpen.toString()}</Tooltip.Content>
</Tooltip.Positioner>
</Portal>
</>
)}
</Tooltip.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tooltip } from '@ark-ui/vue'
const isOpen = ref(false)
</script>
<template>
<Tooltip.Root v-slot="{ isOpen }">
<Tooltip.Trigger>Hover Me, isOpen {{ isOpen.toString() }}</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>This tooltip is open: {{ isOpen.toString() }}</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
</template>
To display an arrow pointing to the trigger from the tooltip, use the
Tooltip.Arrow
and Tooltip.ArrowTip
components:
import { Tooltip } from '@ark-ui/react'
const Arrow = () => (
<Tooltip.Root>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>
<Tooltip.Arrow>
<Tooltip.ArrowTip />
</Tooltip.Arrow>
I am a tooltip!
</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
)
import { Tooltip } from '@ark-ui/solid'
import { Portal } from 'solid-js/web'
const Arrow = () => (
<Tooltip.Root>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Portal>
<Tooltip.Positioner>
<Tooltip.Arrow>
<Tooltip.ArrowTip />
</Tooltip.Arrow>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Portal>
</Tooltip.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tooltip } from '@ark-ui/vue'
const isOpen = ref(false)
</script>
<template>
<Tooltip.Root>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>
<Tooltip.Arrow>
<Tooltip.ArrowTip />
</Tooltip.Arrow>
I am a tooltip!
</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
</template>
To configure the delay timings for the Tooltip, use the closeDelay
and
openDelay
props:
import { Tooltip } from '@ark-ui/react'
const Timings = () => (
<Tooltip.Root closeDelay={0} openDelay={0}>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
)
import { Tooltip } from '@ark-ui/solid'
import { Portal } from 'solid-js/web'
const Timings = () => (
<Tooltip.Root closeDelay={0} openDelay={0}>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Portal>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Portal>
</Tooltip.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tooltip } from '@ark-ui/vue'
const isOpen = ref(false)
</script>
<template>
<Tooltip.Root :closeDelay="0" :openDelay="0">
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
</template>
To customize the position of the Tooltip relative to the trigger, use the
positioning
prop:
import { Tooltip } from '@ark-ui/react'
const Positioning = () => (
<Tooltip.Root
positioning={{ placement: 'left-start', gutter: 16, offset: { mainAxis: 12, crossAxis: 12 } }}
>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
)
import { Tooltip } from '@ark-ui/solid'
import { Portal } from 'solid-js/web'
const Positioning = () => (
<Tooltip.Root
positioning={{ placement: 'left-start', gutter: 16, offset: { mainAxis: 12, crossAxis: 12 } }}
>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Portal>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Portal>
</Tooltip.Root>
)
<script setup lang="ts">
import { ref } from 'vue'
import { Tooltip } from '@ark-ui/vue'
const isOpen = ref(false)
</script>
<template>
<Tooltip.Root
:positioning="{
placement: 'left-start',
gutter: 16,
offset: { mainAxis: 12, crossAxis: 12 },
}"
>
<Tooltip.Trigger>Hover Me</Tooltip.Trigger>
<Tooltip.Positioner>
<Tooltip.Content>I am a tooltip!</Tooltip.Content>
</Tooltip.Positioner>
</Tooltip.Root>
</template>
Prop | Type | Default |
---|---|---|
aria-label Custom label for the tooltip. | string | |
closeDelay The close delay of the tooltip. | number | |
closeOnEsc Whether to close the tooltip when the Escape key is pressed. | boolean | |
closeOnPointerDown Whether to close the tooltip on pointerdown. | boolean | |
dir The document's text/writing direction. | 'ltr' | 'rtl' | "ltr" |
disabled Whether the tooltip is disabled | boolean | |
getRootNode A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron. | () => Node | ShadowRoot | Document | |
id The `id` of the tooltip. | string | |
ids The ids of the elements in the tooltip. Useful for composition. | Partial<{
trigger: string
content: string
arrow: string
positioner: string
}> | |
interactive Whether the tooltip's content is interactive. In this mode, the tooltip will remain open when user hovers over the content. | boolean | |
lazyMount Whether to enable lazy mounting | boolean | false |
onExitComplete Function called when the animation ends in the closed state. | () => void | |
onOpenChange Function called when the tooltip is opened. | (details: OpenChangeDetails) => void | |
open Whether the tooltip is open | boolean | |
openDelay The open delay of the tooltip. | number | |
positioning The user provided options used to position the popover content | PositioningOptions | |
present Whether the node is present (controlled by the user) | boolean | |
unmountOnExit Whether to unmount on exit. | boolean | false |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Prop | Type | Default |
---|---|---|
asChild Render as a different element type. | boolean |
Previous
Toggle GroupNext
Changelog