fix(Table): Make checkbox selection interactive and fix click handling#17
fix(Table): Make checkbox selection interactive and fix click handling#17mattrothenberg wants to merge 5 commits intocloudflare:mainfrom
Conversation
- Add indeterminate prop to Table.CheckHead and Table.CheckCell - Fix checkbox click handling by removing onClick stopPropagation that was interfering with Base UI's internal click handling - Refactor TableSelectedRowDemo and TableFullDemo with proper React state management for interactive row selection - Header checkbox now shows indeterminate state when some rows selected - Regenerate component registry
- Wrap checkbox in span with stopPropagation to prevent double-toggle when clicking directly on the checkbox - Add w-10 (40px) default width to TableCheckCell and TableCheckHead so checkbox columns are properly sized without needing colgroup - Add state management to TableWithCheckboxDemo - Remove redundant colgroup width from TableFullDemo
Add a DropdownMenu to the DotsThree button with View, Edit, and Delete options
Remove hacky span wrapper with stopPropagation. Instead: - Remove cell onClick handler entirely - Use CSS pseudo-element (before:-inset-3) to expand checkbox hit area - Only onCheckedChange handles clicks - no event bubbling issues This is cleaner and matches TanStack Table's approach.
| }} | ||
| aria-label={label ?? "Select row"} | ||
| disabled={disabled} | ||
| className="relative before:absolute before:-inset-3 before:content-['']" |
There was a problem hiding this comment.
CSS trick to make the tap target of the checkbox fill the entire surrounding w-10 div.
While it may seem like you’re passing selection state twice, this is a intentional choice to keep the Table component stateless and presentational. By decoupling the visual highlight from the functional checkbox, we provide developers with full control. Automated syncing (checking the box when the row is "selected") breaks in complex scenarios—specifically when a single row contains multiple independent actions. For example, in a Permissions Matrix, a row shouldn't be "selected" just because one of several capability checkboxes is active: |
Summary
indeterminateprop support toTable.CheckHeadandTable.CheckCellw-10(40px) width to checkbox cellscheck.mov
Problem
The Table component demos at https://kumo-ui.com/components/table/ had non-functional checkboxes:
Solution
Component changes (
table.tsx)indeterminateprop toTable.CheckHeadandTable.CheckCellfor partial selection statew-10default width to checkbox cells for consistent sizingbefore:-inset-3) to expand the checkbox hit area without needing wrapper hacksDemo changes (
TableDemo.tsx)useState<Set<string>>) to all checkbox demosonValueChangehandlers for interactive selectionindeterminatestate to header checkboxesOpen Question
Is the
variant="selected"API onTable.Rowweird? Would a boolean make more sense here?Should we consider:
selectedboolean prop onTable.Row?CheckCellchild?Testing
/components/table/on the docs site