Merge pull request #306 from buster-so/nate/fix-broken-widths-measure

fix broken measure
This commit is contained in:
Nate Kelley 2025-05-09 14:05:36 -06:00 committed by GitHub
commit 62d92c92ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View File

@ -14,7 +14,7 @@ const getCanvasContext = () => {
export const measureTextWidth = memoize(
(text: string | number, font: any = {}) => {
if (!isServer) {
const { fontSize, fontFamily = 'sans-serif', fontWeight, fontStyle, fontVariant } = font;
const { fontSize, fontFamily = 'Roobert_Pro', fontWeight, fontStyle, fontVariant } = font;
const ctx = getCanvasContext();
// @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/font
ctx.font = [fontStyle, fontWeight, fontVariant, `${fontSize || 13.6}px`, fontFamily].join(

View File

@ -34,7 +34,7 @@ const getDefaultColumnWidth = (
const longestString = rows.reduce((acc, curr) => {
const currString = cellFormat(curr[field], field);
if (!currString) return acc;
return acc.length > currString.length ? acc : currString;
return String(acc).length > String(currString).length ? acc : currString;
}, headerString);
const longestWidth = measureTextWidth(longestString).width + OFFSET;
return clamp(longestWidth, MIN_COLUMN_WIDTH, MAX_COLUMN_WIDTH);