Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions packages/visx-legend/src/shapes/Rect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ export type ShapeRectProps = {
};

export default function ShapeRect({ fill, width, height, style }: ShapeRectProps) {
const cleanWidth = typeof width === 'string' || typeof width === 'undefined' ? 15 : width;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

const cleanHeight = typeof height === 'string' || typeof height === 'undefined' ? 15 : height;
return (
<div
style={{
width,
height,
background: fill,
...style,
}}
/>
<svg width={cleanWidth} height={cleanHeight}>
<rect width={cleanWidth} height={cleanHeight} fill={fill} style={style} />
</svg>
);
}
12 changes: 9 additions & 3 deletions packages/visx-legend/test/LegendThreshold.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ describe('<LegendThreshold />', () => {
range.forEach((color, index) => {
const legendItem = thresholdLegend[index];
const legendShape = legendItem?.querySelector('.visx-legend-shape');
expect(legendShape?.querySelector('div')).toHaveStyle(`background: ${color}`);
const rectEl = legendShape?.querySelector('rect');
expect(rectEl).not.toBeNull();
expect(rectEl).toHaveAttribute('fill', color);
});
});

Expand All @@ -55,7 +57,9 @@ describe('<LegendThreshold />', () => {
range.forEach((color, index) => {
const legendItem = thresholdLegend[index];
const legendShape = legendItem?.querySelector('.visx-legend-shape');
expect(legendShape?.querySelector('div')).toHaveStyle(`background: ${color}`);
const rectEl = legendShape?.querySelector('rect');
expect(rectEl).not.toBeNull();
expect(rectEl).toHaveAttribute('fill', color);
});
});

Expand All @@ -78,7 +82,9 @@ describe('<LegendThreshold />', () => {
range.forEach((color, index) => {
const legendItem = thresholdLegend[index];
const legendShape = legendItem?.querySelector('.visx-legend-shape');
expect(legendShape?.querySelector('div')).toHaveStyle(`background: ${color}`);
const rectEl = legendShape?.querySelector('rect');
expect(rectEl).not.toBeNull();
expect(rectEl).toHaveAttribute('fill', color);
});
});
});