Improving the Playground TableCellResizer #6766
rissois
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
THE PROBLEM
If you have played around with table resizing in the Lexical Playground, you will notice that resizing the column width can be quite inexact. Oftentimes, the cell boundary will undershoot or overshoot the mouse release point, which can be frustrating.
The reason for this is that under the hood, table cells are initialized to a minimum value (92px) while the tables themselves have a
width: fit-content
. This stretches all the table cells, even though the underlying cell width is only 92px. So whenTableCellResizer
callsupdateColumnWidth
, it is applying the raw distance value (widthChange
) frommousedown
tomouseup
on the hidden, unstretched set values of column width. The scales are completely different.THE FALSE SOLUTION
The solution seems a simple matter of scaling the
widthChange
relative to the set values of column width. Unfortunately, this is not the complete solution for a number of reasons:[100, 100, 100]
, and we drag the middle column 50px to the right, we'd expect to see something like[100, 150, 50]
with our new boundary at5/6
the width of our table. Instead, the wayTableCellResizer
is written we get[100, 150, 100]
, which places the new boundary at5/7
, and shrinks the first two cells.THE SOLUTION
The below solution allows for more precise adjustments when the total cell width is smaller than the table width. All "downstream" cells are proportionally reduced in size while respecting the minimum width.
I did not create a PR as the code is still a little imprecise and untested, but I hope this is helpful to someone, Please feel free to offer any advice or corrections. Personally, I think the best solution is actually to limit the drag feature up to the adjacent cell boundary, but that's a different project.
Beta Was this translation helpful? Give feedback.
All reactions