Overview
NSFloatingActionButton is a specialized button component that renders as a portal to the document body, floating above all other content. It’s positioned at the bottom of the viewport and can be placed on the left, middle, or right side.
Key Features
Portal Rendering
Renders outside the normal component hierarchy using React portals
Flexible Positioning
Position on left, middle, or right side of the viewport
Fixed Placement
Stays visible at the bottom while scrolling
Custom Content
Accepts any React component as children
Import
Basic Usage
Props
The element to be rendered as the floating button. Typically an
NSIconButton or custom button component.The horizontal position of the floating button at the bottom of the viewport.
'left': Positioned on the left side'mid': Centered horizontally'right': Positioned on the right side
Function called when the floating button is clicked. Receives a ref to the floating button element, which is useful for positioning popovers or menus relative to the button.
The offset of the floating button from the side boundaries (left or right edge of the viewport).
The offset of the floating button from the bottom boundary of the viewport.
Additional CSS class names to apply to the floating button container.
Examples
Three Position Options
Custom Offsets
With Menu
Custom Styled Button
Multiple FABs
Animated FAB
Behavior
The component uses
ReactDOM.createPortal to render the button as a direct child of document.body. This ensures it appears above all other content and is not affected by parent component positioning or overflow settings.The
onClick callback receives a ref to the floating button element. This is particularly useful when you need to position a popover or menu relative to the button, as shown in the examples with NSPopOver.Positioning Details
- Fixed positioning: The button uses
position: fixedin CSS - Z-index: Rendered at a high z-index to appear above other content
- Bottom alignment: Always positioned relative to the bottom of the viewport
- Horizontal alignment: Controlled by the
positionpropleft:left: {sideOffset}mid: Centered using transformright:right: {sideOffset}
Use Cases
Primary Actions
Primary Actions
Use for the most important action on a page, such as creating a new item, composing a message, or starting a new task.
Quick Access Menus
Quick Access Menus
Chat or Support
Chat or Support
Provide quick access to chat or support features:
Scroll to Top
Scroll to Top
Create a scroll-to-top button for long pages:
Best Practices
Do:
- Use for primary or frequently used actions
- Keep the button visible and accessible at all times
- Use clear, recognizable icons
- Provide appropriate spacing from screen edges
- Consider mobile viewport sizes when setting offsets
Accessibility
- Ensure the child button element has appropriate ARIA labels
- Use
NSIconButtonwhich includes proper accessibility attributes - Provide sufficient contrast for the button and icon
- Ensure the button is keyboard accessible
- Consider adding a tooltip for clarity
Mobile Considerations
On mobile devices, ensure the FAB doesn’t interfere with native navigation elements or important content. Consider using larger offsets on smaller screens: