File tree 2 files changed +42
-0
lines changed
2 files changed +42
-0
lines changed 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
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
You can’t perform that action at this time.
0 commit comments