Skip to content

Improves UI issues when rendering a Kino.DataTable#497

Merged
jonatanklosko merged 18 commits intomainfrom
hb-improve-datatable-ui-rendering
Mar 5, 2025
Merged

Improves UI issues when rendering a Kino.DataTable#497
jonatanklosko merged 18 commits intomainfrom
hb-improve-datatable-ui-rendering

Conversation

@hugobarauna
Copy link
Member

Context

When rendering a Kino.Datable, I encountered two issues:

1. Table header does not fit within the width

CleanShot 2025-03-04 at 15 05 01

2. Fonts are applied only after hovering

CleanShot.2025-03-04.at.15.06.02.mp4

This PR resolves problem 1 for Chrome and Firefox.

Before

before.mp4

After

after.mp4

Copy link
Member

@jonatanklosko jonatanklosko left a comment

Choose a reason for hiding this comment

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

Looks good to me, I have a few comments, but I experimented with it and applied the comments already. Let me know if it works as expected for you :)

Comment on lines 34 to 36
fontPreloader.innerHTML =
"<span style=\"font-family:'JetBrains Mono'\">Font preload</span>" +
"<span style=\"font-family:'Inter'\">Font preload</span>";
Copy link
Member

Choose a reason for hiding this comment

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

We need to have a sample text for every font width, otherwise only the width 400 is loaded for each.

Comment on lines 44 to 51
if (document.fonts && document.fonts.ready) {
await Promise.race([
document.fonts.ready,
new Promise((resolve) => setTimeout(resolve, FONT_LOAD_TIMEOUT)),
]);
} else {
await new Promise((resolve) => setTimeout(resolve, FONT_LOAD_TIMEOUT));
}
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't do the timeout.

When document.fonts.ready is available, we should just wait however long it takes, it may very well take a second, and since this is only the first render, it should be fine. Otherwise, we would wait 0.5s and then run into the same issues this solves.

When document.fonts.ready is not available, we would always wait the timeout, even if the fonts are actually cached, so for most renders it would slow things down unnecessarily. Looks like it's well supported anyway.

Comment on lines 8 to 15
<thead>
<tr class="bg-slate-50 h-[1.5rem]">
${createHeaderCell("w-12")}
${createHeaderCell("w-32")}
${createHeaderCell("w-48")}
${createHeaderCell("w-20")}
</tr>
</thead>
Copy link
Member

Choose a reason for hiding this comment

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

I think it's fine to skip the header, the difference from rows is very subtle, and since it's a placeholder it's barely noticeable anyway.

@hugobarauna
Copy link
Member Author

@jonatanklosko I see you already made the suggested changes, thanks!

I tested again with the new changes, and it's working for me in Chrome and Firefox.

Should we merge that?

@jonatanklosko jonatanklosko merged commit 02eeeb7 into main Mar 5, 2025
1 check passed
@jonatanklosko jonatanklosko deleted the hb-improve-datatable-ui-rendering branch March 5, 2025 12:42
@jonatanklosko
Copy link
Member

Thanks!

@hugobarauna
Copy link
Member Author

@jonatanklosko and whenever we can release a new kino, so that users could benefit from that improvement, it would be great.

Also, now that this works for Chrome and Firefox, do you have ideas on how to make it work for Safari?

I tried a few different things but could not make it work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants