Wrapping text with CellMeasurer
See original GitHub issueI have the following use of CellMeasurer
:
.item {
border-bottom: 1px solid #eee;
padding: 0.5rem;
box-sizing: border-box;
}
.item-text {
display: inline-block;
vertical-align: top;
white-space: pre-wrap; /* CSS3 */
white-space: -moz-pre-wrap; /* Firefox */
white-space: -pre-wrap; /* Opera <7 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* IE */
}
var cache = new CellMeasurerCache({
defaultHeight: 20,
defaultWidth: 50,
fixedWidth: false
});
<CellMeasurer {...}>
<div className="item" key={key} style={style}>
<small>{datum.timestamp}</small>
<br />
<strong>{datum.author}</strong>: <div className="item-text">{datum.text}</div>
</div>
</CellMeasurer>
The problem with it is when datum.text
is a long sense/word. Then the rest of the text goes outside of the display area. I would like the text to be wrapped in available width of the list and the height to be adjusted to the wrapped text. Thanks in advance.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to get content of Column to wrap in react-virtualized
Check out the Table + CellMeasurer demo page (source here) for an example of a Column with wrapping text. Share.
Read more >Create a Virtualized List with Auto Sizing Cells using react ...
In this lesson we'll use CellMeasurer and CellMeasurerCache to automatically calculate and cache the height of a row.
Read more >Wrap text in a cell - Microsoft Support
Wrap text automatically · In a worksheet, select the cells that you want to format. · On the Home tab, in the Alignment...
Read more >Rendering large lists with React Virtualized - LogRocket Blog
CellMeasurer, to dynamically measure the width and height of the rows, ... The placeholder text will be generated with the library ...
Read more >Wrapping and breaking text - CSS: Cascading Style Sheets
What is overflowing text? In CSS, if you have an unbreakable string such as a very long word, by default it will overflow...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t think this relates quite to the issue you’re facing @skipjack but I was facing a similar problem to OP and found that the issue my text wasn’t wrapping in my
Table
cells was that theColumn
component automatically applieswhite-space: nowrap;
, which was cascading down to my cell element. So in myrenderCell
method I just set that back towhite-space: normal;
and everything magically started working. See here.Might just be talking to myself here at this point, but here’s what I found…
I wasn’t able to make any change to the
CellMeasurer
to fix it trying to measureheight
whilewidth
was still equal toauto
. Every attempt I made at delaying the measurement triggered an infinite loop. However, I was able to fix the issue by firing themeasure
callback in the component’s lifecycle returned bycellRenderer
, i.e.Then, in order to properly handle updates (without an unmount and remount), I had to utilize the
keyMapper
method so the cached sizes would correspond directly to the data without the need for re-measuring. I also had to fireMultiGrid.recomputeGridSize
in myTable
component’scomponentDidUpdate
in order for the keys to be updated and the right values pulled from the cache for thecellRenderer
.@bvaughn I like this library a lot but getting this particular feature (text-wrapping in the
MultiGrid
) to work out of the box definitely isn’t super intuitive. I’m a little strapped for time at the moment, but if you’re open to talking through a fix for theCellMeasurer
, I’d love to figure out a better fix for this in the actual library (which would also close thatTODO
I found in the code). If the examples I’ve shared aren’t enough, I’ll try to throw together webpackbin that demos the problem.As for the need for a
keyMapper
and callingrecomputeGridSize
, I think those are understandable at the consumer level as we can’t know the best mapping without knowledge of the data. The only other thought I’d have is that maybeTable
andColumn
could be re-written as wrappers around theMultiGrid
. It could be written to still support all existing features with added support forfixed
columns/rows and more control over cell width (with horizontal scrolling). This change would take a toll on performance though.