quadratic
quadratic copied to clipboard
Alignment
Fixes #290
This pull request is automatically being deployed by Amplify Hosting (learn more).
Access this pull request here: https://pr-318.de5w5iglj13on.amplifyapp.com
@davidfig
Numbers can not be aligned left (we should default to 'auto' then the user could force one to align left) Strings that start with a number, but are not a number are also aligned right by default. Should only align right when the cell contains only a valid number.
Turns out isNaN for strings is way more complicated than I thought. Here's the best solution based on my research:
// from https://stackoverflow.com/a/58550111
function isStringANumber(s: string): boolean {
return s.trim() !== '' && !isNaN(s as any as number);
}
@davidfig, that makes sense. For consistency, I also replaced the function that decides if a cell.value
is a number in the CellTextFormatter
with the same function. See this commit. https://github.com/quadratichq/quadratic/pull/318/commits/a7b374743c634f57c4e4debeca0de483e99959b1
However, there is still an issue. We need to check if the label is a number before applying the CellTextFormatting, not after. Otherwise, adding something like Currency formatting changes the default alignment. See gif.
@davidfig seeing some odd behavior with formatting jumping around when loading files. It also appears to be a bit of a performance hit when true rendering. When loading the Monte Carlo sim doc it seems to be rendering it a few times, and formatting jumps around (see gif)
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
quadratic | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | May 20, 2023 0:32am |
Ok, I update this PR with the latest from main and resolved merge conflicts. After playing around with it sum, these are my thoughts:
Big takeaway
I personally feel like we should start this feature super conservatively.
What do I mean by that? We provide the controls for alignment in the UI to the user but don't auto-align anything. Everything continues to be left-aligned by default. If the user wants to align something, they now have the controls but otherwise we're not taking a stance and implementing any features around auto-alignment based on cell data types.
Separately, we can file an issue where we track the kinds of things that feel like they should be aligned by default, e.g. cells that are only numbers, cells where the user starts typing $
followed by numbers, etc., which all feels like maybe it relates to the concept of #22 too.
In short, I personally don't think we're quite ready to go any further in the product with alignment other than simply: allow the user to align things how they want.
Small item
Editing a cell doesn't preserve alignment (feels like it should? you can do that with an <input>
can you not)? If nothing else, we should make sure we do this in #454
Conclusion
If we do the two items above, IMO it's ready to be merged.