Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/ruby_ui/combobox/combobox_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export default class extends Controller {
if (this.cleanup) { this.cleanup() }
}

handlePopoverToggle(event) {
// Keep ariaExpanded in sync with the actual popover state
this.triggerTarget.ariaExpanded = event.newState === 'open' ? 'true' : 'false'
}

inputChanged(e) {
this.updateTriggerContent()

Expand Down Expand Up @@ -62,9 +67,19 @@ export default class extends Controller {
}
}

openPopover(event) {
togglePopover(event) {
event.preventDefault()

if (this.triggerTarget.ariaExpanded === "true") {
this.closePopover()
} else {
this.openPopover(event)
}
}

openPopover(event) {
if (event) event.preventDefault()

this.updatePopoverPosition()
this.updatePopoverWidth()
this.triggerTarget.ariaExpanded = "true"
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_ui/combobox/combobox_popover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def default_attrs
data: {
ruby_ui__combobox_target: "popover",
action: %w[
toggle->ruby-ui--combobox#handlePopoverToggle
keydown.down->ruby-ui--combobox#keyDownPressed
keydown.up->ruby-ui--combobox#keyUpPressed
keydown.enter->ruby-ui--combobox#keyEnterPressed
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_ui/combobox/combobox_trigger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def default_attrs
data: {
placeholder: @placeholder,
ruby_ui__combobox_target: "trigger",
action: "ruby-ui--combobox#openPopover"
action: "ruby-ui--combobox#togglePopover"
},
aria: {
haspopup: "listbox",
Expand Down