Fab
23 Sep 20255 minutes to read
The FAB Component (Floating Action Button) is an extension of Button Component that appears in front of all the contents of the page and performs the primary action.
Properties
content string
Defines the text content of the Button element.
<button id="primarybtn"></button> import { Button } from '@syncfusion/ej2-buttons';
let button: Button = new Button({content: 'JasButton'});
button.appendTo('#normalbtn');Defaults to ””
cssClass string
Defines class/multiple classes separated by a space in the Button element. The Button types, styles, and
size can be defined by using
this.
<button id="flatbtn">Flat</button> import { Button } from '@syncfusion/ej2-buttons';
let button = new Button({ cssClass: 'e-flat e-primary' });
button.appendTo('#flatbtn');Defaults to ””
disabled boolean
Specifies a value that indicates whether the Button is disabled or not.
Defaults to false.
enableHtmlSanitizer boolean
Specifies whether to enable the rendering of untrusted HTML values in the Button component.
If ‘enableHtmlSanitizer’ set to true, the component will sanitize any suspected untrusted strings and scripts before rendering them.
Defaults to true
enablePersistence boolean
Enable or disable persisting component’s state between page reloads.
Defaults to false
enableRtl boolean
Enable or disable rendering component in right to left direction.
Defaults to false
iconCss string
Defines class/multiple classes separated by a space for the Button that is used to include an icon.
Buttons can also include font icon and sprite image.
Defaults to ””
iconPosition string|IconPosition
Positions the icon before/after the text content in the Button.
The possible values are:
- Left: The icon will be positioned to the left of the text content.
- Right: The icon will be positioned to the right of the text content.
Defaults to IconPosition.Left
isPrimary boolean
Defines whether to apply primary style for FAB.
Defaults to true
isToggle boolean
Makes the Button toggle, when set to true. When you click it, the state changes from normal to active.
Defaults to false
position string|FabPosition
Defines the position of the FAB relative to target.
The possible values are:
- TopLeft: Positions the FAB at the target’s top left corner.
- TopCenter: Positions the FAB at the target’s top left corner.
- TopRight: Positions the FAB at the target’s top left corner.
- MiddleLeft: Positions the FAB at the target’s top left corner.
- MiddleCenter: Positions the FAB at the target’s top left corner.
- MiddleRight: Positions the FAB at the target’s top left corner.
- BottomLeft: Positions the FAB at the target’s top left corner.
- BottomCenter: Places the FAB on the bottom-center position of the target.
- BottomRight: Positions the FAB at the target’s bottom right corner.
<button id='fab'></button>import { Fab } from '@syncfusion/ej2-buttons';
let fab: Fab = new Fab({
content:'fab',
position:'BottomLeft'
});
fab.appendTo('#fab');Defaults to FabPosition.BottomRight
target string|HTMLElement
Defines the selector that points to an element in which the FAB will be positioned.
By default, FAB is positioned based on viewport of browser.
The target element must have relative position, else FAB will get positioned based on the closest element which has relative position.
Defaults to ’’
visible boolean
Defines whether the fab is visible or hidden.
Defaults to true.
Methods
addEventListener
Adds the handler to the given event listener.
| Parameter | Type | Description |
|---|---|---|
| eventName | string |
A String that specifies the name of the event |
| handler | Function |
Specifies the call to run when the event occurs. |
Returns void
appendTo
Appends the control within the given HTML element
| Parameter | Type | Description |
|---|---|---|
| selector (optional) |
string | HTMLElement
|
Target element where control needs to be appended |
Returns void
attachUnloadEvent
Adding unload event to persist data when enable persistence true
Returns void
click
Click the button element
its native method
Returns void
dataBind
When invoked, applies the pending property changes immediately to the component.
Returns void
destroy
Destroys the FAB instance.
Returns void
detachUnloadEvent
Removing unload event to persist data when enable persistence true
Returns void
focusIn
Sets the focus to Button
its native method
Returns void
getLocalData
Returns the persistence data for component
Returns any
getPersistData
Get the properties to be maintained in the persisted state.
Returns string
getRootElement
Returns the route element of the component
Returns HTMLElement
handleUnload
Handling unload event to persist data when enable persistence true
Returns void
refresh
Applies all the pending property changes and render the component again.
Returns void
refreshPosition
Refreshes the FAB position. You can call this method to re-position FAB when target is resized.
Returns void
removeEventListener
Removes the handler from the given event listener.
| Parameter | Type | Description |
|---|---|---|
| eventName | string |
A String that specifies the name of the event to remove |
| handler | Function |
Specifies the function to remove |
Returns void
Events
created EmitType<Event>
Triggers once the component rendering is completed.