hotwire_combobox 0.1.36 → 0.1.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 446cd3c4beeb66029cab7cd6b92ac04c2a8c7a1f08ffd874728da2a3e605ead7
4
- data.tar.gz: 9783eb83824ebeff3fa55536002c24e129fc66ed0b9d82e33c808a8d65c6c3ee
3
+ metadata.gz: 85fbe2e5c1b8d503be62eceae58650266582ac3428be6558c0af8bb76ec5f03c
4
+ data.tar.gz: f13eb27444b1e530391a8058dc6f00a6d46d9df4af75eb2de2cd28a568851f0b
5
5
  SHA512:
6
- metadata.gz: a4d5e3d5fddd0017fc6bb6e838a60550d0e7dc2da3fac8999befa092ad9a8a7d35753cc785271fdfb8fe43e63edc535dc97f441594c8be2a3eece394622b97d6
7
- data.tar.gz: 1d60ba35f6f043b9698d7b9bd48aadd702e67c00cb626068e797890ebcc3cfd370af14c33479da153f57096c1015c062f7539676da55aac559d76b38234a4d24
6
+ metadata.gz: 207509d422415ad6684e08b09690b2244f6fde41e3a9f92a6e90ddf7808f1d0a43d1966f48847c52e133e48e8d81d8139dd2883053dd7b44ed5739d7ab2d62fc
7
+ data.tar.gz: 184048c9ec147b4d28abf8a3c0d189fa6b73e72a9ef47c6db4c9cf3a595b880287d4e0ddc985d785a38fbce1b9a58279825c46099f800492368ae2cafe349a30
@@ -6,6 +6,10 @@ Combobox.Actors = Base => class extends Base {
6
6
  this._actingCombobox = this.comboboxTarget
7
7
  }
8
8
 
9
+ _forAllComboboxes(callback) {
10
+ this._allComboboxes.forEach(callback)
11
+ }
12
+
9
13
  get _actingListbox() {
10
14
  return this.actingListbox
11
15
  }
@@ -21,4 +25,8 @@ Combobox.Actors = Base => class extends Base {
21
25
  set _actingCombobox(combobox) {
22
26
  this.actingCombobox = combobox
23
27
  }
28
+
29
+ get _allComboboxes() {
30
+ return [ this.comboboxTarget, this.dialogComboboxTarget ]
31
+ }
24
32
  }
@@ -41,12 +41,14 @@ Combobox.Selection = Base => class extends Base {
41
41
  }
42
42
 
43
43
  option.setAttribute("aria-selected", selected)
44
+ this._setActiveDescendant(selected ? option.id : "")
44
45
  }
45
46
 
46
47
  _deselect() {
47
48
  const option = this._selectedOptionElement
48
49
  if (option) this._commitSelection(option, { selected: false })
49
50
  this.hiddenFieldTarget.value = null
51
+ this._setActiveDescendant("")
50
52
  }
51
53
 
52
54
  _selectNew() {
@@ -77,6 +79,10 @@ Combobox.Selection = Base => class extends Base {
77
79
  }
78
80
  }
79
81
 
82
+ _setActiveDescendant(id) {
83
+ this._forAllComboboxes(el => el.setAttribute("aria-activedescendant", id))
84
+ }
85
+
80
86
  get _hasValueButNoSelection() {
81
87
  return this.hiddenFieldTarget.value && !this._selectedOptionElement
82
88
  }
@@ -53,8 +53,9 @@ class HotwireCombobox::Component
53
53
  class: "hw-combobox__input",
54
54
  type: input_type,
55
55
  data: input_data,
56
- aria: input_aria
57
- }.merge combobox_attrs.except(*nested_attrs)
56
+ aria: input_aria,
57
+ autocomplete: :off
58
+ }.with_indifferent_access.merge combobox_attrs.except(*nested_attrs)
58
59
  end
59
60
 
60
61
 
@@ -77,11 +78,6 @@ class HotwireCombobox::Component
77
78
  end
78
79
 
79
80
 
80
- def listbox_options_attrs
81
- { id: listbox_options_id }
82
- end
83
-
84
-
85
81
  def dialog_wrapper_attrs
86
82
  {
87
83
  class: "hw-combobox__dialog__wrapper"
@@ -239,7 +235,8 @@ class HotwireCombobox::Component
239
235
  controls: listbox_id,
240
236
  owns: listbox_id,
241
237
  haspopup: "listbox",
242
- autocomplete: autocomplete
238
+ autocomplete: autocomplete,
239
+ activedescendant: ""
243
240
  end
244
241
 
245
242
 
@@ -260,11 +257,6 @@ class HotwireCombobox::Component
260
257
  end
261
258
 
262
259
 
263
- def listbox_options_id
264
- "#{listbox_id}__options"
265
- end
266
-
267
-
268
260
  def dialog_data
269
261
  {
270
262
  action: "keydown->hw-combobox#navigate",
@@ -290,7 +282,8 @@ class HotwireCombobox::Component
290
282
  {
291
283
  controls: dialog_listbox_id,
292
284
  owns: dialog_listbox_id,
293
- autocomplete: autocomplete
285
+ autocomplete: autocomplete,
286
+ activedescendant: ""
294
287
  }
295
288
  end
296
289
 
@@ -1,3 +1,5 @@
1
+ require "securerandom"
2
+
1
3
  class HotwireCombobox::Listbox::Option
2
4
  def initialize(option)
3
5
  @option = option.is_a?(Hash) ? Data.new(**option) : option
@@ -30,7 +32,7 @@ class HotwireCombobox::Listbox::Option
30
32
  end
31
33
 
32
34
  def id
33
- option.try(:id)
35
+ option.try(:id) || SecureRandom.uuid
34
36
  end
35
37
 
36
38
  def data
@@ -1,5 +1,6 @@
1
1
  <%# locals: (for_id:, next_page:, src:) -%>
2
2
 
3
- <%= turbo_stream.replace hw_pagination_frame_id(for_id) do %>
3
+ <%= turbo_stream.remove hw_pagination_frame_wrapper_id(for_id) %>
4
+ <%= turbo_stream.append hw_listbox_id(for_id) do %>
4
5
  <%= render "hotwire_combobox/pagination", for_id: for_id, src: hw_combobox_next_page_uri(src, next_page) %>
5
6
  <% end %>
@@ -1,6 +1,6 @@
1
1
  <%# locals: (for_id:, options:) -%>
2
2
 
3
- <%= turbo_stream.public_send(hw_combobox_page_stream_action, hw_listbox_options_id(for_id)) do %>
3
+ <%= turbo_stream.public_send(hw_combobox_page_stream_action, hw_listbox_id(for_id)) do %>
4
4
  <% options.each do |option| %>
5
5
  <%= render option %>
6
6
  <% end %>
@@ -1,4 +1,7 @@
1
1
  <%# locals: (for_id:, src:) -%>
2
2
 
3
- <%= turbo_frame_tag hw_pagination_frame_id(for_id), src: src, loading: :lazy,
4
- data: { hw_combobox_target: "endOfOptionsStream", input_type: params[:input_type] } %>
3
+ <%= tag.li id: hw_pagination_frame_wrapper_id(for_id), data: {
4
+ hw_combobox_target: "endOfOptionsStream", input_type: params[:input_type] },
5
+ aria: { hidden: true } do %>
6
+ <%= turbo_frame_tag hw_pagination_frame_id(for_id), src: src, loading: :lazy %>
7
+ <% end %>
@@ -1,8 +1,6 @@
1
1
  <%= tag.ul **component.listbox_attrs do |ul| %>
2
- <%= tag.div **component.listbox_options_attrs do %>
3
- <% component.options.each do |option| %>
4
- <%= render option %>
5
- <% end %>
2
+ <% component.options.each do |option| %>
3
+ <%= render option %>
6
4
  <% end %>
7
5
 
8
6
  <% if component.paginated? %>
@@ -45,8 +45,12 @@ module HotwireCombobox
45
45
  hw_alias :hw_async_combobox_options
46
46
 
47
47
  protected # library use only
48
- def hw_listbox_options_id(id)
49
- "#{id}-hw-listbox__options"
48
+ def hw_listbox_id(id)
49
+ "#{id}-hw-listbox"
50
+ end
51
+
52
+ def hw_pagination_frame_wrapper_id(id)
53
+ "#{id}__hw_combobox_pagination__wrapper"
50
54
  end
51
55
 
52
56
  def hw_pagination_frame_id(id)
@@ -1,3 +1,3 @@
1
1
  module HotwireCombobox
2
- VERSION = "0.1.36"
2
+ VERSION = "0.1.37"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotwire_combobox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.36
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Farias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-02 00:00:00.000000000 Z
11
+ date: 2024-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails