Fab

The Floating Action Button (FAB) is a dynamic button that stays visible and provides access to a primary action throughout the user's journey in the application. It is a powerful UI element that adds a touch of elegance and convenience to the user experience.
Installation
This is an illustration of Fab component.
size
placement
isHovered
isDisabled
isPressed
<Box className="h-[360px] w-80 bg-background-50 rounded-md">
<Fab
size="md"
placement="bottom right"
isHovered={false}
isDisabled={false}
isPressed={false}
>
<FabIcon as={AddIcon} />
<FabLabel>Quick start</FabLabel>
</Fab>
</Box>

Installation

Run the following command:

npx gluestack-ui add fab

API Reference

To use this component in your project, include the following import statement in your file.
import { Fab } from "@gluestack-ui/themed"
export default () => (
<Fab>
<FabLabel />
<FabIcon />
</Fab>
)

Fab

Contains all fab related layout style props and actions. It inherits all the properties of React Native's Pressable component.
Prop
Type
Default
Description
placement
"top left" | "top right" | "bottom left" | "bottom right" | "top center" | "bottom center"
"bottom right"
Placement of the Fab
isHovered
bool
false
To manually set hover to the fab.
isPressed
bool
false
To manually set pressable state to the fab.
isFocused
bool
false
To manually set focused state to the fab.
isDisabled
bool
false
To manually set disable to the fab.

FabLabel

Contains all text related layout style props and actions. It inherits all the properties of React Native's Text component.

FabIcon

Contains all Icon related layout style props and actions. It inherits all the properties of Gluestack Style's AsForwarder component.

Features

  • Keyboard support for actions.
  • Support for hover, focus and active states.
  • Option to add your styles or use the default styles.

Accessibility

We have outlined the various features that ensure the Fab component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards.Adheres to the WAI-ARIA design pattern

Keyboard

  • Tab: Moves focus to the next focusable element.
  • Shift + Tab: Moves focus to the previous focusable element.
  • Enter: Triggers the fab's action.

Screen Reader

  • VoiceOver: When the fab is focused, the screen reader will announce the fab's label and its current state.

Focus Management

  • The onFocus and onBlur props manage focus states and provide visual cues to users. This is especially important for users who rely on keyboard navigation.

Dependencies

The following are the lists of all the libraries and packages the component relies on. This information will help you ensure that your project has all the necessary dependencies installed to use the component.
  • @gluestack-ui/utils
  • @react-native-aria/focus
  • @react-native-aria/interactions

Props

Fab component is created using Pressable component from react-native. It extends all the props supported by React Native Pressable.

Fab

Name
Value
Default
size
sm | md | lg
md
placement
top right | top left | bottom right | bottom left | top center | bottom center
bottom right
Note: These props are exclusively applicable when utilizing the default configuration of gluestack-ui/config. If you are using a custom theme, these props may not be available.

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

FAB with Icon

A Fab component with an icon adds a visually striking and easily recognizable button that triggers a specific action or function within a user interface.
function App() {
const data = [
{
uri: "https://images.unsplash.com/photo-1599566150163-29194dcaad36?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=774&q=80",
name: "Kevin James",
msg: "Hi Rachel, What's up",
},
{
uri: "https://images.unsplash.com/photo-1527980965255-d3b416303d12?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1180&q=80",
name: "Jacob Jones",
msg: "Good Morning!",
},
{
uri: "https://images.unsplash.com/photo-1633332755192-727a05c4013d?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1180&q=80",
name: "Albert Flores",
msg: "Coffee?",
},
]
return (
<Box className="border rounded-lg border-outline-200 p-6 bg-background-200 min-w-[240px] sm:min-w-[360px] md:min-w-[476px]">
<VStack space="md">
{data.map((chatData) => {
return (
<HStack space="sm" className="items-center">
<Avatar size="sm">
<AvatarImage
source={{
uri: chatData.uri,
}}
/>
</Avatar>
<VStack>
<Heading size="xs">{chatData.name}</Heading>
<Text size="xs">{chatData.msg}</Text>
</VStack>
</HStack>
)
})}
</VStack>
<Fab
size="lg"
className="bg-emerald-600 hover:bg-emerald-700 active:bg-emerald-800"
>
{/* EditIcon is imported from 'lucide-react-native' */}