Chip
Chips are compact elements that represent an input, attribute, or action.
Usage
Import the component:
import 'mdui/components/chip.js';
Import the TypeScript type:
import type { Chip } from 'mdui/components/chip.js';
Example:
<mdui-chip>Chip</mdui-chip>Examples
Variant
The variant attribute determines the chip's appearance. There are four available variants:
assist: Used for auxiliary actions related to the current context, such as sharing or favoriting an item.filter: Represents filters for a collection.input: Represents discrete pieces of information entered by a user.suggestion: Helps narrow a user’s intent by presenting dynamically generated suggestions.
Elevated
Add the elevated attribute to give the chip a shadow.
Icons
Use the icon and end-icon attributes to add Material Icons to the left and right sides of the chip, respectively. Alternatively, use the icon and end-icon slots to add elements to the chip's sides.
Link
Use the href attribute to turn the chip into a link. The download, target, and rel attributes are available for link-related functionality.
Disabled and Loading States
Use the disabled attribute to disable the chip. The loading attribute shows the loading state.
Selectable
Add the selectable attribute to make the chip selectable.
Use the selected-icon attribute to specify the Material Icon 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 chip is selected. Add the selected attribute to set the chip as selected by default.
Deletable
Add the deletable attribute to add a delete icon to the right of the chip. Clicking this icon triggers the delete event. Use the delete-icon attribute to specify the Material Icon for the delete icon, or use the delete-icon slot to specify the element for the delete icon.
API
Properties
| Attribute | Property | Reflect | Type | Default |
|---|---|---|---|---|
variant | variant | 'assist' | 'filter' | 'input' | 'suggestion' | 'assist' | |
Defines the chip variant. Possible values:
| ||||
elevated | elevated | boolean | false | |
Adds a shadow to the chip. | ||||
selectable | selectable | boolean | false | |
Makes the chip selectable. | ||||
selected | selected | boolean | false | |
Marks the chip as selected. | ||||
deletable | deletable | boolean | false | |
Makes the chip deletable. If set, a delete icon appears on the right. | ||||
icon | icon | string | - | |
Sets the Material Icons name for the left icon. Alternatively, use | ||||
selected-icon | selectedIcon | string | - | |
Sets the Material Icons name for the left icon when selected. Alternatively, use | ||||
end-icon | endIcon | string | - | |
Sets the Material Icons name for the right icon. Alternatively, use | ||||
delete-icon | deleteIcon | string | - | |
Sets the Material Icons name for the delete icon when deletable. Alternatively, use | ||||
href | href | string | - | |
The URL for the link. When set, the component renders as an | ||||
download | download | string | - | |
Downloads the linked URL. Note: Only available when | ||||
target | target | '_blank' | '_parent' | '_self' | '_top' | - | |
Controls where the linked URL opens. Possible values:
Note: 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: Only available when | ||||
autofocus | autofocus | boolean | false | |
Whether the element is focused when the page loads. | ||||
tabindex | tabIndex | number | - | |
The element's tab order 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 name submitted with form data. Note: Only available when | ||||
value | value | string | '' | |
The button value submitted with form data. Note: Only available when | ||||
type | type | 'submit' | 'reset' | 'button' | 'button' | |
Specifies the button's default action. Default:
Note: Only available when | ||||
form | form | string | - | |
Associates the button with a This lets the button target any form in the document, not just the one it is nested in. 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 how to encode the form data. 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 open the response after form submission. Possible values:
Overrides the Note: Only available when | ||||
validity | ValidityState | - | ||
A | ||||
validationMessage | string | - | ||
The validation message. Returns an empty string when the element is valid. | ||||
Methods
| Name | Parameters | Returns |
|---|---|---|
click | void | |
Simulates a mouse click on the element. | ||
focus |
| void |
Sets focus on the element. An optional object parameter may include a | ||
blur | void | |
Removes focus from the element. | ||
checkValidity | boolean | |
Checks the validity of the form field. If it is invalid, it triggers an | ||
reportValidity | boolean | |
Checks the validity of the form field. If it is invalid, it triggers an | ||
setCustomValidity |
| void |
Sets a custom error message. If the message is non-empty, the field is considered invalid. | ||
Slots
| Name |
|---|
| (default) |
Text. |
icon |
Left icon. |
end-icon |
Right icon. |
selected-icon |
Left icon when selected. |
delete-icon |
Delete icon when deletable. |
CSS Parts
| Name |
|---|
button |
Internal |
label |
Text. |
icon |
Left icon. |
end-icon |
Right icon. |
selected-icon |
Left icon when selected. |
delete-icon |
Delete icon on the right. |
loading |
The |
CSS Custom Properties
| Name |
|---|
--shape-corner |
The corner radius of the component. You can use a specific pixel value, but it is recommended to reference design tokens. |