fix(legend): render Rect shape as SVG for print compatibility#1985
Open
pranay0703 wants to merge 1 commit intoairbnb:masterfrom
Open
fix(legend): render Rect shape as SVG for print compatibility#1985pranay0703 wants to merge 1 commit intoairbnb:masterfrom
pranay0703 wants to merge 1 commit intoairbnb:masterfrom
Conversation
Closes airbnb#1984 The Rect legend shape was rendered as a <div> with a CSS background color. Browsers suppress CSS backgrounds during printing unless the user enables 'Print background colors'. SVG fill attributes are treated as document content and always print. Changed ShapeRect to use <svg><rect fill={fill}> matching the existing Circle and Line shape implementations. Updated LegendThreshold tests to assert on the SVG rect fill attribute instead of the div background style.
mreizvikh
reviewed
Apr 14, 2026
| }; | ||
|
|
||
| export default function ShapeRect({ fill, width, height, style }: ShapeRectProps) { | ||
| const cleanWidth = typeof width === 'string' || typeof width === 'undefined' ? 15 : width; |
There was a problem hiding this comment.
What's the magic number 15 and why it's needed here? Previously we passed width and height directly to the element without a fallback value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1984
The
Rectlegend shape (shape="rect") was implemented as a<div>withbackgroundCSS color. Browsers suppress CSS backgrounds during printing unless the user explicitly enables "Print background colors". SVGfillattributes are treated as document content and always print regardless of this setting.Changes
packages/visx-legend/src/shapes/Rect.tsx— Changed from<div style={{ background: fill }}>to<svg><rect fill={fill}></svg>, consistent with howCircleandLineshapes are already implemented.packages/visx-legend/test/LegendThreshold.test.tsx— Updated assertions to query the<rect>element and check itsfillattribute instead of querying<div>and checkingbackgroundstyle.Before / After
<div style={{ background: fill }}><svg><rect fill={fill}></svg>Testing
All 18 existing tests pass with the updated implementation.