Skip to content

Commit 9846ec4

Browse files
committed
Merge branch 'allow-to-pass-strategy-option-to-dropdown-menu' of github.com:lsouoliveira/ruby_ui into allow-to-pass-strategy-option-to-dropdown-menu
2 parents 1b31533 + 2189098 commit 9846ec4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/ruby_ui/dropdown_menu/dropdown_menu.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def default_attrs
1717
{
1818
class: [
1919
"group/dropdown-menu",
20-
(@strategy == "absolute") ? "is-absolute" : "is-fixed"
20+
(strategy == "absolute") ? "is-absolute" : "is-fixed"
2121
],
2222
data: {
2323
controller: "ruby-ui--dropdown-menu",
@@ -26,5 +26,9 @@ def default_attrs
2626
}
2727
}
2828
end
29+
30+
def strategy
31+
@_strategy ||= @options[:strategy] || "absolute"
32+
end
2933
end
3034
end

lib/ruby_ui/dropdown_menu/dropdown_menu_controller.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { Controller } from "@hotwired/stimulus";
2-
import { computePosition, flip, shift, offset, autoUpdate } from "@floating-ui/dom";
2+
import {
3+
computePosition,
4+
flip,
5+
shift,
6+
offset,
7+
autoUpdate,
8+
} from "@floating-ui/dom";
39

410
export default class extends Controller {
511
static targets = ["trigger", "content", "menuItem"];
@@ -17,15 +23,17 @@ export default class extends Controller {
1723
connect() {
1824
this.boundHandleKeydown = this.#handleKeydown.bind(this); // Bind the function so we can remove it later
1925
this.selectedIndex = -1;
20-
this.cleanup = autoUpdate(
26+
this.autoUpdateCleanup = autoUpdate(
2127
this.triggerTarget,
2228
this.contentTarget,
2329
this.#computeTooltip.bind(this),
2430
);
2531
}
2632

2733
disconnect() {
28-
this.cleanup();
34+
if (this.autoUpdateCleanup) {
35+
this.autoUpdateCleanup();
36+
}
2937
}
3038

3139
#computeTooltip() {

0 commit comments

Comments
 (0)