Skip to content

Resizing for textareas#81

Merged
travisdock merged 1 commit intomainfrom
text-boxes
Feb 3, 2026
Merged

Resizing for textareas#81
travisdock merged 1 commit intomainfrom
text-boxes

Conversation

@travisdock
Copy link
Owner

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds automatic textarea resizing functionality to improve the user experience when entering content in project-related forms. The changes introduce a new Stimulus controller that dynamically adjusts textarea height based on content while respecting minimum and maximum row constraints.

Changes:

  • Created a new auto_resize_textarea_controller.js Stimulus controller to handle automatic textarea resizing
  • Updated three form templates (thoughts, resources, and journal entries) to use the new auto-resize functionality
  • Changed CSS from resize-none to resize-y to allow both automatic and manual resizing

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
app/javascript/controllers/auto_resize_textarea_controller.js New Stimulus controller implementing auto-resize logic with configurable min/max rows
app/views/projects/thoughts/_form.html.erb Added auto-resize controller integration with data attributes for min/max rows configuration
app/views/projects/resources/_form.html.erb Added auto-resize controller integration with data attributes for min/max rows configuration
app/views/projects/journal_entries/_form.html.erb Added auto-resize controller integration with data attributes for min/max rows configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

export default class extends Controller {
static values = {
minRows: { type: Number, default: 2 },
maxRows: { type: Number, default: 10 }
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value for maxRows in the controller is set to 10, but all the view templates are explicitly passing 12. Consider updating the default to 12 in the controller to match the usage in the views, or document why the default differs from the common usage.

Suggested change
maxRows: { type: Number, default: 10 }
maxRows: { type: Number, default: 12 }

Copilot uses AI. Check for mistakes.
Comment on lines +27 to +32
// Calculate new height based on content
const newHeight = Math.min(Math.max(textarea.scrollHeight, minHeight), maxHeight)
textarea.style.height = `${newHeight}px`

// Show scrollbar if content exceeds max height
textarea.style.overflowY = textarea.scrollHeight > maxHeight ? 'auto' : 'hidden'
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overflow check occurs after setting the textarea height to newHeight, which may cause scrollHeight to be inaccurate. Consider capturing the original scrollHeight before setting the new height, or check if the original scrollHeight exceeded maxHeight before applying the height constraint. For example, store 'const contentHeight = textarea.scrollHeight' before line 28, and then use 'contentHeight > maxHeight' in line 32.

Suggested change
// Calculate new height based on content
const newHeight = Math.min(Math.max(textarea.scrollHeight, minHeight), maxHeight)
textarea.style.height = `${newHeight}px`
// Show scrollbar if content exceeds max height
textarea.style.overflowY = textarea.scrollHeight > maxHeight ? 'auto' : 'hidden'
// Capture content height before applying max height constraint
const contentHeight = textarea.scrollHeight
// Calculate new height based on content
const newHeight = Math.min(Math.max(contentHeight, minHeight), maxHeight)
textarea.style.height = `${newHeight}px`
// Show scrollbar if content exceeds max height
textarea.style.overflowY = contentHeight > maxHeight ? 'auto' : 'hidden'

Copilot uses AI. Check for mistakes.
auto_resize_textarea_min_rows_value: 2,
auto_resize_textarea_max_rows_value: 12
},
class: "w-full rounded-2xl border border-slate-300/80 bg-white px-4 py-3 text-base text-slate-900 placeholder:text-slate-400 focus:border-blue-500 focus:outline-none focus:ring-4 focus:ring-blue-400/30 resize-y" %>
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CSS class changed from 'resize-none' to 'resize-y', which allows manual resizing. However, the auto-resize controller also sets the height programmatically on input. This may cause confusing behavior where user-initiated manual resizing is overridden by automatic resizing. Consider whether 'resize-none' would be more appropriate to prevent conflict between manual and automatic resizing, or document that manual resizing is intentionally supported alongside auto-resizing.

Suggested change
class: "w-full rounded-2xl border border-slate-300/80 bg-white px-4 py-3 text-base text-slate-900 placeholder:text-slate-400 focus:border-blue-500 focus:outline-none focus:ring-4 focus:ring-blue-400/30 resize-y" %>
class: "w-full rounded-2xl border border-slate-300/80 bg-white px-4 py-3 text-base text-slate-900 placeholder:text-slate-400 focus:border-blue-500 focus:outline-none focus:ring-4 focus:ring-blue-400/30 resize-none" %>

Copilot uses AI. Check for mistakes.
auto_resize_textarea_min_rows_value: 2,
auto_resize_textarea_max_rows_value: 12
},
class: "w-full rounded-2xl border border-slate-300/80 bg-white px-4 py-3 text-base text-slate-900 placeholder:text-slate-400 focus:border-blue-500 focus:outline-none focus:ring-4 focus:ring-blue-400/30 resize-y" %>
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CSS class changed from 'resize-none' to 'resize-y', which allows manual resizing. However, the auto-resize controller also sets the height programmatically on input. This may cause confusing behavior where user-initiated manual resizing is overridden by automatic resizing. Consider whether 'resize-none' would be more appropriate to prevent conflict between manual and automatic resizing, or document that manual resizing is intentionally supported alongside auto-resizing.

Suggested change
class: "w-full rounded-2xl border border-slate-300/80 bg-white px-4 py-3 text-base text-slate-900 placeholder:text-slate-400 focus:border-blue-500 focus:outline-none focus:ring-4 focus:ring-blue-400/30 resize-y" %>
class: "w-full rounded-2xl border border-slate-300/80 bg-white px-4 py-3 text-base text-slate-900 placeholder:text-slate-400 focus:border-blue-500 focus:outline-none focus:ring-4 focus:ring-blue-400/30 resize-none" %>

Copilot uses AI. Check for mistakes.
auto_resize_textarea_min_rows_value: 2,
auto_resize_textarea_max_rows_value: 12
},
class: "w-full rounded-2xl border border-slate-300/80 bg-white px-4 py-3 text-base text-slate-900 placeholder:text-slate-400 focus:border-blue-500 focus:outline-none focus:ring-4 focus:ring-blue-400/30 resize-y" %>
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CSS class changed from 'resize-none' to 'resize-y', which allows manual resizing. However, the auto-resize controller also sets the height programmatically on input. This may cause confusing behavior where user-initiated manual resizing is overridden by automatic resizing. Consider whether 'resize-none' would be more appropriate to prevent conflict between manual and automatic resizing, or document that manual resizing is intentionally supported alongside auto-resizing.

Suggested change
class: "w-full rounded-2xl border border-slate-300/80 bg-white px-4 py-3 text-base text-slate-900 placeholder:text-slate-400 focus:border-blue-500 focus:outline-none focus:ring-4 focus:ring-blue-400/30 resize-y" %>
class: "w-full rounded-2xl border border-slate-300/80 bg-white px-4 py-3 text-base text-slate-900 placeholder:text-slate-400 focus:border-blue-500 focus:outline-none focus:ring-4 focus:ring-blue-400/30 resize-none" %>

Copilot uses AI. Check for mistakes.
@travisdock travisdock merged commit 9b771e6 into main Feb 3, 2026
12 checks passed
@travisdock travisdock deleted the text-boxes branch February 3, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant