Mentions

Add @mentions functionality to spreadsheet cells

The mentions feature allows users to reference people, tags, or entities within cells using the @ symbol, similar to social media platforms. This is useful for collaborative spreadsheets, task management, and commenting systems.

Overview

Mentions enable:

  • User tagging: Reference team members in cells

  • Entity references: Link to external resources or data

  • Autocomplete: Dropdown suggestions as users type

  • Custom rendering: Display mentions with custom styling

  • Data binding: Connect mentions to your application's data model

Basic Usage

import { SpreadsheetProvider, CanvasGrid } from "@rowsncolumns/spreadsheet";
import { useCallback } from "react";

function SpreadsheetWithMentions() {
  const getMentions = useCallback(async (query?: string) => {
    // Fetch mentions from your API or database
    return [
      { label: "John Doe", value: "user-123" },
      { label: "Jane Smith", value: "user-456" },
      { label: "Marketing Team", value: "team-789" },
    ];
  }, []);

  return (
    <SpreadsheetProvider>
      <CanvasGrid
        sheetId={1}
        getMentions={getMentions}
        // ... other props
      />
    </SpreadsheetProvider>
  );
}

getMentions Function

The getMentions callback is called when users type @ in a cell. It should return a Promise that resolves to an array of mention objects.

Function Signature

Parameters

  • query (optional): The search text entered by the user after @

Custom Dropdown Rendering

Customize how mentions appear in the autocomplete dropdown using MentionDropdownItemComponent:

MentionDropdownItemComponent Props

Async Data Loading

Fetch mentions from an API:

Complete Example

Accessing Mention Data

When a mention is selected, it's stored in the cell data. You can access it through the cell's data structure:

Use Cases

Team Collaboration

Project Management

Comments and Notes

Styling

Mentions in cells can be styled using custom text format runs. The spreadsheet automatically formats mentioned text when rendered.

Performance Optimization

Caching

Best Practices

  1. Limit Results: Return a maximum of 10-20 mentions to keep the dropdown manageable

  2. Fast Response: Keep the getMentions function fast (< 300ms) for good UX

  3. Error Handling: Handle API failures gracefully and return an empty array

  4. Unique Values: Ensure each mention has a unique value property

  5. Clear Labels: Use descriptive labels that help users identify the right mention

  6. Type Safety: Use TypeScript to define your mention structure

Troubleshooting

Mentions Not Appearing

  • Verify getMentions returns an array of objects with label and value properties

  • Check that the function returns a Promise

  • Ensure there are no JavaScript errors in the console

Search Not Working

  • Confirm the query parameter is being used in your filter logic

  • Test the search function independently

  • Check for case sensitivity issues

Slow Performance

  • Implement debouncing for API calls

  • Add caching for frequently accessed results

  • Limit the number of returned results

  • Use pagination for large datasets

Last updated

Was this helpful?