From e512a2556160a14d77215e5c77ed4f12e630d483 Mon Sep 17 00:00:00 2001 From: Hugo Richard Date: Thu, 25 Sep 2025 14:12:29 +0100 Subject: [PATCH 1/4] feat(useToast): add `maxToasts` global configuration --- src/runtime/composables/useToast.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/runtime/composables/useToast.ts b/src/runtime/composables/useToast.ts index e2f05cf50b..9a16b582ac 100644 --- a/src/runtime/composables/useToast.ts +++ b/src/runtime/composables/useToast.ts @@ -1,5 +1,5 @@ import { ref, nextTick } from 'vue' -import { useState } from '#imports' +import { useState, useAppConfig } from '#imports' import type { ToastProps, ToastEmits } from '../types' import type { EmitsToProps } from '../types/utils' @@ -9,8 +9,9 @@ export interface Toast extends Omit, EmitsToProps('toasts', () => []) - const maxToasts = 5 + const maxToasts = (appConfig.toaster as any)?.maxToasts ?? 5 const running = ref(false) const queue: Toast[] = [] From a81d6913b45e3bbd063243d0d1b17ee616d4ba97 Mon Sep 17 00:00:00 2001 From: Hugo Richard Date: Mon, 29 Sep 2025 11:16:53 +0100 Subject: [PATCH 2/4] use injectionKey --- src/runtime/components/Toaster.vue | 14 +++++++++++--- src/runtime/composables/useToast.ts | 12 +++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/runtime/components/Toaster.vue b/src/runtime/components/Toaster.vue index ad6d47a02c..5ecc7ee219 100644 --- a/src/runtime/components/Toaster.vue +++ b/src/runtime/components/Toaster.vue @@ -27,6 +27,11 @@ export interface ToasterProps extends Omit * @defaultValue true */ portal?: boolean | string | HTMLElement + /** + * Maximum number of toasts to display at once. + * @defaultValue 5 + */ + max?: number class?: any ui?: Toaster['slots'] } @@ -41,11 +46,11 @@ export default { + + diff --git a/docs/content/docs/2.components/toast.md b/docs/content/docs/2.components/toast.md index 1f44cf35f2..a14dcd740f 100644 --- a/docs/content/docs/2.components/toast.md +++ b/docs/content/docs/2.components/toast.md @@ -256,18 +256,44 @@ name: 'toast-example' :toaster-duration-example :: -::note{to="https://github.com/nuxt/ui/blob/v4/docs/app/app.config.ts#L5"} +::note{to="https://github.com/nuxt/ui/blob/v4/docs/app/app.config.ts#L4"} In this example, we use the `AppConfig` to configure the `duration` prop of the `Toaster` component globally. :: -### Stacked toasts +### Change global max :badge{label="Soon"} -Set the `toaster.expand` prop to `false` on the [App](/docs/components/app#props) component to display stacked toasts. +Change the `toaster.max` prop on the [App](/docs/components/app#props) component to change the max number of toasts displayed at once. -::tip -You can hover over the toasts to expand them. This will also pause the timer of the toasts. +```vue [app.vue] + + + +``` + +::component-example +--- +prettier: true +name: 'toast-example' +--- + +#options +:toaster-max-example +:: + +::note{to="https://github.com/nuxt/ui/blob/v4/docs/app/app.config.ts#L5"} +In this example, we use the `AppConfig` to configure the `max` prop of the `Toaster` component globally. :: +### Stacked toasts + +Set the `toaster.expand` prop to `false` on the [App](/docs/components/app#props) component to display stacked toasts (inspired by [Sonner](https://sonner.emilkowal.ski/)). + ```vue [app.vue]