Cell Tooltips and Popovers
Display tooltips and expandable content for spreadsheet cells
Enhance your spreadsheet with custom tooltips and expandable cell content. Display additional information, rich media, or interactive components when users hover over or click on cells.
Overview
The spreadsheet provides two main ways to display additional cell content:
Tooltips (
getTooltipContent): Show hover tooltips with custom contentExpandable Content (
getCellExpandContent): Display rich content in a popover when cells are expanded
Cell Tooltips
Display custom tooltips when users hover over cells using the getTooltipContent callback.
Basic Usage
import { SpreadsheetProvider, CanvasGrid } from "@rowsncolumns/spreadsheet";
function SpreadsheetWithTooltips() {
const getTooltipContent = (
sheetId: number,
rowIndex: number,
columnIndex: number
) => {
// Return undefined for no tooltip
if (rowIndex === 0 || columnIndex === 0) {
return undefined;
}
// Return JSX for custom tooltip
return (
<div className="p-2">
<strong>Cell:</strong> {cellToAddress({ rowIndex, columnIndex })}
<br />
<strong>Sheet:</strong> {sheetId}
</div>
);
};
return (
<SpreadsheetProvider>
<CanvasGrid
sheetId={1}
getTooltipContent={getTooltipContent}
// ... other props
/>
</SpreadsheetProvider>
);
}Function Signature
Return Values
React.ReactNode: Display tooltip with custom content
undefined: No tooltip for this cell
Examples
Display Cell Metadata
Show Validation Rules
Display Error Messages
Expandable Cell Content
Display rich, interactive content when users expand cells using the getCellExpandContent callback.
Basic Usage
Function Signature
Advanced Examples
Rich Text Editor
Image Gallery
Interactive Form
Data Visualization
Cell-Specific Content
Customize content based on the cell being expanded:
Complete Example
Styling
Tooltip Styling
Tooltips automatically position themselves to avoid going off-screen. Style them using standard CSS classes:
Popover Styling
Expandable content appears in a popover with scrolling support:
Use Cases
Data Annotations
Show additional context or metadata for cells containing important data.
Error Explanations
Display helpful error messages and suggestions when formulas fail.
Rich Content Preview
Preview images, charts, or formatted text without cluttering the grid.
Interactive Dialogs
Provide forms or interactive elements for complex data entry.
Audit Information
Display who last edited a cell and when.
Performance Considerations
Memoize Callbacks: Use
useCallbackto prevent unnecessary re-rendersConditional Rendering: Return
undefinedwhen no tooltip is neededLazy Loading: Load heavy content only when the popover is opened
Limit Complexity: Keep tooltip content simple for smooth hover interactions
Best Practices
Keep Tooltips Concise: Display only essential information in tooltips
Use Popovers for Rich Content: Save complex content for expandable popovers
Avoid Heavy Computations: Don't perform expensive calculations in tooltip callbacks
Accessibility: Ensure tooltips and popovers work with keyboard navigation
Consistent Styling: Match your application's design system
Troubleshooting
Tooltips Not Showing
Verify
getTooltipContentreturns valid JSX or undefined (not null)Check that the function is properly passed to CanvasGrid
Ensure there are no JavaScript errors in the console
Popovers Not Opening
Confirm
getCellExpandContentis definedCheck that the cell expansion trigger is working (usually double-click or icon)
Verify the content isn't too large or causing layout issues
Performance Issues
Use
React.memofor complex tooltip componentsImplement lazy loading for heavy content
Consider debouncing tooltip display
Last updated
Was this helpful?