Overview
TheuseYooptaFocused hook returns a boolean indicating whether the Yoopta editor is currently focused. This is useful for showing/hiding UI elements or changing behavior based on editor focus state.
Usage
Signature
Returns
boolean - true if the editor is focused, false otherwise
Examples
Show Toolbar When Focused
Conditional Styling
Focus Indicator
Keyboard Shortcut Handler
Character Count with Focus State
Auto-save on Blur
Use Cases
- Floating Toolbars: Show formatting tools only when editor is focused
- Visual Feedback: Highlight editor border or background on focus
- Keyboard Shortcuts: Enable/disable shortcuts based on focus
- Auto-save: Trigger save operations when focus is lost
- Analytics: Track user engagement with the editor
- Context Menus: Show/hide context-sensitive menus
- Status Indicators: Display editor state in the UI
Focus vs Selection
Note the difference between editor focus and block selection:- Focus (
useYooptaFocused): Whether the editor as a whole has focus - Selection (
useBlockSelected): Whether a specific block is selected
Implementation Details
Under the hood, this hook callseditor.isFocused(), which is a method on the YooEditor instance. The focus state is managed internally by the editor.
See Also
- useYooptaEditor - Access the editor instance
- useBlockSelected - Check if block is selected
- useYooptaReadOnly - Get read-only state