File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed
Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,11 @@ export default class extends Controller {
2828 if ( this . cleanup ) { this . cleanup ( ) }
2929 }
3030
31+ handlePopoverToggle ( event ) {
32+ // Keep ariaExpanded in sync with the actual popover state
33+ this . triggerTarget . ariaExpanded = event . newState === 'open' ? 'true' : 'false'
34+ }
35+
3136 inputChanged ( e ) {
3237 this . updateTriggerContent ( )
3338
@@ -62,9 +67,19 @@ export default class extends Controller {
6267 }
6368 }
6469
65- openPopover ( event ) {
70+ togglePopover ( event ) {
6671 event . preventDefault ( )
6772
73+ if ( this . triggerTarget . ariaExpanded === "true" ) {
74+ this . closePopover ( )
75+ } else {
76+ this . openPopover ( event )
77+ }
78+ }
79+
80+ openPopover ( event ) {
81+ if ( event ) event . preventDefault ( )
82+
6883 this . updatePopoverPosition ( )
6984 this . updatePopoverWidth ( )
7085 this . triggerTarget . ariaExpanded = "true"
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ def default_attrs
1717 data : {
1818 ruby_ui__combobox_target : "popover" ,
1919 action : %w[
20+ toggle->ruby-ui--combobox#handlePopoverToggle
2021 keydown.down->ruby-ui--combobox#keyDownPressed
2122 keydown.up->ruby-ui--combobox#keyUpPressed
2223 keydown.enter->ruby-ui--combobox#keyEnterPressed
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ def default_attrs
3131 data : {
3232 placeholder : @placeholder ,
3333 ruby_ui__combobox_target : "trigger" ,
34- action : "ruby-ui--combobox#openPopover "
34+ action : "ruby-ui--combobox#togglePopover "
3535 } ,
3636 aria : {
3737 haspopup : "listbox" ,
You can’t perform that action at this time.
0 commit comments