Bedform UIMessages

Toast

Show a short-lived status message in the viewport.

Toast

Saved
*
number
*
string
*
boolean
*
*

Usage

import { Button } from "@bedform/ui/button";
import { Toast } from "@bedform/ui/toast";
import { useState } from "react";

export function SaveWorld() {
  const [saved, setSaved] = useState(false);

  return (
    <>
      <Button type="button" onClick={() => setSaved(true)}>
        Save
      </Button>
      <Toast
        open={saved}
        onOpenChange={(event) => setSaved(event.detail)}
        aria-label="World saved"
      >
        Saved
      </Toast>
    </>
  );
}

Open and close

Toast is closed by default. Use defaultOpen for an initial open state, or open to control it. A Toast closes itself when its duration ends, so pass onOpenChange with open and copy event.detail back into your state; otherwise the next open={true} does not reopen it.

The ref points to the Toast element, which is a Popover, so showPopover() and hidePopover() also open and close it.

Duration and position

duration defaults to 3000 ms. Set it to 0 to keep the Toast open until it is closed. Hovering the Toast or moving focus inside it pauses the remaining time. The default position is bottom-center; use top-start, top-center, top-end, bottom-start, or bottom-end for another viewport corner or edge.

<Toast defaultOpen duration={5000} position="top-end" aria-label="Settings saved">
  Saved
</Toast>

Color

Toast uses the same background variants as Tag: neutral, secondary, primary, informative, notice, warning, and realms-informative. It also accepts className and --ore-toast-* variables.

Events

oreui:openchange fires when the Popover state changes, whether the application or the timer changed it. onOpenChange receives it, and its detail is the new boolean state.

API

Toast renders a div, accepts every div attribute, and forwards its ref to the div.

PropTypeDefault
defaultOpenbooleanfalse
durationnumber3000
onOpenChange(event: CustomEvent<boolean>) => void—
openboolean—
position"top-start" | "top-center" | "top-end" | "bottom-start" | "bottom-center" | "bottom-end""bottom-center"
variant"neutral" | "secondary" | "primary" | "informative" | "notice" | "warning" | "realms-informative""neutral"

The Toast has no public child classes. Use className for layout and --ore-toast-* variables for component details.

CSS variables

VariablePurpose
--ore-toast-unitBase size unit
--ore-toast-insetDistance from the viewport edge
--ore-toast-backgroundToast background color
--ore-toast-foregroundToast text color
--ore-toast-borderToast border color
--ore-toast-shadowToast shadow color

Accessibility

Toast uses role="status", aria-live="polite", and aria-atomic="true" so short status messages do not interrupt the current task. Always provide an accessible name with aria-label or aria-labelledby. Keep the message concise and do not use Toast for actions that require a user decision.

On this page