Skip to Content
Onevra

Tooltip

A short text hint shown when a control is hovered or focused.

Loading the live example…

tooltip.go
import (
	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type publish struct{}

func (publish) View(c *ui.Context) {
	ui.Row(c).Gap(8).Children(func() {
		save := components.Button(c, "Save draft", components.ButtonSecondary)
		components.Tooltip(c, save, "Saves without publishing")
		send := components.Button(c, "Publish", components.ButtonPrimary)
		components.Tooltip(c, send, "Makes the post visible to everyone")
	})
}
Source

Call components.Tooltip after building its anchor. MyGo owns the hover delay, keyboard-focus activation and placement. The text also becomes the anchor's accessible description.

API

Tooltip

func Tooltip(c *ui.Context, anchor ui.Element, text string) ui.Element

Tooltip attaches a non-interactive text hint to anchor. Call it each frame after building the anchor; both handles belong to the current build pass. MyGo owns hover delay, keyboard-focus activation, dismissal and positioning above the anchor (or below when space is limited).

The text also becomes anchor's accessible description. To provide a different description, call anchor.Description after Tooltip. Empty text does nothing. The returned tip is invalid while hidden. Use Popover for interactive content.

pkg.go.dev
Edit this page on GitHub

On this page