Events in React Floating Action Button
13 Nov 20264 minutes to read
The React Floating Action Button component provides events to respond to user interactions. This section explains the available events, their purposes, and how to handle them in your React application.
created
The created event triggers after the React Floating Action Button component is initialized and ready for interaction. Use this event to perform initialization tasks or access component properties after rendering.
import { FabComponent } from '@syncfusion/ej2-react-buttons';
import * as React from 'react';
function App() {
function onCreate(): void {
// Perform initialization logic after FAB creation
}
return (
{/* To render Floating Action Button */}
<FabComponent id='fab' iconCss='e-icons e-edit' content='Edit' created={onCreate}></FabComponent>
);
}
export default App;onclick
The click event triggers when the React Floating Action Button is clicked by the user. Handle this event to execute actions or trigger workflows when the button is activated through mouse click or keyboard press.
import { FabComponent } from '@syncfusion/ej2-react-buttons';
import * as React from 'react';
function App() {
function onClick(): void {
// Execute action when FAB is clicked
}
return (
{/* To render Floating Action Button */}
<FabComponent id='fab' iconCss='e-icons e-edit' content='Edit' onClick={onClick}></FabComponent>
);
}
export default App;Below example demonstrates the click event of the React Floating Action Button.
import { FabComponent } from '@syncfusion/ej2-react-buttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
function App() {
function onClick() {
alert("Edit is clicked!");
}
return (<div>
<div id="targetElement" style=></div>
{/* To render Floating Action Button */}
<FabComponent id='fab' iconCss='e-icons e-edit' content='Edit' onClick={onClick} target='#targetElement'></FabComponent>
</div>);
}
export default App;
ReactDom.render(<App />, document.getElementById('button'));import { FabComponent } from '@syncfusion/ej2-react-buttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
function App() {
function onClick(): void {
alert("Edit is clicked!");
}
return (
<div>
<div id="targetElement" style=></div>
{/* To render Floating Action Button */}
<FabComponent id='fab' iconCss='e-icons e-edit' content='Edit' onClick={onClick} target='#targetElement'></FabComponent>
</div>
);
}
export default App;
ReactDom.render(<App />, document.getElementById('button'));/* Represents the styles for loader */
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}