Skip to content

Commit 12a5b9e

Browse files
committed
[Bug Fix] Anchor toast items per position; add Text Only example
Items now anchor inline to top:0 (top positions) or bottom:0 (bottom positions) via the toaster controller's reflow. Previously every item was hardcoded to bottom:0 in the Tailwind class list, so for top-* positions the OL grew downward on hover, pulling the front toast out from under the cursor and causing an enter/leave thrash. Add a Text Only example after Promise: default variant with title only, no description, no icon, no action — matches shadcn sonner's Text Only demo.
1 parent 1752abd commit 12a5b9e

5 files changed

Lines changed: 9 additions & 3 deletions

File tree

docs/app/javascript/controllers/ruby_ui/toaster_controller.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ export default class extends Controller {
202202
el.style.setProperty("--scale", String(scale))
203203
el.style.setProperty("--y-offset", `${ty}px`)
204204
el.style.transformOrigin = isBottom ? "center bottom" : "center top"
205+
el.style.top = isBottom ? "auto" : "0"
206+
el.style.bottom = isBottom ? "0" : "auto"
205207
el.style.transform = `translate3d(0, ${ty}px, 0) scale(${scale})`
206208
el.style.zIndex = String(1000 - i)
207209
el.style.pointerEvents = visible ? "auto" : "none"

docs/app/javascript/controllers/toast_demo_controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const PRESETS = {
77
warning: { variant: "warning", title: "Event start time cannot be earlier than 8am" },
88
error: { variant: "error", title: "Event has not been created" },
99
with_action: { variant: "default", title: "Event has been created", action: { label: "Undo" } },
10+
text_only: { variant: "default", title: "Event has been created" },
1011
}
1112

1213
export default class extends Controller {

docs/app/views/docs/toast.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ class Views::Docs::Toast < Views::Base
1010
{key: "warning", label: "Warning", title: "Event start time cannot be earlier than 8am"},
1111
{key: "error", label: "Error", title: "Event has not been created"},
1212
{key: "with_action", label: "With Action", title: "Event has been created", action_label: "Undo"},
13-
{key: "promise", label: "Promise", title: nil}
13+
{key: "promise", label: "Promise", title: nil},
14+
{key: "text_only", label: "Text Only", title: "Event has been created"}
1415
].freeze
1516

1617
POSITIONS = %w[top-left top-center top-right bottom-left bottom-center bottom-right].freeze

gem/lib/ruby_ui/toast/toast_item.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def default_attrs
5454

5555
def item_classes
5656
<<~CLASSES.tr("\n", " ").squeeze(" ").strip
57-
group/toast pointer-events-auto absolute bottom-0 left-0 right-0
58-
origin-bottom flex w-[356px] max-w-full items-center gap-3
57+
group/toast pointer-events-auto absolute left-0 right-0
58+
flex w-[356px] max-w-full items-center gap-3
5959
overflow-hidden rounded-lg border bg-popover text-popover-foreground
6060
border-border p-4 pr-8 shadow-lg
6161
transition-[transform,opacity] duration-300 ease-out

gem/lib/ruby_ui/toast/toaster_controller.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ export default class extends Controller {
202202
el.style.setProperty("--scale", String(scale))
203203
el.style.setProperty("--y-offset", `${ty}px`)
204204
el.style.transformOrigin = isBottom ? "center bottom" : "center top"
205+
el.style.top = isBottom ? "auto" : "0"
206+
el.style.bottom = isBottom ? "0" : "auto"
205207
el.style.transform = `translate3d(0, ${ty}px, 0) scale(${scale})`
206208
el.style.zIndex = String(1000 - i)
207209
el.style.pointerEvents = visible ? "auto" : "none"

0 commit comments

Comments
 (0)