Class IconButton
A button component that displays only an icon, ideal for compact UI actions.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class IconButton : ExVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, ISizeableElement, IPressable
Remarks
IconButton is a specialized button component that displays an icon without text. It's commonly used for toolbar actions, navigation items, or any UI element where space is limited and the icon clearly communicates the action.
The component supports different sizes, variants, and states to accommodate various design requirements and user interactions.
IconButtons can be styled with primary and quiet variants, making them versatile for different visual hierarchies in your interface.
For accessibility, IconButtons are keyboard focusable and support keyboard navigation with a tabIndex of 0 by default.
Examples
**Basic IconButton Usage.** Different variations of IconButton usage in C#.
// Create a simple icon button
var deleteButton = new IconButton("delete");
deleteButton.clicked += () => HandleDelete();
// Create a primary action button
var addButton = new IconButton("add") ;
// Create a quiet variant for secondary actions
var menuButton = new IconButton("menu") ;
**UXML Integration.** Using IconButton in UXML markup.
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:appui="Unity.AppUI.UI">
<appui:IconButton icon="settings"
size="M"
primary="false"
quiet="false"
variant="Regular" />
</ui:UXML>
**Toolbar Example.** Creating a toolbar with multiple IconButtons.
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:appui="Unity.AppUI.UI">
<ui:VisualElement class="toolbar">
<appui:IconButton icon="undo" quiet="true" size="S" />
<appui:IconButton icon="redo" quiet="true" size="S" />
<appui:IconButton icon="save" primary="true" size="S" />
<appui:IconButton icon="delete" size="S" />
</ui:VisualElement>
</ui:UXML>
Constructors
IconButton()
Default constructor.
Declaration
public IconButton()
IconButton(string, Action)
Construct an IconButton with a given icon.
Declaration
public IconButton(string iconName, Action clickEvent = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | iconName | The name of the icon. |
| Action | clickEvent | The click event callback. |
Fields
containerUssClassName
The IconButton leading container styling class.
Declaration
public const string containerUssClassName = "appui-button__leadingcontainer"
Field Value
| Type | Description |
|---|---|
| string |
iconUssClassName
The IconButton leading icon styling class.
Declaration
public const string iconUssClassName = "appui-button__leadingicon"
Field Value
| Type | Description |
|---|---|
| string |
primaryUssClassName
The IconButton primary variant styling class.
Declaration
public const string primaryUssClassName = "appui-button--primary"
Field Value
| Type | Description |
|---|---|
| string |
quietUssClassName
The IconButton quiet mode styling class.
Declaration
public const string quietUssClassName = "appui-button--quiet"
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The IconButton size styling class.
Declaration
public const string sizeUssClassName = "appui-button--size-"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The IconButton main styling class.
Declaration
public const string ussClassName = "appui-button"
Field Value
| Type | Description |
|---|---|
| string |
Properties
clickable
Clickable Manipulator for this Button.
Declaration
[CreateProperty]
public Pressable clickable { get; set; }
Property Value
| Type | Description |
|---|---|
| Pressable |
icon
The IconButton icon.
Declaration
[CreateProperty]
[UxmlAttribute]
public string icon { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
primary
Use the primary variant of the Button.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool primary { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
quiet
The quiet state of the Button.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool quiet { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
size
The Button size.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
variant
The IconButton icon variant.
Declaration
[CreateProperty]
[UxmlAttribute]
public IconVariant variant { get; set; }
Property Value
| Type | Description |
|---|---|
| IconVariant |
Methods
GetSizeUssClassName(Size)
Declaration
public static string GetSizeUssClassName(Size enumValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | enumValue |
Returns
| Type | Description |
|---|---|
| string |
Events
clicked
Event triggered when the Button has been clicked.
Declaration
public event Action clicked
Event Type
| Type | Description |
|---|---|
| Action |