nadbm / react-datasheet

Excel-like data grid (table) component for React
https://nadbm.github.io/react-datasheet/
MIT License
5.4k stars 455 forks source link

Cell width quirks #149

Open Vassi opened 5 years ago

Vassi commented 5 years ago

There's easy ways to control column width uniformly but it'd be nice to have a feature on the Cell for it to preserve its width when in edit mode. Because of browser quirks with how inputs are treated vs spans (which can easily size to their content width) even setting the input to 100% doesn't quite get your cell to look the same in edit mode and in input mode.

Again, to be clear, I'd like to be able to easily avoid the width juking between going into edit mode and input mode, like when you have no-wrap mode on.

My idea would be to have the Cell check it's width just before going into edit mode and set it manually, via style, and then remove it when out of edit mode. That would let the input, which is 100%, size appropriately. (or some other solution).

nbd if it's too small potatoes, we can do our own cell renderer afterall, but it would be a nice to have.

annjawn commented 5 years ago

This might help with maintaining the cell's width in edit mode.

.data-grid-container .data-grid .cell .value-viewer ,
.data-grid-container .data-grid .cell .data-editor{
   display: block;
   box-sizing: content-box;
   width: inherit;
 }
rayventerprise commented 3 years ago

Setting to context-box didnt help, hope this helps anyone else; this is what I did.

Using TailwindCSS, you can use normal CSS however.

.data-grid-container .data-grid .cell > input {
    @apply w-full h-full top-0 text-center absolute border-none;
}

.data-grid-container .data-grid .cell.selected {
    @apply relative
}