Skip to content

Commit 3c89b31

Browse files
pierry01claude
andcommitted
[Improvement] Combobox: configurable popover placement
Adds a `placement` value (default `bottom-start`, unchanged behavior) so consumers can position the popover differently, e.g. `left-start`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent df9ee88 commit 3c89b31

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

gem/lib/ruby_ui/combobox/combobox.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
module RubyUI
44
class Combobox < Base
5-
def initialize(term: nil, **)
5+
def initialize(term: nil, placement: "bottom-start", **)
66
@term = term
7+
@placement = placement
78
super(**)
89
end
910

@@ -19,6 +20,7 @@ def default_attrs
1920
data: {
2021
controller: "ruby-ui--combobox",
2122
ruby_ui__combobox_term_value: @term,
23+
ruby_ui__combobox_placement_value: @placement,
2224
action: "turbo:morph@window->ruby-ui--combobox#updateTriggerContent"
2325
}
2426
}

gem/lib/ruby_ui/combobox/combobox_controller.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { computePosition, autoUpdate, offset, flip } from "@floating-ui/dom";
55
export default class extends Controller {
66
static values = {
77
term: String,
8-
minPopoverWidth: { type: Number, default: 240 }
8+
minPopoverWidth: { type: Number, default: 240 },
9+
placement: { type: String, default: 'bottom-start' }
910
}
1011

1112
static targets = [
@@ -175,7 +176,7 @@ export default class extends Controller {
175176
updatePopoverPosition() {
176177
this.cleanup = autoUpdate(this.triggerTarget, this.popoverTarget, () => {
177178
computePosition(this.triggerTarget, this.popoverTarget, {
178-
placement: 'bottom-start',
179+
placement: this.placementValue,
179180
middleware: [offset(4), flip()],
180181
}).then(({ x, y }) => {
181182
Object.assign(this.popoverTarget.style, {

0 commit comments

Comments
 (0)