DyeLight includes built-in automatic resizing that adjusts the textarea height dynamically as content changes. This creates a more natural editing experience by eliminating scrollbars for shorter content.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ragaeeb/dyelight/llms.txt
Use this file to discover all available pages before exploring further.
How it works
WhenenableAutoResize is enabled (the default), the textarea automatically grows and shrinks based on its content. The component uses the scrollHeight property to calculate the required height (see useAutoResize.ts:26-27).
Enabling and disabling
Auto-resize is enabled by default. You can disable it to allow manual vertical resizing:When
enableAutoResize is false, the textarea’s resize CSS property is set to 'vertical', allowing users to manually resize. When true, it’s set to 'none' (see DyeLight.tsx:423).The resize mechanism
The auto-resize functionality is managed by theuseAutoResize hook, which:
- Monitors content changes
- Calculates the new height using
scrollHeight - Applies the height to the textarea
- Synchronizes the highlight overlay
useAutoResize.ts:55-80:
Resize triggers
The textarea automatically resizes in response to:- Text changes: When the user types or deletes content
- Paste operations: When content is pasted in
- Programmatic updates: When
setValue()is called via ref - Layout changes: When styles, className, or rows props change
- ResizeObserver events: When the textarea is resized by external factors
Initial rows
Therows prop sets the initial visible height when the textarea is empty or contains minimal content:
Use cases
Comment boxes
Auto-resize is perfect for comment or message inputs that should grow with content:Code editors with limited space
For inline code editors where you want to see all content without scrolling:Fixed-height editors
When you need a fixed-height editor with scrolling (e.g., for large documents):Performance considerations
The auto-resize mechanism is optimized to avoid layout thrashing:- ResizeObserver batching: Uses
ResizeObserverto detect size changes, which is batched by the browser (seeDyeLight.tsx:400-410) - Debouncing: Layout updates are debounced using
requestAnimationFrameto prevent rapid recalculations - Memoization: Height calculations are cached and only recomputed when necessary
Telemetry and debugging
When debug mode is enabled, auto-resize events are tracked with telemetry data:useAutoResize.ts:67-75):
beforeHeight: Height before resizeafterHeight: Height after resizechanged: Whether the height actually changedtextLength: Current text length
Excessive resize events (more than text changes) may indicate an infinite ResizeObserver loop. Check the debug report for this pattern.
Styling with auto-resize
When using auto-resize with custom styles:If you need to limit the maximum height, apply
max-height to the containerClassName rather than the textarea itself. This allows the textarea to grow within a scrollable container.