Skip to content

feat: add horizontal scroll option for chart legend#181

Merged
jperals merged 2 commits intocloudscape-design:mainfrom
jsilll:main
Mar 19, 2026
Merged

feat: add horizontal scroll option for chart legend#181
jperals merged 2 commits intocloudscape-design:mainfrom
jsilll:main

Conversation

@jsilll
Copy link
Copy Markdown
Contributor

@jsilll jsilll commented Mar 6, 2026

Adds an enableHorizontalScroll option to LegendOptions that allows legend containers to scroll horizontally instead of truncating long text with ellipsis.

Changes:

  • Added enableHorizontalScroll prop threaded through CoreChartProps.LegendOptionsCoreLegendChartLegend
  • Applied overflow-x: auto on the legend list and overflow: visible on item labels when enabled

Testing

Screenshot 2026-03-06 at 14 48 32 Screenshot 2026-03-06 at 14 48 45

@jsilll jsilll requested a review from a team as a code owner March 6, 2026 14:49
@jsilll jsilll requested review from jperals and removed request for a team March 6, 2026 14:49
-webkit-box-orient: vertical;
}

.list-horizontal-scroll {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are issues with the tooltip:

  • It is misplaced when the labels are very long
  • Very long labels are cut off
  • It moves along when horizontally scrolling
scrollable-legend-horizontal-02-trimmed.mov

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll create a PR in the components repository to allow locking the horizontal position of the tooltip.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it also be an option to prevent the tooltip trigger from scrolling by having the overflowing element be a descendant of the trigger instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll try that

* When set to true, enables horizontal scrolling for legend items with long text.
* By default, long text is truncated with ellipsis.
*/
enableHorizontalScroll?: boolean;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note that you'll have to update the Documenter snapshots.

You can do it by running

npx vitest run --config vite.config.unit.mjs -u src/__tests__/documenter.test.ts

jperals
jperals previously approved these changes Mar 18, 2026
Copy link
Copy Markdown
Member

@jperals jperals left a comment

Choose a reason for hiding this comment

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

Note: the series name in the chart popover is still a problem (it gets truncated, without even a visual indicator of the ellipsis), but this will have to be handled separately as the popover does not live in this package.

Image

}
/>
);
case "legendHorizontalScroll":
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be useful to have actually really long series names in this dev page in order to test this. There could be an option for it, or alternative change the series names when legendHorizontalScroll is true.

@jperals jperals added this pull request to the merge queue Mar 19, 2026
Merged via the queue into cloudscape-design:main with commit 481a071 Mar 19, 2026
42 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants