SelectionBar
Floats a bulk-action bar with a pluralized selected count, actions, and a clear button over a multi-select list.
- Frameworks
- Astro · React · Elements · Dioxus
- Registry
lumen add SelectionBar- Interaction
- Enhanced runtime
See it and copy it
Framework example
Choose Astro, React, Elements, or Dioxus to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.
View SelectionBar code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. Before copying an example, complete the matching framework setup; React, Elements, and Dioxus use their own behavior APIs.Width controls resize the preview container. Resize your browser to test viewport breakpoints.---
import { Button, Checkbox, Label, SelectionBar, Stack } from '@santi020k/lumen-astro'
const photos = ['Harbor at dawn', 'Market street', 'Summit trail', 'Night ferry']
---
<div id="demo-selection" style="max-block-size: 16rem; overflow: auto; border: 1px solid hsl(var(--line)); border-radius: var(--ui-radius-lg); padding: 0.75rem;">
<Stack gap="related">
{photos.map((photo, index) => (
<Label for={`demo-photo-${index}`}>
<Checkbox checked={index < 2} id={`demo-photo-${index}`} name="photos" value={photo} />
{photo}
</Label>
))}
</Stack>
<SelectionBar
id="demo-selection-bar"
count={2}
clearOnEscape
label={{ one: '{count} photo selected', other: '{count} photos selected' }}
>
<Button size="sm" variant="outline">Download</Button>
<Button size="sm" variant="destructive">Delete</Button>
</SelectionBar>
</div>
<script>
const container = document.getElementById('demo-selection')
const bar = document.getElementById('demo-selection-bar')
const boxes = (): HTMLInputElement[] => Array.from(container?.querySelectorAll<HTMLInputElement>('input[name="photos"]') ?? [])
const update = (): void => {
bar?.setAttribute('data-count', String(boxes().filter(box => box.checked).length))
}
container?.addEventListener('change', update)
bar?.addEventListener('ui:selection-clear', () => {
for (const box of boxes()) box.checked = false
update()
})
</script>'use client'
import { useState } from 'react'
import { Button, Checkbox, Label, SelectionBar, Stack } from '@santi020k/lumen-react'
const photos = ['Harbor at dawn', 'Market street', 'Summit trail', 'Night ferry']
export function Example() {
const [selected, setSelected] = useState<string[]>(photos.slice(0, 2))
return (
<Stack gap="related">
{photos.map((photo, index) => (
<Label htmlFor={`photo-${index}`} key={photo}>
<Checkbox
checked={selected.includes(photo)}
id={`photo-${index}`}
name="photos"
value={photo}
onChange={event => {
const checked = event.currentTarget.checked
setSelected(current => checked ? [...current, photo] : current.filter(value => value !== photo))
}}
/>
{photo}
</Label>
))}
<SelectionBar
clearOnEscape
count={selected.length}
label={{ one: '{count} photo selected', other: '{count} photos selected' }}
onClear={() => setSelected([])}
>
<Button onClick={() => setSelected([])} size="sm" variant="outline">Done selecting</Button>
</SelectionBar>
</Stack>
)
}<script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<lumen-button id="select-photos">Select four photos</lumen-button>
<lumen-selection-bar
clear-on-escape
count="0"
id="photo-selection"
label-one="{count} photo selected"
label-other="{count} photos selected"
>
<lumen-button id="finish-selection" variant="outline">Done selecting</lumen-button>
</lumen-selection-bar>
<script type="module">
const bar = document.getElementById('photo-selection')
const clearSelection = () => bar?.setAttribute('count', '0')
document.getElementById('select-photos')?.addEventListener('click', () => {
bar?.setAttribute('count', '4')
})
document.getElementById('finish-selection')?.addEventListener('click', clearSelection)
bar?.addEventListener('ui:selection-clear', clearSelection)
</script>use dioxus::prelude::*;
use lumen_dioxus::prelude::*;
#[component]
fn Example() -> Element {
let mut selected = use_signal(|| 3_u64);
rsx! {
SelectionBar {
count: selected(),
label: SelectionBarCountLabel::plural("{count} file selected", "{count} files selected"),
on_clear: move |()| selected.set(0),
Button { size: ButtonSize::Sm, "Archive" }
}
}
}Choose your target
Add this component
Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.
pnpm add @santi020k/lumen-astrolumen add SelectionBarpnpm add @santi020k/lumen-reactlumen add SelectionBar --target reactpnpm add @santi020k/lumen-elementslumen add SelectionBar --target elementsAPI reference
Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.
| Attribute | Values | Default | Description |
|---|---|---|---|
| count | number | 0 | Number of selected items. At 0 the bar is hidden with the hidden attribute, so it leaves the accessibility tree. In Astro, update data-count on the root from your script. |
| label | string | { zero?, one?, two?, few?, many?, other } | "{count} selected" | Count text. An object picks the form with Intl.PluralRules for the locale. {count} is the formatted count. Elements use label, label-one, label-other, and so on. |
| children / default slot | actions | - | Bulk actions, usually small Buttons. |
| onClear / clearable | () => void | boolean | - / true | React shows the clear button when onClear is set. Astro and Elements show it unless clearable is false, and dispatch ui:selection-clear. |
| clearOnEscape | boolean | false | Escape inside the bar clears the selection. Elements use clear-on-escape. |
| placement | "container" | "viewport" | "container" | container sticks to the bottom of the nearest scroll container. viewport pins the bar to the screen and reserves its own height in the flow, so place it after the list and the last items scroll clear of it. Both respect the bottom safe-area inset. |
| clearLabel, clearedLabel, regionLabel | string | "Clear selection", "Selection cleared", "Selection actions" | Clear button text, the announcement when the count returns to 0, and the action group name. |
| locale | string | document language | Locale for plural rules and number formatting. |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML attributes | - | Forwards standard attributes to the root element unless the component consumes them. |
Customize SelectionBar
Start with semantic theme tokens and a class on the public component. Keep its accessible name, focus treatment, and interaction state intact.
.product-selection-bar {
--surface: 0 0% 100%;
--ink: 220 20% 15%;
--line: 220 15% 82%;
}Apply product-selection-bar through Astro's class, React's className, or the custom element's class. Verify foreground and background contrast in both schemes.
| Hook | Values | Default | Contract |
|---|---|---|---|
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
Use the documented hooks above and adapter types when targeting component states. Theme guide · Accessibility verification scope
Keyboard interactions
Keyboard behavior provided by the Astro UIPrimitives runtime for this component.
| Key | Action |
|---|---|
| Tab | Move through the actions and the clear button. |
| Escape in the bar | Clear the selection when clearOnEscape is set. |
Runtime events
CustomEvents dispatched by the Astro UIPrimitives runtime for this component.
| Event | Target | Detail | When |
|---|---|---|---|
| ui:selection-clear | SelectionBar root ([data-ui-selection-bar]) | { count: number } | The clear button is pressed, or Escape is pressed inside the bar with clear-on-escape. Clear your selection and set the count to 0. |