From 13c50c7df84a88fdadb7a1d1065029b79ded1881 Mon Sep 17 00:00:00 2001 From: Seth Horsley Date: Sun, 19 Oct 2025 05:38:40 -0400 Subject: [PATCH 1/2] add toggle to combobox trigger --- lib/ruby_ui/combobox/combobox_controller.js | 17 ++++++++++++++++- lib/ruby_ui/combobox/combobox_popover.rb | 1 + lib/ruby_ui/combobox/combobox_trigger.rb | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/ruby_ui/combobox/combobox_controller.js b/lib/ruby_ui/combobox/combobox_controller.js index 8d1d9d32..d1932772 100644 --- a/lib/ruby_ui/combobox/combobox_controller.js +++ b/lib/ruby_ui/combobox/combobox_controller.js @@ -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() @@ -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" diff --git a/lib/ruby_ui/combobox/combobox_popover.rb b/lib/ruby_ui/combobox/combobox_popover.rb index 68b937f4..6e089f8b 100644 --- a/lib/ruby_ui/combobox/combobox_popover.rb +++ b/lib/ruby_ui/combobox/combobox_popover.rb @@ -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 diff --git a/lib/ruby_ui/combobox/combobox_trigger.rb b/lib/ruby_ui/combobox/combobox_trigger.rb index be32a761..56ea757b 100644 --- a/lib/ruby_ui/combobox/combobox_trigger.rb +++ b/lib/ruby_ui/combobox/combobox_trigger.rb @@ -22,7 +22,7 @@ def default_attrs { type: "button", class: [ - "flex h-full w-full items-center whitespace-nowrap rounded-md text-sm ring-offset-background transition-colors border border-input bg-background h-10 px-4 py-2 justify-between", + "flex h-full w-full items-center whitespace-nowrap rounded-md text-sm ring-offset-background transition-colors border border-input bg-background h-9 px-4 py-2 justify-between", "hover:bg-accent hover:text-accent-foreground", "disabled:pointer-events-none disabled:opacity-50", "aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-disabled:cursor-not-allowed", @@ -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", From aa0a347885f9bf46fec86977c734a7d54a0136af Mon Sep 17 00:00:00 2001 From: Seth Horsley Date: Sun, 19 Oct 2025 05:42:41 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ruby_ui/combobox/combobox_trigger.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ruby_ui/combobox/combobox_trigger.rb b/lib/ruby_ui/combobox/combobox_trigger.rb index 56ea757b..892d4b91 100644 --- a/lib/ruby_ui/combobox/combobox_trigger.rb +++ b/lib/ruby_ui/combobox/combobox_trigger.rb @@ -22,7 +22,7 @@ def default_attrs { type: "button", class: [ - "flex h-full w-full items-center whitespace-nowrap rounded-md text-sm ring-offset-background transition-colors border border-input bg-background h-9 px-4 py-2 justify-between", + "flex h-full w-full items-center whitespace-nowrap rounded-md text-sm ring-offset-background transition-colors border border-input bg-background h-10 px-4 py-2 justify-between", "hover:bg-accent hover:text-accent-foreground", "disabled:pointer-events-none disabled:opacity-50", "aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-disabled:cursor-not-allowed",