Drawer

A sliding panel that emerges from the edge of the screen to reveal additional content or navigation options..
Installation
API Reference
This is an illustration of Drawer component.
size
anchor
function App() {
const [showDrawer, setShowDrawer] = React.useState(false)
return (
<>
<Button
onPress={() => {
setShowDrawer(true)
}}
>
<ButtonText>Show Drawer</ButtonText>
</Button>
<Drawer
isOpen={showDrawer}
onClose={() => {
setShowDrawer(false)
}}
size="sm"
anchor="left"
>
<DrawerBackdrop />
<DrawerContent>
<DrawerHeader>
<Heading size="3xl">Heading</Heading>
</DrawerHeader>
<DrawerBody>
<Text size="2xl" className="text-typography-800">
This is a sentence.
</Text>
</DrawerBody>
<DrawerFooter>
<Button
onPress={() => {
setShowDrawer(false)
}}
className="flex-1"
>
<ButtonText>Button</ButtonText>
</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
</>
)
}

Installation

Run the following command:

npx gluestack-ui add drawer

API Reference

To use this component in your project, include the following import statement in your file.
import {
Drawer,
DrawerBackdrop,
DrawerContent,
DrawerHeader,
DrawerCloseButton,
DrawerBody,
DrawerFooter,
} from "@/components/ui/drawer"
anatomy-image
export default () => (
<Drawer>
<DrawerBackdrop />
<DrawerContent>
<DrawerHeader>
<DrawerCloseButton></DrawerCloseButton>
</DrawerHeader>
<DrawerBody />
<DrawerFooter />
</DrawerContent>
</Drawer>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

Drawer

Contains all View related layout style props and actions. It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
isOpen
boolean
-
If true, the drawer will open. Useful for controllable state behavior.
onClose
() => any
-
Callback invoked when the drawer is closed.
defaultIsOpen
boolean
-
Specifies the default open state of the Drawer
initialFocusRef
React.RefObject<any>
-
The ref of element to receive focus when the drawer opens.
finalFocusRef
React.RefObject<any>
-
The ref of element to receive focus when the drawer closes
avoidKeyboard
boolean
-
If true, the Drawer will avoid the keyboard.
closeOnOverlayClick
boolean
-
If true, the Drawer will close when the overlay is clicked.
isKeyboardDismissable
boolean
-
If true, the keyboard can dismiss the Drawer
children
any
-
The content to display inside the Drawer

DrawerBackdrop

It is React Native's Pressable component, created using @legendapp/motion's createMotionAnimatedComponent function to add animation to the component. You can use any declarative animation library you prefer.

DrawerContent

It is @legendapp/motion's Motion.View component. You can use any declarative animation library you prefer.
Prop
Type
Default
Description
focusable
boolean
false
If true, Drawer Content will be focusable.

DrawerHeader

It inherits all the properties of React Native's View component.

DrawerCloseButton

It inherits all the properties of React Native's View component.

DrawerBody

It inherits all the properties of React Native's View component

DrawerFooter

It inherits all the properties of React Native's View component.

Props

Modal component is created using View component from react-native. It extends all the props supported by React Native View, utility props and the props mentioned below.
Name
Value
Default
size
xs | sm | md | lg | full
sm
anchor
left | right | top | bottom
left

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.

Filter

function App() {
const [showDrawer, setShowDrawer] = React.useState(false)
const [categories, setCategories] = React.useState([])
const [brands, setBrands] = React.useState([])
const [colors, setColors] = React.useState([])
return (
<>
<Button
onPress={() => {
setShowDrawer(true)
}}
>
<ButtonText>Show Drawer</ButtonText>
</Button>
<Drawer
isOpen={showDrawer}
onClose={() => {
setShowDrawer(false)
}}
>
<DrawerBackdrop />
<DrawerContent className="px-4 py-3 w-[270px] md:w-[300px]">
<DrawerHeader>
<Heading size="md">FILTERS</Heading>
<Button
variant="link"
size="xs"
onPress={() => {
setCategories([])
setBrands([])
setColors([])
}}
>
<ButtonText>Clear All</ButtonText>
</Button>
</DrawerHeader>
<DrawerBody className="gap-4 mt-0 mb-0">
<VStack className="pl-2 py-3">
<Text className="font-semibold" size="sm">
Categories
</Text>
<Divider className="my-1" />
<CheckboxGroup
value={categories}
onChange={(keys) => {
setCategories(keys)
}}
>
<VStack className="gap-3 mt-3 ml-1">
<HStack className="items-center gap-1">
<Checkbox value="tops" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Tops</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(143,234)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="bottoms" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Bottoms</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(5,431,234)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="shoes" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Shoes</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(98,234)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="accessories" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Accessories</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(91,234)
</Text>
</HStack>
</VStack>
</CheckboxGroup>
</VStack>
<VStack className="pl-2 py-3">
<Text className="font-semibold">Brands</Text>
<Divider className="my-1" />
<CheckboxGroup
value={brands}
onChange={(keys) => {
setBrands(keys)
}}
>
<VStack className="gap-3 mt-3 ml-1">
<HStack className="items-center gap-1">
<Checkbox value="tops" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Allen Solly</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(1,234)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="bottoms" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Adidas</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(524)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="shoes" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Nike</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(931)
</Text>
</HStack>
<HStack className="items-center gap-1">
<Checkbox value="accessories" size="sm">
<CheckboxIndicator>
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>Marks & Spencer</CheckboxLabel>
</Checkbox>
<Text className="text-typography-500" size="xs">
(1,241)
</Text>
</HStack>
</VStack>
</CheckboxGroup>
</VStack>
<VStack className="pl-2 py-3">
<Text className="font-semibold">Price Range</Text>
<Divider className="my-1" />
<VStack className="pt-6 pr-4 ml-1">
<Slider
defaultValue={2000}
size="sm"
orientation="horizontal"