Fab
The Floating Action Button (FAB) is a primary action button that gives users quick access to key actions.
Usage
Import the component:
import 'mdui/components/fab.js';
Import the TypeScript type:
import type { Fab } from 'mdui/components/fab.js';
Example:
<mdui-fab icon="edit"></mdui-fab>Extended State
Use extended to show the default slot's text in the extended state.
Shape
Use the variant attribute to set the FAB shape.
Size
Use the size attribute to set the FAB size.
Link
Use the href attribute to turn the FAB into a link. The download, target, and rel attributes are available for link-related functionality.
Disabled and Loading State
Use disabled to disable the FAB. Use loading to show a loading state.
API
Properties
| Attribute | Property | Reflect | Type | Default |
|---|---|---|---|---|
variant | variant | 'primary' | 'surface' | 'secondary' | 'tertiary' | 'primary' | |
Sets the FAB color. Possible values:
| ||||
size | size | 'normal' | 'small' | 'large' | 'normal' | |
Sets the FAB size. Possible values:
| ||||
icon | icon | string | - | |
Sets the Material Icons name. Alternatively, use | ||||
extended | extended | boolean | false | |
Extends the FAB to show text alongside the icon. | ||||
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. | ||
CSS Custom Properties
| Name |
|---|
--shape-corner-small |
The corner radius of the component when |
--shape-corner-normal |
The corner radius of the component when |
--shape-corner-large |
The corner radius of the component when |