Skip to content

Table selection: add a reusable bulk-actions wrapper #6474

Open

Description

@humbertovirtudes

TL;DR Add a reusable Table bulk-actions wrapper that consumes the same typed selection-state output as useTableSelection. Keep the plugin behaviour-only and keep fixed or floating placement at the product callsite.

Follow-up to #5486 and #5489.

Problem

The fixed and floating recipes in #5489 deliberately keep product chrome outside useTableSelection, but both callsites repeat the same integration work:

  • derive visibility and count from selectedKeys
  • render a named, muted, small Toolbar
  • render the count and Unselect All
  • keep action content aligned with Toolbar semantics

That UI is common enough to consider a component. However, adding it to the selection plugin would mix product chrome with behavioural concerns.

There is also no shared output for a wrapper to consume today. useTableSelectionState returns only selectionConfig; controlled selectedKeys and setSelectedKeys remain separate at the callsite. A wrapper should consume the same public selection-state model as the plugin so the two APIs cannot drift.

Proposed direction

Add a separate wrapper component (working name: TableSelectionToolbar) built on Astryx Toolbar, plus a small public selection-state contract returned by useTableSelectionState.

const {selectionConfig, selectionState} = useTableSelectionState({
  data,
  idKey: 'id',
  selectedKeys,
  setSelectedKeys,
});

const selection = useTableSelection(selectionConfig);

<TableSelectionToolbar
  selection={selectionState}
  startContent={
    <>
      <Button onPress={handleExport}>Export</Button>
      <Button variant="destructive" onPress={handleDelete}>Delete</Button>
    </>
  }
/>
<Table data={data} columns={columns} plugins={{selection}} />

The exact names should be resolved before publishing the API. The important constraint is one typed selection-state object shared by the behavioural integration and the visual wrapper.

Ownership

Layer Owns
useTableSelection Row controls, select-all behaviour, row semantics
Selection-state output Selected keys, selected count, selection presence, clear-selection command
Bulk-actions wrapper Toolbar semantics, default count, clear action, visibility
Product callsite Action content, handlers, copy overrides, fixed or floating placement

Component requirements

  • Build on Toolbar, including its keyboard and size behaviour.
  • Default to label="Bulk actions", variant="muted", and size="sm".
  • Accept product actions as React content, not an action configuration array.
  • Render the selected count and a clear-selection action by default.
  • Hide when no keys are selected.
  • Keep current selected keys available to product action handlers through the shared selection-state object.
  • Allow products to override count and clear labels for localisation and domain language.
  • Work unchanged in both the fixed and floating callsite layouts from feat(core): opt-in bulk-actions toolbar for useTableSelection (#5486) #5489.

Selection-state requirements

The shared public contract should expose at least:

  • selectedKeys: ReadonlySet<string>
  • selectedCount: number
  • hasSelection: boolean
  • clearSelection(): void

clearSelection() must clear the complete controlled selection, including keys retained across filtering or pagination. It is distinct from deselecting only the currently actionable rows through the header checkbox.

Non-goals

  • Injecting UI through useTableSelection or transformScrollWrapper.
  • Owning sticky or floating geometry inside the wrapper.
  • Defining product actions as data objects.
  • Adding cross-page "select all matching" behaviour.
  • Replacing the general-purpose Toolbar component.

Acceptance criteria

  • useTableSelection remains behaviour-only and returns no React chrome.
  • The plugin integration and wrapper consume one public typed selection-state contract.
  • The wrapper uses Toolbar rather than recreating toolbar semantics.
  • Product actions remain slot content owned by the caller.
  • Count, visibility, selected keys, and clear behaviour stay synchronized after row selection, select-all, filtering, and pagination changes.
  • Clearing removes all controlled selected keys.
  • Fixed and floating examples demonstrate the same wrapper without wrapper-owned positioning.
  • Unit tests cover the shared state contract, default rendering, overrides, keyboard semantics, and clear behaviour.
  • Storybook interaction tests and real-browser verification cover both layouts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions