Table of Contents

Method Button

Namespace
Velvet
Assembly
Velvet.Docs.dll

Button(string?, string?, Action?, string?, string?, string?, bool?, StyleOverrides?, Func<VisualElement, Action>?, Func<VisualElement, VisualElement>?, string?, string?, string?, VNode?[]?, IReadOnlyDictionary<string, string>?, IReadOnlyDictionary<string, string>?)

Creates a Button. text and children can be combined. UI Toolkit's Button inherits from TextElement and keeps the text property and child VisualElements independently, so use children when declaring multiple children (e.g. icon + label) and text for text-only buttons.

public static ElementNode Button(string? className = null, string? text = null, Action? onClick = null, string? key = null, string? name = null, string? tooltip = null, bool? enabled = null, StyleOverrides? styles = null, Func<VisualElement, Action>? refCallback = null, Func<VisualElement, VisualElement>? wrapElement = null, string? whileHoverClass = null, string? whileTapClass = null, string? whileFocusClass = null, VNode?[]? children = null, IReadOnlyDictionary<string, string>? data = null, IReadOnlyDictionary<string, string>? aria = null)

Parameters

className string

CSS-like utility class string. Multiple classes separated by spaces.

text string

Button label text. Coexists with children.

onClick Action

Click handler. When null, no click event is bound.

key string

Key used to disambiguate siblings at the same position.

name string

Element name assigned to UnityEngine.UIElements.VisualElement.name for query/debug.

tooltip string

Tooltip string shown on hover.

enabled bool?

When false, disables the button (greyed out, no click).

styles StyleOverrides

Inline style overrides applied on top of USS classes.

refCallback Func<VisualElement, Action>

Callback invoked on mount with the created VisualElement; returned Action runs on unmount.

wrapElement Func<VisualElement, VisualElement>

Optional wrapper that returns a parent VisualElement enclosing the button (e.g. for shadow effects).

whileHoverClass string

USS class toggled while the pointer hovers the element.

whileTapClass string

USS class toggled while the pointer is pressed on the element.

whileFocusClass string

USS class toggled while the element holds keyboard/UI focus.

children VNode[]

Child VNodes (e.g. icon + label) rendered inside the button.

data IReadOnlyDictionary<string, string>

data-* attribute map matched by data-[...] variants.

aria IReadOnlyDictionary<string, string>

aria-* attribute map matched by aria-[...] variants.

Returns

ElementNode

The created ElementNode representing this button.

Button(string, params VNode?[])

Shorthand overload: positional className + variadic children, building a Button with just a class string and children (e.g. an icon + label). For any other prop — notably onClick — use the long-form overload with named arguments.

public static ElementNode Button(string className, params VNode?[] children)

Parameters

className string

CSS-like utility class string. Multiple classes separated by spaces.

children VNode[]

Child VNodes; pass zero or more positionals or expand an existing array.

Returns

ElementNode

The created ElementNode.