Skip to content

Feature: Collapse/expand individual file diffs #331

@blimmer

Description

@blimmer

Prerequisites

Proposal

Add a built-in mechanism to programmatically collapse and expand the diff content within a diff component instance. This would allow consumers to hide/show the diff body while keeping the header visible, which is a standard UX pattern in code review tools (GitHub, GitLab, Bitbucket, etc.).

Could we add a collapsed boolean prop on all diff components?

<FileDiff
  collapsed={isCollapsed}
  // ... other props
/>

When collapsed={true}, the diff body (lines/hunks) should be hidden but the header should remain visible.

Motivation and context

Multi-file diff views are more usable when users can collapse/expand files. When reviewing a changeset with many files, users might to collapse files they've already reviewed or that aren't relevant.

I've worked around this today like this:

<FileDiff<DiffComment[]>
  fileDiff={fileDiffMetadata}
  options={{
    enableHoverUtility: !readOnly && !isCollapsed,
    unsafeCSS: isCollapsed ? 'pre[data-diffs] { display: none !important; }' : '/* expanded */',

However, this is bound to the internal implementation. A top-level collapsed flag would be great.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions