+
+
+
+
+## Show a toast
+The `Toast` component has an imperative API for getting displayed. It will not be displayed just because it is part of the DOM.
+In order to show the Toast, you have to get a reference to the `Toast` DOM element and call the `show`-method.
+You can either access the DOM element by using a React `ref` or work with IDs.
+
+**Example**
+```jsx
+export const MyComponentWithAToast() {
+ const toast = useRef();
+
+ const showToast = () => {
+ toast.current.show();
+ };
+ return (
+
+
+ This is my Toast!
+
+ );
+}
+```
+
+
+
diff --git a/packages/main/src/webComponents/Toast/Toast.stories.tsx b/packages/main/src/webComponents/Toast/Toast.stories.tsx
index bdebeb06c64..57c1ca199c0 100644
--- a/packages/main/src/webComponents/Toast/Toast.stories.tsx
+++ b/packages/main/src/webComponents/Toast/Toast.stories.tsx
@@ -2,11 +2,17 @@ import { number, select } from '@storybook/addon-knobs';
import { Button } from '@ui5/webcomponents-react/lib/Button';
import { Toast } from '@ui5/webcomponents-react/lib/Toast';
import { ToastPlacement } from '@ui5/webcomponents-react/lib/ToastPlacement';
-import React from 'react';
+import React, { useRef } from 'react';
+import mdx from './Toast.mdx';
export default {
title: 'UI5 Web Components / Toast',
- component: Toast
+ component: Toast,
+ parameters: {
+ docs: {
+ page: mdx
+ }
+ }
};
const showToast = () => {
@@ -14,20 +20,26 @@ const showToast = () => {
document.querySelector('#web_components_react_toast_demo').show();
};
-export const generatedDefaultStory = () => (
- <>
-
- Some Content
-
-
- >
-);
+export const generatedDefaultStory = () => {
+ const toast = useRef();
+
+ const showToast = () => {
+ toast.current.show();
+ };
+ return (
+ <>
+
+ Some Content
+
+
+ >
+ );
+};
generatedDefaultStory.story = {
- name: 'Generated default story'
+ name: 'Default story'
};