tramway 4.1 → 4.1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a20badcbb5b3d0d460bbadafb95816d4932ce5e8af0d41a9ce2315507220bed0
4
- data.tar.gz: 800c9136a41a012e3b8581611afa70e666f81c4dab9d331cc7c094d096cb2b86
3
+ metadata.gz: b7992bbaa872dc64b21203cb0350463136687e0bfe033a1b461c87bf15804f6b
4
+ data.tar.gz: 24024ccfa23c7e0718a8dcfd708ce4fcfe232e67c352e5fa28360b017f0b323e
5
5
  SHA512:
6
- metadata.gz: 84e42fc4f2acf64a31007add38185688e84d9728873a528a1d1b787b5b7383e94b5b7ff22ee62c0040eb75f0daae50d0d1c182f68424a39919e3f4ee2ef90a92
7
- data.tar.gz: de23a5e5b76877268ce42d2371f5db9907c3ce6a517b15ea7b234a2ecc944c6a04fb3b70001b098ab06b07d52f25fdeae1a36ec9112eb2530be0394f719354d2
6
+ metadata.gz: 5a8e09bf7ab1d4c09d881f87d99cd1ab5841e92b29a17e2bab144bc009e70263af0cf3ffc71930a027dd589beb13f50c933f4ffcc9fb292e3c36e75f2015b699
7
+ data.tar.gz: 0110e0d22d0f745d459021d97b929ed4915e08d292a706d7a06dd0c409cd2426c42f2fdb0e40af5ef243e1609b8c37c5ad20204c38b7d16db4f4d0f9d5599b89
data/README.md CHANGED
@@ -1563,10 +1563,19 @@ Autocomplete select example:
1563
1563
  <% end %>
1564
1564
  ```
1565
1565
 
1566
- `autocomplete: true` renders an autocomplete-enabled select. It cannot be used together with `multiselect: true` in the
1567
- same select field.
1566
+ `autocomplete: true` renders an autocomplete-enabled select. It can be combined with `multiple: true` to get a
1567
+ searchable multi-select:
1568
1568
 
1569
- When you use `multiselect: true`, make sure any preselected values still exist in the collection you render. Unknown
1569
+ ```erb
1570
+ <%= tramway_form_for @user do |f| %>
1571
+ <%= f.select :departments, [['Engineering', 'engineering'], ['Sales', 'sales']], autocomplete: true, multiple: true %>
1572
+ <% end %>
1573
+ ```
1574
+
1575
+ With both options set, the search input stays visible after each selection so you can keep filtering and picking
1576
+ more options; selected options still show as removable tags.
1577
+
1578
+ When you use `multiple: true`, make sure any preselected values still exist in the collection you render. Unknown
1570
1579
  values are ignored by the widget so the select can still boot safely.
1571
1580
 
1572
1581
  **Examples**
@@ -26,7 +26,7 @@ class TramwaySelect extends Controller {
26
26
  this.items = JSON.parse(this.element.dataset.items).map((item, index) => {
27
27
  return {
28
28
  index,
29
- text: item.text,
29
+ text: item.text == null ? '' : item.text.toString(),
30
30
  value: item.value.toString(),
31
31
  selected: false
32
32
  }
@@ -59,7 +59,7 @@ class TramwaySelect extends Controller {
59
59
 
60
60
  let content = allItems;
61
61
 
62
- if (this.autocomplete() && this.selectedItems.length === 0) {
62
+ if (this.autocomplete() && (this.multiple() || this.selectedItems.length === 0)) {
63
63
  content += this.element.dataset.autocompleteInput;
64
64
  }
65
65
 
@@ -80,7 +80,14 @@ class TramwaySelect extends Controller {
80
80
  }
81
81
  }
82
82
 
83
- toggleDropdown() {
83
+ toggleDropdown(event) {
84
+ // Clicking into the autocomplete search input bubbles up to this action. While the dropdown
85
+ // is already open, that click should keep it open (so the user can keep typing/selecting)
86
+ // rather than close it on every refocus.
87
+ if (this.dropdownState === 'open' && event && event.target.tagName === 'INPUT') {
88
+ return;
89
+ }
90
+
84
91
  if (this.dropdownState === 'closed') {
85
92
  this.openDropdown();
86
93
  } else {
@@ -103,6 +110,14 @@ class TramwaySelect extends Controller {
103
110
 
104
111
  this.caretDownTarget.classList.add('hidden');
105
112
  this.caretUpTarget.classList.remove('hidden');
113
+
114
+ if (this.autocomplete()) {
115
+ this.searchInput()?.focus();
116
+ }
117
+ }
118
+
119
+ searchInput() {
120
+ return this.showSelectedAreaTarget.querySelector('input');
106
121
  }
107
122
 
108
123
  dropdown() {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '4.1'
4
+ VERSION = '4.1.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway
3
3
  version: !ruby/object:Gem::Version
4
- version: '4.1'
4
+ version: 4.1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kalashnikovisme