Class: Form::Combobox

Inherits:
BaseTag
  • Object
show all
Defined in:
app/views/form/combobox.rb

Constant Summary collapse

ALLOWED_OPTIONS =
[
  :choices,
  :text_method,
  :value_method,
  :multiple,
  :selected,
  :help_text,
  :searching_text,
  :no_results_text,
  :all_choices_selected_text
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allowed_optionsObject



17
18
19
# File 'app/views/form/combobox.rb', line 17

def allowed_options
  super + ALLOWED_OPTIONS
end

Instance Method Details

#view_templateObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/views/form/combobox.rb', line 32

def view_template
  div data: {
    controller: "combobox",
    combobox_multiple_value: multiple,
    combobox_search_url_value: choices.is_a?(String) ? choices : nil,
    combobox_help_text_value: help_text,
    combobox_searching_text_value: searching_text,
    combobox_no_results_text_value: no_results_text,
    combobox_all_choices_selected_text_value: all_choices_selected_text,
    combobox_input_name_value: name,
    has_choices: multiple && existing_selections.any?
  }, class: "relative group" do
    fieldset(class: classes, data:) do
      input(
        id: input_id,
        type: :search,
        role: "combobox",
        "aria-expanded": "false",
        "aria-autocomplete": "list",
        "aria-haspopup": "listbox",
        data: {
          combobox_target: "input",
          action: "keydown->combobox#keydown input->combobox#search focus->combobox#showMenu blur->combobox#hideMenuWithDelay"
        },
        value: input_value,
        class: input_classes,
        placeholder: options[:placeholder] || ""
      )

      render_selected
    end

    div data: {
      combobox_target: "menu",
      transition_enter_from: "opacity-0 scale-95",
      transition_enter_to: "opacity-100 scale-100",
      transition_leave_from: "opacity-100 scale-100",
      transition_leave_to: "opacity-0 scale-95"
    }, class: "hidden w-full transition transform origin-top-left absolute left-0 top-0 z-50" do
      menu role: "listbox", class: "w-full bg-white rounded-lg shadow-lg outline -outline-offset-1
      outline-gray-300 inline-flex flex-col justify-start items-start overflow-hidden max-h-60 overflow-y-auto" do
        render_choices_container
      end
    end
  end
end