Skip to content

Commit 407ba4c

Browse files
committed
Add width measurement to tree cell
1 parent 62f422a commit 407ba4c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/cells/src/cell.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,8 @@ export const CustomCells: React.VFC = () => {
537537
width: 120,
538538
},
539539
{
540+
id: "treeview",
540541
title: "TreeView",
541-
width: 150,
542542
},
543543
{
544544
id: "multiselect",

packages/cells/src/cells/tree-view-cell.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ const renderer: CustomRenderer<TreeViewCell> = {
4343
const overIcon = isOverIcon(posX, posY, depth * depthShift, theme, h);
4444
return overIcon ? onClickOpener(cell) : undefined;
4545
},
46+
measure: (ctx, cell, theme) => {
47+
const { text, depth } = cell.data;
48+
// We add 2 to the depth to give it a bit more space, otherwise it looks cramped.
49+
return ctx.measureText(text).width + theme.cellHorizontalPadding * 2 + (depth + 2) * depthShift;
50+
},
4651
draw: (args, cell) => {
4752
const { ctx, theme, rect, hoverX = 0, hoverY = 0 } = args;
4853
const { x, y, height: h } = rect;

0 commit comments

Comments
 (0)