Skip to content

feat(widgets): support resizable columns in Table component#1916

Open
realtushartyagi wants to merge 2 commits into
Karanjot786:mainfrom
realtushartyagi:feat/table-resizable-columns
Open

feat(widgets): support resizable columns in Table component#1916
realtushartyagi wants to merge 2 commits into
Karanjot786:mainfrom
realtushartyagi:feat/table-resizable-columns

Conversation

@realtushartyagi

@realtushartyagi realtushartyagi commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description

This PR implements interactive resizable columns for the Table widget. By passing resizable: true into TableOptions, users can now click and drag on column boundaries in the terminal to dynamically resize columns horizontally in data-heavy CLI applications.

Related Issue

Closes #1719

Which package(s)?

@termuijs/widgets

Type of Change

  • 🐛 Bug fix (type:bug)
  • ✨ Feature (type:feature)
  • 📝 Docs (type:docs)
  • 🧪 Tests (type:testing)
  • ♻️ Refactor (type:refactor)
  • 🎨 Design / UX (type:design)
  • ♿ Accessibility (type:accessibility)
  • ⚡ Performance (type:performance)
  • 🔧 DevOps / CI (type:devops)
  • 🔒 Security (type:security)

Checklist

  • ⭐ You starred the repo. The needs-star check blocks your merge otherwise.
  • Tests pass locally: bun vitest run
  • Build passes: bun run build
  • Typecheck passes: bun run typecheck
  • You read CONTRIBUTING.md.
  • Your PR title follows type: short description.
  • Widget state mutators call markDirty() (if your change affects rendering).
  • No new any types without an inline comment explaining why.
  • No unrelated refactors bundled into this PR.

GSSoC 2026 Participation

  • You are a GSSoC 2026 contributor.
  • Your GSSoC profile: https://gssoc.girlscript.org/profile/f49aa65e-aab2-4e9f-99d6-2174f339ecfe

Screenshots / Recordings (UI changes)

(Optional: Add a screenshot or GIF showing the drag-to-resize behavior here)

Notes for the Reviewer

Added dynamic state tracking for the _columnWidths array. When mousedrag events fire on a column boundary separator, the table immediately adjusts the respective width and re-renders dynamically.

Summary by CodeRabbit

  • New Features
    • Added optional interactive column resizing in tables via a new table option.
    • Users can resize columns by dragging column separators when resizing is enabled.
    • Column widths update dynamically during drag and remain consistent while scrolling.

Copilot AI review requested due to automatic review settings July 1, 2026 07:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added type:feature +10 pts. New feature. area:widgets @termuijs/widgets labels Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 86aabd10-fb83-49de-a20c-8b2cb7a99a93

📥 Commits

Reviewing files that changed from the base of the PR and between 10a9ac9 and 12e2fe8.

📒 Files selected for processing (1)
  • packages/widgets/src/data/Table.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/widgets/src/data/Table.ts

📝 Walkthrough

Walkthrough

Table.ts now supports optional mouse-driven column resizing via TableOptions.resizable, with new drag state, boundary hit-testing, and a cached column-width helper reused by rendering and scroll clamping.

Changes

Resizable Table Columns

Layer / File(s) Summary
Resizable option and state fields
packages/widgets/src/data/Table.ts
Adds resizable?: boolean to TableOptions, imports MouseEvent, and adds _resizable, _columnWidths, _lastWidth, _isDragging, _dragColIndex fields.
Constructor wiring of mouse handler
packages/widgets/src/data/Table.ts
Initializes _resizable from options and conditionally registers the mouse event handler when resizing is enabled.
Mouse-driven resize implementation
packages/widgets/src/data/Table.ts
Implements handleMouse for mousedown/drag/mouseup and _findColumnBoundaryAt for boundary hit-testing, updating column widths and marking the widget dirty.
Cached width computation and render/scroll integration
packages/widgets/src/data/Table.ts
Adds _getColWidths for cached width computation and switches rendering and scroll clamping to use it instead of inline computation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • Karanjot786/TermUI#1384: Both PRs modify packages/widgets/src/data/Table.ts to change interaction logic and rendering behavior.

Suggested labels: level:intermediate

Suggested reviewers: Karanjot786

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: resizable Table columns in the widgets package.
Description check ✅ Passed The PR description includes the required sections and clearly links the change to issue #1719.
Linked Issues check ✅ Passed The changes add resizable Table options, mouse drag handling on boundaries, _columnWidths updates, and markDirty as requested in #1719.
Out of Scope Changes check ✅ Passed The diff stays focused on the Table widget resize feature with no obvious unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/widgets/src/data/Table.ts (1)

424-434: 🎯 Functional Correctness | 🔵 Trivial | ⚖️ Poor tradeoff

Any manual column resize is discarded on the next terminal resize.

Since _lastWidth !== rectWidth triggers a full _computeColumnWidths recompute, any width the user dragged into place is lost the moment the content rect width changes (e.g. terminal resize), even by one column. Consider scaling the cached widths proportionally instead of recomputing from scratch when only the rect width changes (keep the full recompute for column-count changes).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/widgets/src/data/Table.ts` around lines 424 - 434, The _getColWidths
method in Table is overwriting user-resized column widths whenever rectWidth
changes because the _lastWidth check forces a full _computeColumnWidths
recompute. Update the resize path so _columnWidths are proportionally scaled to
the new rect width when only the terminal size changes, while preserving the
existing full recompute behavior for column-count changes or when _columnWidths
is uninitialized; keep the logic localized in _getColWidths and use
_lastWidth/_columnWidths to distinguish these cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/widgets/src/data/Table.ts`:
- Around line 187-211: Fix the drag-resize handling in Table.handleMouse so it
uses the actual MouseEventType values and no longer relies on a nonexistent dx
field. Track the drag start/previous x position locally from event.x when
mousedown begins, compute the width delta from successive drag events, and
update _columnWidths accordingly in the mousedrag/drag path. Also ensure
markDirty() is called when _isDragging and _dragColIndex change on drag
start/end so the table redraws correctly.

---

Nitpick comments:
In `@packages/widgets/src/data/Table.ts`:
- Around line 424-434: The _getColWidths method in Table is overwriting
user-resized column widths whenever rectWidth changes because the _lastWidth
check forces a full _computeColumnWidths recompute. Update the resize path so
_columnWidths are proportionally scaled to the new rect width when only the
terminal size changes, while preserving the existing full recompute behavior for
column-count changes or when _columnWidths is uninitialized; keep the logic
localized in _getColWidths and use _lastWidth/_columnWidths to distinguish these
cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 16bdb986-000b-4250-ab3c-ee1b012387cf

📥 Commits

Reviewing files that changed from the base of the PR and between 85e8d36 and 10a9ac9.

📒 Files selected for processing (1)
  • packages/widgets/src/data/Table.ts

Comment thread packages/widgets/src/data/Table.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:widgets @termuijs/widgets type:feature +10 pts. New feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Support Resizable Columns in Table Component

2 participants