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 content

  • Expandable 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

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

  1. Memoize Callbacks: Use useCallback to prevent unnecessary re-renders

  2. Conditional Rendering: Return undefined when no tooltip is needed

  3. Lazy Loading: Load heavy content only when the popover is opened

  4. Limit Complexity: Keep tooltip content simple for smooth hover interactions

Best Practices

  1. Keep Tooltips Concise: Display only essential information in tooltips

  2. Use Popovers for Rich Content: Save complex content for expandable popovers

  3. Avoid Heavy Computations: Don't perform expensive calculations in tooltip callbacks

  4. Accessibility: Ensure tooltips and popovers work with keyboard navigation

  5. Consistent Styling: Match your application's design system

Troubleshooting

Tooltips Not Showing

  • Verify getTooltipContent returns 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 getCellExpandContent is defined

  • Check 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.memo for complex tooltip components

  • Implement lazy loading for heavy content

  • Consider debouncing tooltip display

Last updated

Was this helpful?