Skip to content

Export a selection hook for content inside Table (useTableSelection) #22

Closed

Description

@n4ff4h

From: javaabu/bulk-actions (Javaabu/bulk-actions#6, #10)

Table keeps the row selection in a private TableContext (selected, the registered row ids, toggle). Packages that put content in bulkForm (bulk-actions' action bar) can't read it, so they can't show "3 selected" or "All 20 on this page are selected — select all 1,234?" without reading the DOM.

Asked for: export a hook for content rendered inside Table, e.g.

export function useTableSelection(): {
  model: string
  selected: ReadonlySet<string>   // checked row ids
  rows: ReadonlySet<string>       // registered, enabled row ids
  setSelected: (ids: Iterable<string>) => void   // e.g. clear after "all matching" is cancelled
} | null

Why: the bulk-actions bar (@javaabu/bulk-actions' BulkActionsBar, rendered in bulkForm) shows the selected count and offers "select all matching" when every row on the page is checked.

Not blocking: bulk-actions currently counts with new FormData(form).getAll("articles[]") on change/click events of the surrounding form, which works with the HTML and Onu adapters. With the hook it would switch to it.

Activity

  1. added
    next-genNext-gen Javaabu packages
    cross-packageRequested by or affecting another next-gen package
    on Nov 4, 2026
  2. n4ff4h commented on Nov 5, 2026

    @n4ff4h
    CollaboratorAuthor

    Done in 204e616 on next-gen (PR #19), CI green: https://github.com/Javaabu/react-forms/actions/runs/42055926515

    useTableSelection(): TableSelection | null is exported from @javaabu/forms, with the shape you asked for: { model, selected, rows, setSelected }. selected and rows are ReadonlySet<string>, rows holds the registered rows with an enabled checkbox, and setSelected(ids) replaces the selection. Outside a Table it returns null.

    bulkForm content was rendered outside the table's context before this change, so the context provider now wraps the whole table, including bulkForm, beforeTable and pagination. Covered by a test in src/components/listing.test.tsx and documented in docs/basic-usage/listing.md#reading-the-selection and the Boost skill's listing reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cross-packageRequested by or affecting another next-gen packagenext-genNext-gen Javaabu packages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions