Skip to content

Table selection: range and modifier key selection #143

Closed

Description

@cixzhang

Motivation

The current table selection plugin (useXDSTableSelection) supports individual row toggle and select-all. Real-world table interactions also need range selection (shift-click) and additive selection (ctrl/cmd-click).

Proposed behavior

Shift-click (range select)

  • User clicks row A, then shift-clicks row B
  • All rows between A and B become selected (inclusive)
  • Previous selection is replaced by the range

Ctrl/Cmd-click (additive toggle)

  • User ctrl-clicks (or cmd-click on Mac) a row
  • That row toggles without affecting other selections
  • This is the current default behavior — but should be explicit when modifier is held

Click (no modifier)

  • Selects only the clicked row, deselecting all others
  • This would be a behavior change from current (which toggles)

Select-all checkbox

  • Unchanged — toggles all selectable rows

API changes

The useXDSTableSelection hook config would need:

interface UseXDSTableSelectionConfig<T> {
  // ...existing props
  /** Selection mode. @default "toggle" */
  selectionMode?: "toggle" | "standard";
}
  • toggle (current default): each click toggles that row, no modifier key behavior
  • standard: click = single select, shift = range, ctrl/cmd = additive toggle

Alternatively, the hook could always support modifier keys and let the onSelectItem callback receive modifier state:

onSelectItem: (event: {
  item: T;
  isSelected: boolean;
  shiftKey: boolean;
  metaKey: boolean;  // cmd on Mac, ctrl on Windows
}) => void;

This lets consumers implement their own range logic, keeping the hook simple.

Implementation considerations

  • Need to track the "anchor" row (last clicked without shift) for range selection
  • Range selection needs access to the full data array to determine which rows are between anchor and target
  • The hook may need a data prop or getItemIndex callback for range calculation
  • Keyboard support: Shift+Arrow for extending selection

Depends on

Related

  • WAI-ARIA grid pattern recommends shift/ctrl selection for data grids

Activity

  1. added
    enhancement
    on Feb 18, 2026
  2. added this to the Component set 2 milestone on Feb 20, 2026
  3. cixzhang commented on Mar 26, 2026

    @cixzhang
    ContributorAuthor

    Merged into #719 (Cindy's Components — Table section). Range/modifier key selection tracked there.

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

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions