11import { Controller } from "@hotwired/stimulus" ;
2- import { computePosition , autoUpdate , offset } from "@floating-ui/dom" ;
2+ import { computePosition , autoUpdate , offset , flip } from "@floating-ui/dom" ;
33
44// Connects to data-controller="ruby-ui--combobox"
55export default class extends Controller {
@@ -54,7 +54,8 @@ export default class extends Controller {
5454 openPopover ( event ) {
5555 event . preventDefault ( )
5656
57- this . popoverTarget . style . positionAnchor
57+ this . updatePopoverPosition ( )
58+ this . updatePopoverWidth ( )
5859 this . triggerTarget . ariaExpanded = "true"
5960 this . selectedItemIndex = null
6061 this . itemTargets . forEach ( item => item . ariaCurrent = "false" )
@@ -141,7 +142,8 @@ export default class extends Controller {
141142 updatePopoverPosition ( ) {
142143 this . cleanup = autoUpdate ( this . triggerTarget , this . popoverTarget , ( ) => {
143144 computePosition ( this . triggerTarget , this . popoverTarget , {
144- middleware : [ offset ( 4 ) ] ,
145+ placement : 'bottom-start' ,
146+ middleware : [ offset ( 4 ) , flip ( ) ] ,
145147 } ) . then ( ( { x, y } ) => {
146148 Object . assign ( this . popoverTarget . style , {
147149 left : `${ x } px` ,
@@ -150,4 +152,8 @@ export default class extends Controller {
150152 } ) ;
151153 } ) ;
152154 }
155+
156+ updatePopoverWidth ( ) {
157+ this . popoverTarget . style . width = `${ this . triggerTarget . offsetWidth } px`
158+ }
153159}
0 commit comments