diff --git a/app/assets/stylesheets/components/form.css b/app/assets/stylesheets/components/form.css index 5bff0c355..3895f6780 100644 --- a/app/assets/stylesheets/components/form.css +++ b/app/assets/stylesheets/components/form.css @@ -36,4 +36,12 @@ .auth-login-links { @apply flex items-center justify-center gap-4 text-center border-t border-solid text-gray border-light_gray; } + + /* Formula field */ + .formula{ + border-radius: inherit !important; + border-color: #6b7280 !important; + overflow: hidden; + resize: none !important; + } } diff --git a/app/javascript/controllers/textarea_controller.js b/app/javascript/controllers/textarea_controller.js new file mode 100644 index 000000000..33e25e146 --- /dev/null +++ b/app/javascript/controllers/textarea_controller.js @@ -0,0 +1,18 @@ +import { Controller } from "@hotwired/stimulus"; + +export default class extends Controller { + static targets = ["textarea"]; + + connect() { + this.resize(this.element); + } + + resize(textarea) { + textarea.style.height = "auto"; + textarea.style.height = `${textarea.scrollHeight}px`; // Adjust height based on scrollHeight + } + + input(event) { + this.resize(event.target); + } +} diff --git a/app/views/account/calculators/partials/_formula_fields.html.erb b/app/views/account/calculators/partials/_formula_fields.html.erb index ce40536f6..bee217020 100644 --- a/app/views/account/calculators/partials/_formula_fields.html.erb +++ b/app/views/account/calculators/partials/_formula_fields.html.erb @@ -3,7 +3,9 @@
<%= 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: { class: "formula", + data: { controller: "textarea", action: "input->textarea#input" } + } %> <%= f.input :uk_unit, label: "Uk Unit Label:" %> <%= f.input :en_unit, label: "Unit Label:" %> diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 01d857619..29f931450 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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|