Skip to content

Commit fda6d02

Browse files
committed
fix: action sizing, component memoization
1 parent db83ea4 commit fda6d02

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

src/components/legend/_legend_item.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ $legendItemVerticalPadding: $echLegendRowGap / 2;
2626
justify-content: center;
2727
align-items: center;
2828
margin-left: $euiSizeXS;
29+
height: 16px;
30+
width: 20px;
2931
}
3032

3133
&__color {

src/components/legend/color.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
import classNames from 'classnames';
21-
import React, { MouseEventHandler, forwardRef } from 'react';
21+
import React, { MouseEventHandler, forwardRef, memo } from 'react';
2222

2323
import { Icon } from '../icons/icon';
2424

@@ -33,8 +33,8 @@ interface ColorProps {
3333
* Color component used by the legend item
3434
* @internal
3535
*/
36-
export const Color = forwardRef<HTMLDivElement, ColorProps>(
37-
({ color, isSeriesHidden = false, hasColorPicker, onClick }, ref) => {
36+
export const Color = memo(
37+
forwardRef<HTMLDivElement, ColorProps>(({ color, isSeriesHidden = false, hasColorPicker, onClick }, ref) => {
3838
if (isSeriesHidden) {
3939
return (
4040
<div className="echLegendItem__color" aria-label="series hidden" title="series hidden">
@@ -60,5 +60,6 @@ export const Color = forwardRef<HTMLDivElement, ColorProps>(
6060
</div>
6161
</div>
6262
);
63-
},
63+
}),
6464
);
65+
Color.displayName = 'Color';

src/specs/settings.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ export interface LegendActionProps {
212212
/**
213213
* Legend action component used to render actions next to legend items
214214
*
215+
* render slot is constrained to 20px x 16px
216+
*
215217
* @public
216218
*/
217219
export type LegendAction = ComponentType<LegendActionProps>;

src/state/selectors/get_legend_size.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,21 @@ export const getLegendSizeSelector = createCachedSelector(
7272
if (!showLegend) {
7373
return { width: 0, height: 0, margin: 0 };
7474
}
75-
const actionPadding = isDefined(legendAction) ? 4 : 0; // euiSizeXS padding between action and label
75+
const actionDimension = isDefined(legendAction) ? 24 : 0; // max width plus margin
7676
const legendItemWidth =
7777
MARKER_WIDTH + MARKER_LEFT_MARGIN + bbox.width + (showLegendDisplayValue ? VALUE_LEFT_MARGIN : 0);
7878
if (isVerticalAxis(legendPosition)) {
7979
const legendItemHeight = bbox.height + VERTICAL_PADDING * 2;
8080
return {
81-
width: Math.floor(Math.min(legendItemWidth + spacingBuffer + actionPadding, verticalWidth)),
81+
width: Math.floor(Math.min(legendItemWidth + spacingBuffer + actionDimension, verticalWidth)),
8282
height: legendItemHeight,
8383
margin,
8484
};
8585
}
8686
const isSingleLine = (parentDimensions.width - 20) / 200 > labels.length;
8787
return {
8888
height: isSingleLine ? bbox.height + 16 : bbox.height * 2 + 24,
89-
width: Math.floor(Math.min(legendItemWidth + spacingBuffer + actionPadding, verticalWidth)),
89+
width: Math.floor(Math.min(legendItemWidth + spacingBuffer + actionDimension, verticalWidth)),
9090
margin,
9191
};
9292
},

0 commit comments

Comments
 (0)