A list with an edit mode for selecting multiple rows and acting on them from a floating toolbar.
Selection List is an open-source interaction from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
import { CaretRightIcon } from "@phosphor-icons/react"import * as React from "react"import { SelectionList, SelectionListBar, SelectionListCount, SelectionListItem, SelectionListTrigger, useSelectionList,} from "@/components/interactions/selection-list"import { Button } from "@/components/ui/button"const initialNotes = [ { id: "groceries", title: "Groceries", preview: "Milk, eggs, bread, coffee" }, { id: "trip", title: "Trip ideas", preview: "Lisbon, Porto, the coast road" }, { id: "books", title: "Book list", preview: "Three novels for the summer" },
SelectionList recreates the iOS Select mode for lists. Pressing SelectionListTrigger switches into editing: each SelectionListItem slides in a round checkmark indicator and becomes a checkbox, and SelectionListBar rises from the bottom of the screen as a floating toolbar. The row content is made inert while editing, so taps toggle selection instead of opening the row. Leaving editing clears the selection.
The trigger is a suiss/ui Button that reads Select or Done by default, and SelectionListCount shows how many rows are selected. Use it for lists where people manage several items at once, such as deleting notes or archiving mail.
A controlled selection, through value and onValueChange, drives icon-only toolbar actions that stay disabled until a row is picked.
import { ArchiveIcon, CaretRightIcon, FolderSimpleIcon, TrashIcon,} from "@phosphor-icons/react"import * as React from "react"import { SelectionList, SelectionListBar, SelectionListCount, SelectionListItem, SelectionListTrigger,} from "@/components/interactions/selection-list"import { Button } from "@/components/ui/button"
Accessibility
SelectionListTrigger sets aria-pressed while editing.
In editing mode, each row has role="checkbox" with aria-checked, is focusable, and toggles with Enter or Space. Its accessible name comes from the row's text unless you set aria-label.
SelectionListBar has role="toolbar" and is inert while not editing; give it an aria-label.
SelectionListCount is a polite live region, so selection changes are announced.
Escape leaves editing.
API Reference
SelectionList
The root that holds the editing state and the selected values.
Prop
Type
Default
editing
boolean
-
defaultEditing
boolean
false
onEditingChange
(editing: boolean) => void
-
value
string[]
-
defaultValue
string[]
[]
onValueChange
(value: string[]) => void
-
Also accepts the props of React.ComponentProps<"div">.
Place SelectionListTrigger, the SelectionListItem rows and SelectionListBar inside SelectionList. Editing and selection are each uncontrolled by default; pass editing and onEditingChange, or value and onValueChange, to control them. onValueChange is called with the new array of selected values. useSelectionList returns editing, setEditing, selected, setSelected, selectAll and clear for building actions such as Select All or Delete.
The root sets data-editing while editing, available to children as the group/selection-list Tailwind group. Each part sets a data-slot, such as selection-list-item, for styling.
SelectionListTrigger
The button that enters and leaves editing.
Also accepts the props of React.ComponentProps<typeof Button>.
SelectionListItem
A row that becomes a selectable checkbox while editing.
Prop
Type
Default
value
string
Required
Also accepts the props of React.ComponentProps<"div">.
Give each row a unique value that identifies it in the selection. Shift-clicking a row, or pressing Shift with Enter or Space, selects the range from the previously toggled row. Rows expose data-value and data-checked.
SelectionListBar
The floating toolbar shown while editing.
Also accepts the props of React.ComponentProps<"div">.
Put your own action buttons and SelectionListCount inside the bar. The bar is fixed to the bottom of the viewport, so leave room below the list for it.
SelectionListCount
A live label with the number of selected rows.
Also accepts the props of React.ComponentProps<"span">.
Web
Web preview
import { CaretRightIcon } from "phosphor-react-native"import * as React from "react"import { Pressable, View } from "react-native"import { SelectionList, SelectionListBar, SelectionListCount, SelectionListItem, SelectionListTrigger,} from "@/components/interactions/selection-list"import { Button } from "@/components/ui/button"import { Icon } from "@/components/ui/icon"import { Text } from "@/components/ui/text"const initialNotes = [ { id: "groceries", title: "Groceries", preview: "Milk, eggs, bread, coffee" },
This code uses Tailwind classes that need Uniwind or NativeWind. With StyleSheet, pass the same values through the style props.
import PhosphorSwiftimport SwiftUIstruct SelectionListNote: Identifiable { let id: String let title: String let preview: String}@MainActor let selectionListInitialNotes = [ SelectionListNote(id: "groceries", title: "Groceries", preview: "Milk, eggs, bread, coffee"), SelectionListNote(id: "trip", title: "Trip ideas", preview: "Lisbon, Porto, the coast road"), SelectionListNote(id: "books", title: "Book list", preview: "Three novels for the summer"), SelectionListNote(id: "meeting", title: "Meeting notes", preview: "Ship the beta on Friday"), SelectionListNote(id: "gifts", title: "Gift ideas", preview: "Headphones, a plant, a scarf"), SelectionListNote(id: "recipes", title: "Recipes", preview: "Lemon pasta and a quick curry"),
SelectionList switches a list between normal and editing modes. In editing mode each SelectionListItem slides in a check circle at its start, the whole row toggles on press, and selected rows are highlighted.
SelectionListBar floats above the bottom safe area while editing, sliding up into view, for actions such as delete or move. Leaving editing mode clears the selection. Use it for mail, notes or photo lists that need bulk actions.
On Android the hardware back button also leaves editing mode.
import * as React from "react"
import { HapticsContext } from "./haptics"
const DEFAULT_PORTAL_HOST = "INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME"
type PortalEntries = ReadonlyMap<string, React.ReactNode>
const EMPTY_ENTRIES: PortalEntries = new Map()
let hosts: ReadonlyMap<string, PortalEntries> = new Map()
const listeners = new Set<() => void>()
function emit() {
for (const listener of listeners) listener()
}
Copy and paste the following code into components/interactions/selection-list.tsx:
import { cn } from "cn"import { CheckIcon } from "phosphor-react-native"import * as React from "react"import { Pressable, View, type ViewProps } from "react-native"import { Easing, Keyframe, ReduceMotion, useAnimatedStyle, withTiming,} from "react-native-reanimated"import { useSafeAreaInsets } from "react-native-safe-area-context"import { useBackHandler } from "@/components/primitives/hooks"import { Portal } from "@/components/primitives/portal"import { AnimatedView } from "@/components/ui/animated-view"import { Button } from "@/components/ui/button"
Update the import paths to match your project setup.
import * as React from "react"
import { HapticsContext } from "./haptics"
const DEFAULT_PORTAL_HOST = "INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME"
type PortalEntries = ReadonlyMap<string, React.ReactNode>
const EMPTY_ENTRIES: PortalEntries = new Map()
let hosts: ReadonlyMap<string, PortalEntries> = new Map()
const listeners = new Set<() => void>()
function emit() {
for (const listener of listeners) listener()
}
Copy and paste the following code into components/interactions/selection-list.tsx:
import { cn } from "cn"import { CheckIcon } from "phosphor-react-native"import * as React from "react"import { Pressable, View, type ViewProps } from "react-native"import { Easing, Keyframe, ReduceMotion, useAnimatedStyle, withTiming,} from "react-native-reanimated"import { useSafeAreaInsets } from "react-native-safe-area-context"import { useBackHandler } from "@/components/primitives/hooks"import { Portal } from "@/components/primitives/portal"import { AnimatedView } from "@/components/ui/animated-view"import { Button } from "@/components/ui/button"
Update the import paths to match your project setup.
import * as React from "react"
import { HapticsContext } from "./haptics"
const DEFAULT_PORTAL_HOST = "INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME"
type PortalEntries = ReadonlyMap<string, React.ReactNode>
const EMPTY_ENTRIES: PortalEntries = new Map()
let hosts: ReadonlyMap<string, PortalEntries> = new Map()
const listeners = new Set<() => void>()
function emit() {
for (const listener of listeners) listener()
}
Copy and paste the following code into components/interactions/selection-list.tsx:
import { CheckIcon } from "phosphor-react-native"import * as React from "react"import { Pressable, StyleSheet, View, type ViewProps } from "react-native"import { Easing, Keyframe, ReduceMotion, useAnimatedStyle, withTiming,} from "react-native-reanimated"import { useSafeAreaInsets } from "react-native-safe-area-context"import { useBackHandler } from "@/components/primitives/hooks"import { Portal } from "@/components/primitives/portal"import { AnimatedView } from "@/components/ui/animated-view"import { Button } from "@/components/ui/button"import { Icon } from "@/components/ui/icon"
Update the import paths to match your project setup.
import CoreTextimport SwiftUIimport UIKitstruct RGBA: Sendable { let red: CGFloat let green: CGFloat let blue: CGFloat let alpha: CGFloat init(_ hex: UInt32, _ alpha: CGFloat = 1) { red = CGFloat((hex >> 16) & 0xFF) / 255 green = CGFloat((hex >> 8) & 0xFF) / 255 blue = CGFloat(hex & 0xFF) / 255 self.alpha = alpha }
swift/Theme/Tokens.swift
import SwiftUIpublic enum EsuissColor { public static let background = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x000000)) public static let foreground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7)) public static let card = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F)) public static let cardForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7)) public static let popover = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F)) public static let popoverForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7)) public static let primary = Color.adaptive(light: .init(0x0071E3), dark: .init(0x0A84FF)) public static let primaryForeground = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0xFFFFFF)) public static let secondary = Color.adaptive(light: .init(0x000000, 0.04), dark: .init(0xFFFFFF, 0.1)) public static let secondaryForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7)) public static let muted = Color.adaptive(light: .init(0xF5F5F7), dark: .init(0x161617)) public static let mutedForeground = Color.adaptive(light: .init(0x6E6E73), dark: .init(0x86868B)) public static let accent = Color.adaptive(light: .init(0x000000, 0.06), dark: .init(0xFFFFFF, 0.1))
Copy the source and every file it uses:
swift/Interactions/SelectionList.swift
import PhosphorSwiftimport SwiftUIstruct SelectionModel<Value: Hashable> { var editing = false var selected: Set<Value> = [] var order: [Value] = [] mutating func toggle(_ value: Value) { if selected.contains(value) { selected.remove(value) } else { selected.insert(value) } }
swift/Components/Button.swift
import SwiftUIpublic struct VariantButtonStyle: ButtonStyle { public enum Variant: CaseIterable, Sendable { case `default`, outline, secondary, tinted, ghost, plain, destructive, link } public enum Size: CaseIterable, Sendable { case `default`, xs, sm, lg, xl, form, icon, iconXs, iconSm, iconLg, iconXl var height: CGFloat { switch self { case .xs, .iconXs: Metrics.Height.buttonXs case .sm, .iconSm: Metrics.Height.buttonSm case .default, .icon: Metrics.Height.button case .lg, .iconLg: Metrics.Height.buttonLg
swift/Components/ButtonGroup.swift
import SwiftUIextension EnvironmentValues { @Entry var buttonGroup: Axis? = nil @Entry var buttonGroupSize: CGSize = .zero}enum ButtonGroupSpace: Hashable { case group}struct ButtonGroupFrame { let bounds: Anchor<CGRect> let outlined: Bool}
Add the files to your app target.
Apply the Compose compiler plugin, enable Compose, set compileSdk to 37 or higher and minSdk to 24 or higher, and add the dependencies:
package com.esuiss.ui.themeimport androidx.compose.runtime.Immutableimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.unit.dp@Immutabledata class Colors( val background: Color, val foreground: Color, val card: Color, val cardForeground: Color, val popover: Color, val popoverForeground: Color, val primary: Color,
While editing, rows have the checkbox role and expose their checked state; otherwise the row wrapper is not focusable and its children are.
The trigger exposes a selected state while editing.
The bar has the toolbar role.
SelectionListCount is a polite live region, reading Select items or n selected by default.
API Reference
SelectionList
The root that holds the editing state and selection.
Prop
Type
Default
editing
boolean
-
defaultEditing
boolean
false
onEditingChange
(editing: boolean) => void
-
value
string[]
-
defaultValue
string[]
EMPTY
onValueChange
(value: string[]) => void
-
Also accepts the props of ViewProps.
Wrap the list in SelectionList. Editing and the selection can be uncontrolled with defaultEditing and defaultValue, or controlled with editing, onEditingChange, value and onValueChange. useSelectionList returns editing, selected, toggle, selectAll and clear for custom actions. Animations respect the system reduce motion setting.
SelectionListTrigger
A plain button that toggles editing.
Also accepts the props of React.ComponentProps<typeof Button>.
It reads Select and Done by default.
SelectionListItem
A row that toggles its value while editing.
Prop
Type
Default
value
string
Required
children
React.ReactNode
-
Also accepts the props of React.ComponentProps<typeof Pressable>.
Give each item a unique value. Outside editing mode, the row's children receive presses as usual.
SelectionListBar
A floating toolbar shown while editing.
Prop
Type
Default
portalHost
string
-
Also accepts the props of ViewProps.
Put your buttons and a SelectionListCount in the bar. portalHost names a portal host to render into. The bar is up to max-w-md wide.
SelectionListCount
Text showing the number of selected items.
Also accepts the props of React.ComponentProps<typeof Text>.
SelectionListProxy
Property
Type
isEditing
Bool
count
Int
total
Int
SelectionListProxy.setEditing
Parameter
Type
Default
_ย value
Bool
-
SelectionListProxy.selectAll
Takes no parameters.
SelectionListProxy.clear
Takes no parameters.
SelectionList
The root that holds the editing state and selection.
Parameter
Type
Default
isEditing
Binding<Bool>?
nil
selection
Binding<Set<Value>>?
nil
defaultEditing
Bool
false
defaultSelection
Set<Value>
[]
content
() -> Content
-
SelectionListTrigger
A plain button that toggles editing.
Parameter
Type
Default
label
() -> Label
-
_ย title
LocalizedStringKey
-
Overloads: init(label:), init(), init(_:).
SelectionListItem
A row that toggles its value while editing.
Parameter
Type
Default
value
Value
-
content
() -> Content
-
SelectionListBar
A floating toolbar shown while editing.
Parameter
Type
Default
content
(SelectionListProxy) -> Content
-
SelectionListCount
Text showing the number of selected items.
Parameter
Type
Default
_ย title
LocalizedStringKey
-
Overloads: init(), init(_:).
SelectionListScope
Property
Type
editing
Boolean
selected
List<String>
SelectionListScope.setEditing
Parameter
Type
Default
editing
Boolean
-
SelectionListScope.setSelected
Parameter
Type
Default
selected
List<String>
-
SelectionListScope.toggle
Parameter
Type
Default
value
String
-
SelectionListScope.selectAll
Takes no parameters.
SelectionListScope.clear
Takes no parameters.
SelectionList
The root that holds the editing state and selection.