Import
import { Drawer } from '@dnb/eufemia'
Description
The Drawer component is a Modal variation that appears as a side panel at any chosen side of the page: top, bottom, left, or right (default right). A Drawer is typically used to show additional information. It can also be used for easy/quick tasks while staying in context.
Relevant links
Parts in Drawer
To provide custom content to parts of the Drawer, a set of component parts are provided:
<Drawer.Navigation>: The navigation field at the top of the component, default with a close button (Equal to the propertynavContent).<Drawer.Header>: The header field of the component, where thetitlewill appear (Equal to the propertyheaderContent).<Drawer.Body>: The body of the Drawer, provided with a section background color, defaultblack-3(Equal to the propertymodalContent).
More detailed information
For more details regarding the component functionality, check out the Modal documentation.
Root Element (React Portal)
The Drawer component uses PortalRoot internally to render its content. See the PortalRoot documentation for information on how to control where the portal content appears in the DOM.
Demos
Basic Drawer
<Drawer title="Drawer title" triggerAttributes={{ text: 'Open drawer', }} > <P top>Some informational content</P> <P top> Elementum eu suspendisse sit platea elit porttitor magna laoreet ad ultrices tempus urna curae parturient conubia quisque viverra eget vestibulum neque pulvinar semper vulputate id dis varius pellentesque nunc egestas risus amet mus aptent luctus imperdiet netus natoque cubilia mattis nostra proin ornare scelerisque sodales faucibus placerat sem bibendum pretium rutrum vitae sociis ligula inceptos morbi quam mi sed pharetra fermentum tortor ullamcorper ipsum tellus eros euismod volutpat nisl dui lectus fames suscipit phasellus praesent justo mollis montes velit taciti gravida </P> </Drawer>
Basic Drawer left placement
<Drawer title="Drawer title" containerPlacement="left"> <P top>Some informational content</P> <P top> Elementum eu suspendisse sit platea elit porttitor magna laoreet ad ultrices tempus urna curae parturient conubia quisque viverra eget vestibulum neque pulvinar semper vulputate id dis varius pellentesque nunc egestas risus amet </P> </Drawer>
Basic Drawer in fullscreen
<Drawer fullscreen title="Drawer title" triggerAttributes={{ text: 'Open drawer', }} > <P top>Some informational content</P> <P top> Elementum eu suspendisse sit platea elit porttitor magna laoreet ad ultrices tempus urna curae parturient conubia quisque viverra eget vestibulum neque pulvinar semper vulputate id dis varius pellentesque nunc egestas risus amet </P> </Drawer>
Drawer with custom content
<Drawer title="Custom title"> <Drawer.Navigation> <Breadcrumb onClick={handleBack} /> </Drawer.Navigation> <Drawer.Header> <P bottom>This is a lorem ipsum dolor</P> <Button bottom size="large"> Lorem ipsum </Button> <Button bottom size="large" variant="secondary"> Dolor sit </Button> <FormStatus state="information"> This is a lorem ipsum dolor </FormStatus> <Tabs id="unique-linked-id" data={[ { title: 'One', key: 'one', }, { title: 'Two', key: 'two', }, ]} /> </Drawer.Header> <Drawer.Body> <Tabs.Content id="unique-linked-id" key="contentKey"> {({ title }) => { return ( <> <H2>{title}</H2> <P top>This is a left aligned Drawer content.</P> <P top> Elementum eu suspendisse sit platea elit porttitor magna laoreet ad ultrices tempus urna curae parturient conubia quisque viverra eget vestibulum neque pulvinar semper vulputate id dis varius pellentesque nunc egestas risus amet mus aptent luctus imperdiet netus natoque cubilia mattis nostra proin ornare scelerisque sodales faucibus placerat sem bibendum pretium rutrum vitae sociis ligula inceptos morbi quam mi sed pharetra fermentum tortor ullamcorper ipsum tellus eros euismod volutpat nisl dui lectus fames suscipit phasellus praesent justo mollis montes velit taciti gravida lacus commodo senectus feugiat lorem etiam consequat penatibus cum hendrerit accumsan orci potenti purus nulla </P> </> ) }} </Tabs.Content> </Drawer.Body> </Drawer>
Customize trigger button
<Drawer title="Drawer with custom trigger" triggerAttributes={{ text: 'Custom trigger', variant: 'primary', size: 'large', icon: 'loupe', iconPosition: 'left', }} > <Drawer.Body innerSpace={{ block: 'large', }} > <P>Opened a Drawer with a custom trigger button!</P> </Drawer.Body> </Drawer>
Close Drawer by callback method
<Drawer title="Drawer title" triggerAttributes={{ text: 'Open drawer', }} hideCloseButton > {/* @ts-expect-error -- strictFunctionTypes */} {({ close }) => ( <> <Button text="Close by callback" onClick={close} /> </> )} </Drawer>
Remove animation and spacing
<Drawer title="No spacing or animation" noAnimation spacing={false} hideCloseButton > <Drawer.Body> <P top bottom> This is a lorem ipsum dolor </P> <Button bottom size="large"> Lorem ipsum </Button> <Button bottom size="large" variant="secondary"> Dolor sit </Button> <FormStatus state="information"> This is a lorem ipsum dolor </FormStatus> </Drawer.Body> </Drawer>