base-ui icon indicating copy to clipboard operation
base-ui copied to clipboard

[Bug][Dialog] Not able to use sonner/react-hot-toast etc with dialog component

Open sreehari-credhive opened this issue 1 year ago • 3 comments

Bug report

Current behavior

  • I am using base ui dialog in 2 of my projects
  • one repo uses sonner for toasts another one uses react hot toast
  • when i trigger a toast while the dialog is open toast is always behind the backdrop

Expected behavior

  • toast should render on top
  • I am migrating dialog from radix to base -> it works fine in radix dialog

Base UI version

1.0.0-beta.3

Which browser are you using?

Chrome

Which OS are you using?

Mac OS

sreehari-credhive avatar Oct 08 '25 11:10 sreehari-credhive

You need to set a z-index on the toasts to be higher than the dialog and ensure the toasts are portaled outside your root app element.

position: relative; z-index: 1 will work fine (this is what our Toast demo does) provided the toast viewports of sonner and react-hot-toast are outside of your main root layout element that has isolation: isolate applied. Base UI has no opinions regarding stacking order, aside from this recommendation for portals. However this can cause toasts rendered inside that element to always be stuck "behind" the Base UI portaled dialog, so you must make sure toasts are outside of that container as well.

That should fix it, but the example you gave is not really a reproducible example given this is interaction between multiple dependencies and the overall app layout's CSS stacking order

atomiks avatar Oct 08 '25 11:10 atomiks

@atomiks i was able to fix this by moving the toast outside the isolation - isolated layout

import "./styles.css";
import { Toaster } from "sonner";

import ExampleDialog from "./Dialog";
export default function App() {
  return (
    <div>
      <Toaster />
      <div className="App">
        <ExampleDialog />
      </div>
    </div>
  );
}

Thanks for the reply - i guess you can close the issue

sreehari-credhive avatar Oct 08 '25 12:10 sreehari-credhive

Yeah I figured it was inside of it, in which case z-index doesn't work no matter how high the value

atomiks avatar Oct 08 '25 12:10 atomiks