Formula Bar
Display and edit cell formulas and values
The Formula Bar is a compound component that displays the active cell reference and allows users to view and edit cell values and formulas. It consists of three main sub-components: FormulaBar, FormulaBarLabel, and FormulaBarInput.
Overview
The Formula Bar provides:
Cell reference display: Shows the active cell address (e.g., "A1", "Sheet2!B5")
Formula editing: Edit cell formulas and values in a larger input area
Formula preview: View complete formulas without cell width constraints
Function hints: Display function syntax and autocomplete
Components
FormulaBar
The parent container that wraps the formula bar components.
import { FormulaBar, FormulaBarLabel, FormulaBarInput } from "@rowsncolumns/spreadsheet";
<FormulaBar>
<FormulaBarLabel>A1</FormulaBarLabel>
<FormulaBarInput
value="=SUM(A1:A10)"
onChange={handleChange}
/>
</FormulaBar>FormulaBarLabel
Displays the active cell reference or range.
FormulaBarInput
Input field for editing cell values and formulas.
Complete Example
Props
FormulaBar
children
React.ReactNode
Child components (FormulaBarLabel, FormulaBarInput)
className
string
Optional CSS class name
FormulaBarLabel
children
React.ReactNode
Cell reference text (e.g., "A1", "B2:D5")
className
string
Optional CSS class name
FormulaBarInput
value
string
Current cell value or formula
onChange
(value: string) => void
Callback when value changes
onKeyDown
(e: React.KeyboardEvent) => void
Optional keyboard handler
functionDescriptions
CalculatorFunction[]
Function definitions for autocomplete
getSheetName
(sheetId: number) => string
Get sheet name by ID
className
string
Optional CSS class name
Features
Formula Autocomplete
The FormulaBarInput supports autocomplete for functions when functionDescriptions is provided:
When users type =SUM(, the input shows function hints and parameter information.
Multi-Cell Selection Display
When multiple cells are selected, the label shows the range:
Named Range Display
Show named range when applicable:
Cross-Sheet References
Display sheet names in cross-sheet references:
Keyboard Shortcuts
The Formula Bar supports standard keyboard shortcuts:
Enter: Confirm and move to next cell
Escape: Cancel editing
Tab: Autocomplete function name
F2: Edit cell in formula bar
Ctrl/Cmd + A: Select all text
Styling
The Formula Bar can be styled using CSS classes:
Integration with Toolbar
Combine with toolbar for a complete spreadsheet interface:
Advanced Usage
Custom Formula Validation
Validate formulas before applying:
Formula Highlighting
Highlight cell references in formulas:
Read-Only Mode
Disable editing in read-only mode:
Best Practices
Always Show Cell Reference: Display the current cell or range reference in FormulaBarLabel
Sync with Active Cell: Update formula bar when active cell changes
Handle Long Formulas: Ensure the input can scroll for long formulas
Provide Function Hints: Include functionDescriptions for better UX
Validate Input: Check for formula errors before applying changes
Support Keyboard Navigation: Implement standard spreadsheet keyboard shortcuts
Troubleshooting
Formula Bar Not Updating
Verify activeCell and selections are properly synced
Check that getCellData returns the correct cell data
Ensure onChange is called when cell values change
Autocomplete Not Working
Confirm functionDescriptions prop is provided
Check that function definitions are properly formatted
Verify the formula starts with "="
Performance Issues
Memoize cellValue calculation for large spreadsheets
Use debouncing for onChange handler
Consider lazy loading function descriptions
See Also
Formula Input - Standalone formula input component
Toolbar - Toolbar component with formatting buttons
Canvas Grid - Main spreadsheet grid component
Last updated
Was this helpful?