File tree Expand file tree Collapse file tree 6 files changed +59
-7
lines changed
components/ruby_ui/combobox
javascript/controllers/ruby_ui Expand file tree Collapse file tree 6 files changed +59
-7
lines changed Original file line number Diff line number Diff line change 14
14
15
15
GIT
16
16
remote: https://github.com/ruby-ui/ruby_ui.git
17
- revision: 500b8d98fbee73f15a3182feb4eca8e8e146d6b5
17
+ revision: 537b7c06f57a0918e4ba07ce08c3dad3dace15a3
18
18
branch: main
19
19
specs:
20
20
ruby_ui (1.0.0.beta1 )
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module RubyUI
4
+ class ComboboxToggleAllCheckbox < Base
5
+ def view_template
6
+ input ( type : "checkbox" , **attrs )
7
+ end
8
+
9
+ private
10
+
11
+ def default_attrs
12
+ {
13
+ class : [
14
+ "peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background accent-primary" ,
15
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2" ,
16
+ "disabled:cursor-not-allowed disabled:opacity-50"
17
+ ] ,
18
+ data : {
19
+ ruby_ui__combobox_target : "toggleAll" ,
20
+ action : "change->ruby-ui--combobox#toggleAllItems"
21
+ }
22
+ }
23
+ end
24
+ end
25
+ end
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ export default class extends Controller {
9
9
10
10
static targets = [
11
11
"input" ,
12
+ "toggleAll" ,
12
13
"popover" ,
13
14
"item" ,
14
15
"emptyState" ,
@@ -33,12 +34,22 @@ export default class extends Controller {
33
34
if ( e . target . type == "radio" ) {
34
35
this . closePopover ( )
35
36
}
37
+
38
+ if ( this . hasToggleAllTarget && ! e . target . checked ) {
39
+ this . toggleAllTarget . checked = false
40
+ }
36
41
}
37
42
38
43
inputContent ( input ) {
39
44
return input . dataset . text || input . parentElement . innerText
40
45
}
41
46
47
+ toggleAllItems ( ) {
48
+ const isChecked = this . toggleAllTarget . checked
49
+ this . inputTargets . forEach ( input => input . checked = isChecked )
50
+ this . updateTriggerContent ( )
51
+ }
52
+
42
53
updateTriggerContent ( ) {
43
54
const checkedInputs = this . inputTargets . filter ( input => input . checked )
44
55
@@ -73,6 +84,12 @@ export default class extends Controller {
73
84
}
74
85
75
86
const filterTerm = this . searchInputTarget . value . toLowerCase ( )
87
+
88
+ if ( this . hasToggleAllTarget ) {
89
+ if ( filterTerm ) this . toggleAllTarget . parentElement . classList . add ( "hidden" )
90
+ else this . toggleAllTarget . parentElement . classList . remove ( "hidden" )
91
+ }
92
+
76
93
let resultCount = 0
77
94
78
95
this . selectedItemIndex = null
Original file line number Diff line number Diff line change @@ -76,6 +76,11 @@ def view_template
76
76
ComboboxList do
77
77
ComboboxEmptyState { "No result" }
78
78
79
+ ComboboxItem(class: "mt-3") do
80
+ ComboboxToggleAllCheckbox(name: "all", value: "all")
81
+ span { "Select all" }
82
+ end
83
+
79
84
ComboboxListGroup label: "Fruits" do
80
85
ComboboxItem do
81
86
ComboboxCheckbox(name: "food", value: "apple")
Original file line number Diff line number Diff line change 2
2
"name" : " app" ,
3
3
"private" : " true" ,
4
4
"dependencies" : {
5
- "@floating-ui/dom" : " ^1.6.12 " ,
5
+ "@floating-ui/dom" : " ^1.6.13 " ,
6
6
"@hotwired/stimulus" : " 3.2.2" ,
7
7
"@hotwired/turbo-rails" : " 8.0.12" ,
8
8
"autoprefixer" : " 10.4.19" ,
Original file line number Diff line number Diff line change 134
134
dependencies :
135
135
" @floating-ui/utils" " ^0.2.8"
136
136
137
- " @floating-ui/dom@^1.6.12 " :
138
- version "1.6.12 "
139
- resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.6.12 .tgz#6333dcb5a8ead3b2bf82f33d6bc410e95f54e556 "
140
- integrity sha512-NP83c0HjokcGVEMeoStg317VD9W7eDlGK7457dMBANbKA6GJZdc7rjujdgqzTaz93jkGgc5P/jeWbaCHnMNc+w ==
137
+ " @floating-ui/dom@^1.6.13 " :
138
+ version "1.6.13 "
139
+ resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.6.13 .tgz#a8a938532aea27a95121ec16e667a7cbe8c59e34 "
140
+ integrity sha512-umqzocjDgNRGTuO7Q8CU32dkHkECqI8ZdMZ5Swb6QAM0t5rnlrN3lGo1hdpscRd3WS8T6DKYK4ephgIH9iRh3w ==
141
141
dependencies :
142
142
" @floating-ui/core" " ^1.6.0"
143
- " @floating-ui/utils" " ^0.2.8 "
143
+ " @floating-ui/utils" " ^0.2.9 "
144
144
145
145
" @floating-ui/utils@^0.2.8 " :
146
146
version "0.2.8"
147
147
resolved "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.8.tgz"
148
148
integrity sha512-kym7SodPp8/wloecOpcmSnWJsK7M0E5Wg8UcFA+uO4B9s5d0ywXOEro/8HM9x0rW+TljRzul/14UYz3TleT3ig==
149
149
150
+ " @floating-ui/utils@^0.2.9 " :
151
+ version "0.2.9"
152
+ resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.9.tgz#50dea3616bc8191fb8e112283b49eaff03e78429"
153
+ integrity sha512-MDWhGtE+eHw5JW7lq4qhc5yRLS11ERl1c7Z6Xd0a58DozHES6EnNNwUWbMiG4J9Cgj053Bhk8zvlhFYKVhULwg==
154
+
150
155
151
156
version "3.2.2"
152
157
resolved "https://registry.npmjs.org/@hotwired/stimulus/-/stimulus-3.2.2.tgz"
You can’t perform that action at this time.
0 commit comments