salla-drawer

A side panel that slides in from the left or right edge of the screen, with an optional title, subtitle, icon and footer.

A side panel that slides in from the left or right edge of the screen, with an optional title, subtitle, icon and footer. Use it for content that should open next to the page, such as filters, a cart preview or a form. It is the drawer counterpart of salla-modal. The component moves itself to the end of document.body when it loads. It is hidden until opened.

Open and close it with the open() and close() methods, by setting or removing the visible attribute, or by emitting drawer::open or drawer::close through salla.event with the drawer's id as the argument. If no id is set, it gets the id salla-drawer. The title is read once from the drawer-title attribute when the element is created (there is no property for it). Change it later with setTitle().

Accessibility: the host has role="dialog" and aria-modal="true". Pressing Escape or clicking the backdrop closes it unless is-closable is false. When opened, the first input, textarea or select inside it is focused.

Use it

In HTML or JSX, use the tag <salla-drawer> with the Attribute names below. In React, the wrapper takes the Property names (camelCase).

import { SallaDrawer } from '@salla.sa/twilight-components-react/drawer';

Try it

web-components/salla-drawer

Example

import { SallaDrawer } from '@salla.sa/twilight-components-react/drawer';

export function Example() {
  return (
    <>
      <SallaDrawer id="filters-drawer" drawerTitle="Filters" position="left" width="sm">
        <p>Filter options go here.</p>
        <div slot="footer"><button type="button">Apply</button></div>
      </SallaDrawer>
      <button onClick={() => document.getElementById('filters-drawer').open()}>Open</button>
    </>
  );
}

Properties

PropertyAttributeDescriptionTypeDefault
centeredcenteredCenters the header content (adds the s-drawer-is-center class to the header).booleanfalse
hasSkeletonhas-skeletonOnly used while the drawer is loading: when true the loading state uses the md width (to fit skeleton content in the loading slot), otherwise the narrow xs width.booleanfalse
iconStyleicon-styleShows a header icon: error shows an alert icon, and any other value (success, primary, normal) shows a check icon. The value also adds a style class to the icon. With no value, no icon is shown. Only shown when the drawer has a title or sub-title, and replaced by the icon slot if you provide one."error" | "normal" | "primary" | "success"undefined
isClosableis-closableLets the customer close the drawer with the close button, the backdrop or the Escape key. Set to false for a drawer that can only be closed from code.booleantrue
isLoadingis-loadingShows the loading state (the loading slot, or a spinner) in place of the content. The loading() and stopLoading() methods change this.booleanfalse
noPaddingno-paddingRemoves the padding of the drawer body. Useful for full-bleed content such as images or a list that draws its own spacing.booleanfalse
positionpositionWhich edge of the screen the drawer slides in from: left or right. Note these are physical sides and do not flip in right-to-left pages."left" | "right"'right'
subTitlesub-titleSubtitle text shown under the title. It is inserted as HTML, so only pass trusted content.string''
subTitleFirstsub-title-firstAdds the s-drawer-title-below class to the title. The markup order (title, then subtitle) does not change, so the visual effect depends on the styles that target that class.booleanfalse
visiblevisibleWhether the drawer is open. Setting or removing this attribute opens or closes it, the same as the open() and close() methods.booleanfalse
widthwidthWidth of the drawer: xs, sm, md, lg, xl or full. While the drawer is loading, the width is md when has-skeleton is set, otherwise xs."full" | "lg" | "md" | "sm" | "xl" | "xs"'md'

Events

Listen with addEventListener, or the on prop of the React wrapper (for example onModalBack).

EventDescriptionDetail
drawerVisibilityChangedFires when the drawer opens or closes. event.detail is true when it opens and false when it closes.Boolean

Methods

Call these on the element or a React ref.

close() => Promise<HTMLElement>

Closes the drawer.

Returns Promise<HTMLElement>: A Promise that resolves to the drawer element.

loading() => Promise<HTMLElement>

Shows the loading state, the same as setting is-loading to true.

Returns Promise<HTMLElement>: A Promise that resolves to the drawer element.

open() => Promise<HTMLElement>

Opens the drawer and focuses its first input, textarea or select, if there is one.

Returns Promise<HTMLElement>: A Promise that resolves to the drawer element.

setTitle(drawerTitle: any) => Promise<HTMLElement>

Changes the drawer title. The value is inserted as HTML, so only pass trusted content.

ParameterTypeDescription
drawerTitleanyThe new title text.

Returns Promise<HTMLElement>: A Promise that resolves to the drawer element.

stopLoading() => Promise<HTMLElement>

Hides the loading state and shows the content again.

Returns Promise<HTMLElement>: A Promise that resolves to the drawer element.

Slots

SlotDescription
(default)Main content of the drawer.
footerContent shown at the bottom of the drawer, after the main content.
iconReplaces the header icon. Only rendered when the drawer has a title or sub-title.
loadingContent shown while the drawer is loading (is-loading is true or loading() was called). Defaults to a loading spinner.

Renders: <salla-loading>.

Used inside: <salla-bottom-alert>, <salla-offer>.

On this page