Skip to content

Sidebar

The column beside the chat — conversations, a new-chat button, a search field, an account row — that folds away and becomes a drawer on a narrow window.

  • <aparte-sidebar>
  • .aparte-sidebar
On this page
Open

<aparte-sidebar> is the column, with the three behaviours a sidebar needs. It folds: collapsed is an attribute you can set, read and save. It becomes a drawer on a narrow window. And its search field filters the list of conversations below it as the reader types, hiding a date group once nothing in it matches.

Its content is yours, in the order you want: a .aparte-sidebar__header, a .aparte-sidebar__search, a .aparte-sidebar__body holding the conversation list, a .aparte-sidebar__footer. The stylesheet lays them out and draws nothing you did not put there. Without the element, <aside class="aparte-sidebar"> is the same look with no behaviour.

Open

Under breakpoint (48rem of window by default, or none for a column that never changes), the sidebar slides over the page. Open, it dims the page behind a scrim, moves the focus inside, closes on Escape or a click outside, and gives the focus back to the button that opened it.

html
<aparte-sidebar collapsed=""></aparte-sidebar>
js
el.addEventListener('aparte-sidebar-toggle', (e) => use(e.detail));

Installation and the framework-specific traps: React · Vue · Svelte · Angular.

Any element carrying data-aparte-sidebar-toggle toggles the nearest sidebar, or the one whose id the attribute names, so a button in the header needs no script. aparte-sidebar-toggle fires on every change, whoever caused it. The search field is any input with data-aparte-sidebar-search; it filters by title, on the rows the list already has.

VariableWhat it sets
--aparte-sidebar-widthThe column’s width, and the drawer’s (260px).
--aparte-sidebar-insetThe inline inset of its four regions.
--aparte-sidebar-bgIts background.

<aparte-sidebar> · class AparteSidebar

Attributes

AttributeDescription
collapsedHidden (in the flow) or closed (as a drawer). Reflected; set it to start closed.
breakpointThe window width under which the sidebar becomes a drawer: a length (default 48rem), or none for a column that never does.
data-drawerReflected BY the element while the window is narrower than breakpoint (48rem unless you set it). Read-only.

Properties

PropertyTypeDescription
collapsedbooleanWhether the sidebar is collapsed (hidden in the flow, or closed as a drawer).
drawer (readonly)booleanTrue while the window is under the breakpoint and the sidebar is a drawer.

Methods

MethodDescription
open(opener?: HTMLElement): voidOpen the sidebar. opener is the control to hand the focus back to when it closes.
close(): void
toggle(opener?: HTMLElement): void
filter(query: string): voidHide the conversation rows whose title does not contain query, and the date groups left empty. Case- and accent-insensitive. An empty query shows everything.

Events

EventTypeDescription
aparte-sidebar-toggleCustomEvent<AparteSidebarToggleDetail>The sidebar opened or closed, by a toggle, by Escape, by a click on the scrim or by collapsed being set. Bubbles.

CSS variables

VariableDefaultDescription
--aparte-sidebar-width260pxWidth of the column, and of the drawer.
--aparte-sidebar-insetvar(--aparte-space-3)The inline inset of the four regions (header, search, body, footer): one value, so their content stands on one axis.
--aparte-sidebar-bgvar(--aparte-surface-2)Its ground.

.aparte-sidebar · .aparte-sidebar__body · .aparte-sidebar__brand · .aparte-sidebar__footer · .aparte-sidebar__header · .aparte-sidebar__scrim · .aparte-sidebar__search

  • A closed sidebar, folded or slid away, is inert and aria-hidden: nothing invisible keeps a tab stop.
  • The toggle’s aria-expanded and aria-controls follow the state; the sidebar gives itself an id when it has none.
  • The open drawer takes the focus and gives it back on close.