ButtonIcon
Icon buttons are used to execute minor actions with a single click.
Usage
Import the component:
import 'mdui/components/button-icon.js';
Import the TypeScript type:
import type { ButtonIcon } from 'mdui/components/button-icon.js';
Example:
<mdui-button-icon icon="search"></mdui-button-icon>
Examples
Icon
Use the icon
attribute to specify the Material Icons name. Alternatively, you can use the default slot to specify the icon element.
Shape
The variant
attribute determines the shape of the icon button.
Selectable
Add the selectable
attribute to make the icon button selectable.
Use the selected-icon
attribute to specify the Material Icons name for the selected state. Alternatively, use the selected-icon
slot to specify the selected state icon element.
The selected
property is true
when the icon button is selected. Add the selected
attribute to set the icon button to the selected state by default.
Link
Use the href
attribute to turn the icon button into a link. The download
, target
, and rel
attributes are available for link-related functionality.
Disabled and Loading State
Use the disabled
attribute to disable the icon button. The loading
attribute displays the loading state.
API
Properties
Attribute | Property | Reflect | Type | Default |
---|---|---|---|---|
variant | variant | 'standard' | 'filled' | 'tonal' | 'outlined' | 'standard' | |
Defines the icon button style. Possible values:
| ||||
icon | icon | string | - | |
Specifies the Material Icons name. Alternatively, use the default slot. | ||||
selected-icon | selectedIcon | string | - | |
Specifies the Material Icons name when selected. Alternatively, use | ||||
selectable | selectable | boolean | false | |
Indicates if the button is selectable. | ||||
selected | selected | boolean | false | |
Indicates if the button is selected. | ||||
href | href | string | - | |
The URL for the hyperlink. If provided, the component is rendered as an | ||||
download | download | string | - | |
Instructs the browser to download the linked URL. Note: This is only available when | ||||
target | target | '_blank' | '_parent' | '_self' | '_top' | - | |
Defines where to open the linked URL. Possible values:
Note: This is only available when | ||||
rel | rel | 'alternate' | 'author' | 'bookmark' | 'external' | 'help' | 'license' | 'me' | 'next' | 'nofollow' | 'noreferrer' | 'opener' | 'prev' | 'search' | 'tag' | - | |
Specifies the relationship of the linked URL as space-separated link types. Possible values:
Note: This is only available when | ||||
autofocus | autofocus | boolean | false | |
Specifies that the element should be focused when the page loads. | ||||
tabindex | tabIndex | number | - | |
Defines the order in which the element receives focus when navigating with the Tab key. | ||||
disabled | disabled | boolean | false | |
Disables the element. | ||||
loading | loading | boolean | false | |
Indicates that the element is in a loading state. | ||||
name | name | string | '' | |
The button's name, which is submitted with form data. Note: This is only available when | ||||
value | value | string | '' | |
The button's value, which is submitted with form data. Note: This is only available when | ||||
type | type | 'submit' | 'reset' | 'button' | 'button' | |
Defines the button's default behavior. The default is
Note: This is only available when | ||||
form | form | string | - | |
Associates the button with a This attribute allows button elements to be associated with Note: Only available when | ||||
formaction | formAction | string | - | |
Specifies the URL that processes the button's submitted information. Overrides the Note: Only available when | ||||
formenctype | formEnctype | 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain' | - | |
Specifies the form data encoding method. Possible values:
Overrides the Note: Only available when | ||||
formmethod | formMethod | 'post' | 'get' | - | |
Specifies the HTTP method for form submission. Possible values:
Overrides the Note: Only available when | ||||
formnovalidate | formNoValidate | boolean | false | |
Specifies that the form should not be validated on submission. Overrides the Note: Only available when | ||||
formtarget | formTarget | '_self' | '_blank' | '_parent' | '_top' | - | |
Specifies where to display the form submission response. Possible values:
Overrides the Note: Only available when | ||||
validity | ValidityState | - | ||
A | ||||
validationMessage | string | - | ||
The element's validation message. This is empty if the element meets its constraints. |
Methods
Name | Parameters | Returns |
---|---|---|
click | void | |
Simulates a mouse click on the element. | ||
focus |
| void |
Sets focus on the element. An optional parameter can be an object with a | ||
blur | void | |
Removes focus from the element. | ||
checkValidity | boolean | |
Checks the validity of the form field. If it's invalid, it triggers an | ||
reportValidity | boolean | |
Checks the validity of the form field. If it's invalid, it triggers an | ||
setCustomValidity |
| void |
Sets a custom error message. If the text is non-empty, it indicates that the field is invalid. |
Slots
Name |
---|
(default) |
Icon component. |
selected-icon |
Icon in the selected state. |
CSS Parts
Name |
---|
button |
Internal |
icon |
Icon. |
selected-icon |
Icon in the selected state. |
loading |
The |
CSS Custom Properties
Name |
---|
--shape-corner |
The size of the component corner. You can use a specific pixel value, but it's recommended to reference design tokens. |