From a37aa2ed380466a1c03bbb7c270065db2de07e59 Mon Sep 17 00:00:00 2001 From: Augusto Xavier Date: Tue, 16 Jun 2026 11:18:02 -0300 Subject: [PATCH] Make item dropdown width responsive to window resizing (5556) --- .../line_items/_line_item_fields.html.erb | 2 +- spec/system/distribution_system_spec.rb | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/views/line_items/_line_item_fields.html.erb b/app/views/line_items/_line_item_fields.html.erb index c81741f69d..99f6adb8a8 100644 --- a/app/views/line_items/_line_item_fields.html.erb +++ b/app/views/line_items/_line_item_fields.html.erb @@ -23,7 +23,7 @@ collection: @item_labels_with_quantities || @items, prompt: "Choose an item", include_blank: "", label: false, - input_html: { class: "my-0 line_item_name", "data-controller": "select2" } %> + input_html: { class: "my-0 line_item_name", "data-controller": "select2", "data-select2-config-value": '{"width": "100%"}' } %> <% if requested.present? %> <%= field.input :item_id, as: :hidden %> <% end %> diff --git a/spec/system/distribution_system_spec.rb b/spec/system/distribution_system_spec.rb index f8fcf5050e..0f3163fd37 100644 --- a/spec/system/distribution_system_spec.rb +++ b/spec/system/distribution_system_spec.rb @@ -706,8 +706,26 @@ expect(@request.distribution_id).to eq @distribution.id expect(@request).to be_status_fulfilled end - end + it "keeps the item dropdown within the form width when the window is narrowed" do + item_id = storage_location.items.first.id + request_items = [{ "item_id" => item_id, "quantity" => 10 }] + @request = create(:request, organization:, request_items:, partner:) + create(:item_request, request: @request, item_id:, quantity: 10) + + visit request_path(id: @request.id) + click_on "Fulfill request" + + expect(page).to have_css(".li-name .select2-container") + + current_window.resize_to(600, 800) + + dropdown_width = page.evaluate_script("document.querySelector('.li-name .select2-container').offsetWidth") + column_width = page.evaluate_script("document.querySelector('.li-name').offsetWidth") + + expect(dropdown_width).to be <= column_width + end + end context "via barcode entry" do let(:existing_barcode) { create(:barcode_item, quantity: 50) } let(:item_with_barcode) { existing_barcode.item }