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 +4 -4
- data/README.md +12 -3
- data/app/assets/javascripts/tramway/tramway.js +18 -3
- data/lib/tramway/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b7992bbaa872dc64b21203cb0350463136687e0bfe033a1b461c87bf15804f6b
|
|
4
|
+
data.tar.gz: 24024ccfa23c7e0718a8dcfd708ce4fcfe232e67c352e5fa28360b017f0b323e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
1567
|
-
|
|
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
|
-
|
|
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() {
|
data/lib/tramway/version.rb
CHANGED