From 1f9abdae614acbfa0be868a599071a601406f0f5 Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Tue, 1 Oct 2024 14:50:27 +0200 Subject: [PATCH] fix(Toast): improve focus styles --- src/theme/toast.ts | 4 +- src/theme/toaster.ts | 2 +- .../__snapshots__/Toast.spec.ts.snap | 64 +++++++++---------- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/theme/toast.ts b/src/theme/toast.ts index efceb55e..c68af30a 100644 --- a/src/theme/toast.ts +++ b/src/theme/toast.ts @@ -2,7 +2,7 @@ import type { ModuleOptions } from '../module' export default (options: Required) => ({ slots: { - root: 'relative overflow-hidden bg-white dark:bg-gray-900 shadow-lg rounded-lg ring ring-gray-200 dark:ring-gray-800 p-4 flex gap-2.5', + root: 'relative group overflow-hidden bg-white dark:bg-gray-900 shadow-lg rounded-lg ring ring-gray-200 dark:ring-gray-800 p-4 flex gap-2.5 focus:outline-none', wrapper: 'w-0 flex-1 flex flex-col gap-1', title: 'text-sm font-medium text-gray-900 dark:text-white', description: 'text-sm text-gray-500 dark:text-gray-400', @@ -16,10 +16,12 @@ export default (options: Required) => ({ variants: { color: { ...Object.fromEntries((options.theme.colors || []).map((color: string) => [color, { + root: `focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-${color}-500 dark:focus-visible:ring-${color}-400`, icon: `text-${color}-500 dark:text-${color}-400`, progress: `bg-${color}-500 dark:bg-${color}-400` }])), gray: { + root: 'focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-gray-900 dark:focus-visible:ring-white', icon: 'text-gray-900 dark:text-white', progress: 'bg-gray-900 dark:bg-white' } diff --git a/src/theme/toaster.ts b/src/theme/toaster.ts index e5ab27a7..d71f35df 100644 --- a/src/theme/toaster.ts +++ b/src/theme/toaster.ts @@ -1,6 +1,6 @@ export default { slots: { - viewport: 'fixed flex flex-col w-[calc(100%-2rem)] sm:w-96 z-[100] data-[expanded=true]:h-[--height]', + viewport: 'fixed flex flex-col w-[calc(100%-2rem)] sm:w-96 z-[100] data-[expanded=true]:h-[--height] focus:outline-none', base: 'absolute inset-x-0 z-[--index] transform-[--transform] data-[expanded=false]:data-[front=false]:h-[--front-height] data-[expanded=false]:data-[front=false]:*:invisible data-[state=closed]:animate-[toast-closed_200ms_ease-in-out] data-[state=closed]:data-[expanded=false]:data-[front=false]:animate-[toast-collapsed-closed_200ms_ease-in-out] data-[swipe=move]:transition-none transition-[transform,translate,height] duration-200 ease-out' }, variants: { diff --git a/test/components/__snapshots__/Toast.spec.ts.snap b/test/components/__snapshots__/Toast.spec.ts.snap index 36ed3332..aa85c66a 100644 --- a/test/components/__snapshots__/Toast.spec.ts.snap +++ b/test/components/__snapshots__/Toast.spec.ts.snap @@ -5,8 +5,8 @@ exports[`Toast > renders with actions correctly 1`] = `
-
    -
  1. +
      +
    1. Toast
      @@ -31,8 +31,8 @@ exports[`Toast > renders with avatar correctly 1`] = `
      -
        -
      1. +
          +
        1. Toast
          @@ -53,8 +53,8 @@ exports[`Toast > renders with class correctly 1`] = `
          -
            -
          1. +
              +
            1. Toast
              @@ -76,8 +76,8 @@ exports[`Toast > renders with close slot correctly 1`] = `
              -
                -
              1. +
                  +
                1. Toast
                  @@ -96,8 +96,8 @@ exports[`Toast > renders with closeIcon correctly 1`] = `
                  -
                    -
                  1. +
                      +
                    1. Toast
                      @@ -119,8 +119,8 @@ exports[`Toast > renders with color gray correctly 1`] = `
                      -
                        -
                      1. +
                          +
                        1. Toast
                          @@ -142,8 +142,8 @@ exports[`Toast > renders with description actions correctly 1`] = `
                          -
                            -
                          1. +
                              +
                            1. Toast
                              @@ -170,8 +170,8 @@ exports[`Toast > renders with description correctly 1`] = `
                              -
                                -
                              1. +
                                  +
                                1. Toast
                                  @@ -195,8 +195,8 @@ exports[`Toast > renders with description slot correctly 1`] = `
                                  -
                                    -
                                  1. +
                                      +
                                    1. Toast
                                      @@ -218,8 +218,8 @@ exports[`Toast > renders with icon correctly 1`] = `
                                      -
                                        -
                                      1. +
                                          +
                                        1. Toast
                                          @@ -240,8 +240,8 @@ exports[`Toast > renders with leading slot correctly 1`] = `
                                          -
                                            -
                                          1. Leading slot
                                            +
                                              +
                                            1. Leading slot
                                              Toast
                                              @@ -261,8 +261,8 @@ exports[`Toast > renders with title correctly 1`] = `
                                              -
                                                -
                                              1. +
                                                  +
                                                1. Toast
                                                  @@ -284,8 +284,8 @@ exports[`Toast > renders with title slot correctly 1`] = `
                                                  -
                                                    -
                                                  1. +
                                                      +
                                                    1. Title slot
                                                      @@ -307,8 +307,8 @@ exports[`Toast > renders with type correctly 1`] = `
                                                      -
                                                        -
                                                      1. +
                                                          +
                                                        1. Toast
                                                          @@ -330,8 +330,8 @@ exports[`Toast > renders with ui correctly 1`] = `
                                                          -
                                                            -
                                                          1. +
                                                              +
                                                            1. Toast
                                                              @@ -353,8 +353,8 @@ exports[`Toast > renders without close correctly 1`] = `
                                                              -
                                                                -
                                                              1. +
                                                                  +
                                                                1. Toast