feat: support table cell wrapping with truncation tooltip#696
Open
albertodainotti wants to merge 1 commit intoNotionX:masterfrom
Open
feat: support table cell wrapping with truncation tooltip#696albertodainotti wants to merge 1 commit intoNotionX:masterfrom
albertodainotti wants to merge 1 commit intoNotionX:masterfrom
Conversation
Implement Notion-native table cell wrap behavior: - Read table_wrap (view-level) and per-column wrap settings - Add notion-table-cell-nowrap class with higher specificity to override the default pre-wrap style - Add TableCellTooltip component using delegated events and React portal to show full content on hover over truncated cells - Add wrap?: boolean to TableCollectionView type definition The tooltip skips URL cells (they have their own abbreviation display) and uses scrollWidth > clientWidth truncation detection.
|
@albertodainotti is attempting to deploy a commit to the Saasify Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Notion has view-level (
table_wrap) and per-column (wrap) settings that control whether table cells wrap text or truncate to a single line. When wrapping is disabled, Notion shows truncated text with a tooltip on hover revealing the full content.The current
react-notion-ximplementation ignores these settings entirely — all cells always wrap.Solution
1. Read wrap settings from the API
The
table_wrapboolean on the collection view controls the default. Each column intable_propertiescan override it with a per-columnwrapfield. Absence meansfalse(Notion convention).2. Apply CSS class for non-wrapping cells
The compound selector (
.notion-table-cell.notion-table-cell-nowrap) gives sufficient specificity to override the existing.notion-table-cell-text { white-space: pre-wrap }rule without!important.3. Truncation tooltip via React Portal
A
TableCellTooltipcomponent shows the full content on hover — but only when content is actually truncated.Why a React Portal?
Three approaches were evaluated:
data-tooltip+::after)scrollWidth > clientWidthSince
react-notion-xis a general-purpose library, tables can be arbitrarily large — Notion databases commonly have hundreds or thousands of rows, and the "Load more" feature can surface them all:Option B degrades linearly with table size. Option C stays constant.
The portal uses event delegation: a single
mouseenterlistener on the.notion-tablecontainer checks whether the hovered.notion-table-cell-nowrapelement hasscrollWidth > clientWidth. If truncated, it clones the cell'sinnerHTMLinto a portal tooltip positioned above the cell. This is O(1) regardless of table size.Why
createPortalis appropriate hereThe
react-notion-xcodebase currently avoidscreatePortaland favors minimal React state. However:createPortalis idiomatic React. The library already usesuseState,useEffect,useRef, anduseCallback. AddingcreatePortalis a natural extension, not a paradigm shift.Additional behaviors
fix-url-abbreviation)Files Changed
packages/notion-types/src/collection-view.ts(+1) — addwrap?: booleanto table property typepackages/react-notion-x/src/third-party/collection-view-table.tsx(+16 / -2) — wrap logic + tooltip mountpackages/react-notion-x/src/third-party/table-cell-tooltip.tsx(+120, new) — portal tooltip componentpackages/react-notion-x/src/styles.css(+5) — nowrap class