Skip to content

Commit

Permalink
fix: set width on all cells
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanmylee authored and Bryan Lee committed Jul 2, 2022
1 parent b1e7a4f commit ba42a67
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/lib/plugins/addResizedColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export type ResizedColumnsAttributeSet = NewTableAttributeSet<{
'box-sizing': 'border-box';
};
};
'tbody.tr.td': {
style?: {
width: string;
'min-width': string;
'max-width': string;
'box-sizing': 'border-box';
};
};
}>;

const getDragXPos = (event: Event): number => {
Expand Down Expand Up @@ -180,7 +188,7 @@ export const addResizedColumns =
window.removeEventListener('touchend', dragEnd);
}
};
const action = (node: Element) => {
const $props = (node: Element) => {
nodeForId[cell.id] = node;
if (cell instanceof FlatHeaderCell) {
columnWidths.update(($columnWidths) => ({
Expand All @@ -194,7 +202,7 @@ export const addResizedColumns =
},
};
};
action.drag = (node: Element) => {
$props.drag = (node: Element) => {
node.addEventListener('mousedown', dragStart);
node.addEventListener('touchstart', dragStart);
return {
Expand All @@ -204,12 +212,15 @@ export const addResizedColumns =
},
};
};
action.disabled = isCellDisabled(cell, disabledResizeIds);
$props.disabled = isCellDisabled(cell, disabledResizeIds);
const props = derived([], () => {
return action;
return $props;
});
const attrs = derived(columnWidths, ($columnWidths) => {
const width = $columnWidths[cell.id];
const width =
cell instanceof GroupHeaderCell
? sum(cell.ids.map((id) => $columnWidths[id]))
: $columnWidths[cell.id];
if (width === undefined) {
return {};
}
Expand All @@ -225,6 +236,24 @@ export const addResizedColumns =
});
return { props, attrs };
},
'tbody.tr.td': (cell) => {
const attrs = derived(columnWidths, ($columnWidths) => {
const width = $columnWidths[cell.id];
if (width === undefined) {
return {};
}
const widthPx = `${width}px`;
return {
style: {
width: widthPx,
'min-width': widthPx,
'max-width': widthPx,
'box-sizing': 'border-box' as const,
},
};
});
return { attrs };
},
},
};
};

0 comments on commit ba42a67

Please sign in to comment.