Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textarea for formula #973

Merged
merged 21 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/javascript/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import "@fortawesome/fontawesome-free";
import "@rails/request.js";
import "@rails/actioncable";
import "turbo_streams/toast";
import "@oddcamp/cocoon-vanilla-js"
import "@oddcamp/cocoon-vanilla-js"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Нема строки в кінці файлу

9 changes: 9 additions & 0 deletions app/javascript/components/auto_resize_textarea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
document.addEventListener('input', function (event) {
if (event.target && event.target.classList.contains('resize-auto') && event.target.tagName === 'TEXTAREA') {
const textarea = event.target;
textarea.style.overflow = 'hidden';
textarea.style.resize = 'none';
textarea.style.height = 'auto';
textarea.style.height = (textarea.scrollHeight) + 'px';
}
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

юзай для цього стімулус контроллер

Copy link
Collaborator

Choose a reason for hiding this comment

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

Досі актуально

Copy link
Collaborator

Choose a reason for hiding this comment

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

Або навіть видали

20 changes: 20 additions & 0 deletions app/javascript/controllers/textarea_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
static targets = ["textarea"];

connect() {
this.resize(this.element);
}

resize(textarea) {
textarea.style.overflow = "hidden"; // Prevent scrollbars
textarea.style.resize = "none"; // Prevent manual resizing
textarea.style.height = "auto"; // Reset height
textarea.style.height = `${textarea.scrollHeight}px`; // Adjust height based on scrollHeight
}

input(event) {
this.resize(event.target);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<div class="nested-fields">
<%= f.input :en_label, label: "Formula Label:" %>
<%= f.input :uk_label, label: "Uk Formula Label:" %>
<%= f.input :expression, label: "Formula Expression:" %>

<%= f.input :expression, as: :text, label: "Formula Expression:", input_html: {
data: { controller: "textarea", action: "input->textarea#input" }
} %>
<%= f.input :uk_unit, label: "Uk Unit Label:" %>
<%= f.input :en_unit, label: "Unit Label:" %>

<%= link_to_remove_association "- Remove Formula", f, class: "text-red-500 underline" %>
</div>
</div>
2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@

config.add_formatter "Fuubar"
config.fuubar_output_pending_results = false

Capybara.default_max_wait_time = 10 # Increase wait time (in seconds), so test don't fail locally
end

Shoulda::Matchers.configure do |config|
Expand Down
Loading