From 686e9f62332ed404825d2fc7d599ad85f872feee Mon Sep 17 00:00:00 2001 From: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com> Date: Tue, 1 Mar 2022 22:07:53 +0700 Subject: [PATCH] fix(ui-components): make Alert not dismissable (#45291) --- .../ui-components/src/alert/alert.stories.tsx | 11 +----- tools/ui-components/src/alert/alert.test.tsx | 38 ------------------- tools/ui-components/src/alert/alert.tsx | 19 +++------- .../src/alert/{index.tsx => index.ts} | 0 4 files changed, 7 insertions(+), 61 deletions(-) rename tools/ui-components/src/alert/{index.tsx => index.ts} (100%) diff --git a/tools/ui-components/src/alert/alert.stories.tsx b/tools/ui-components/src/alert/alert.stories.tsx index 8615e56bd3..974aad9207 100644 --- a/tools/ui-components/src/alert/alert.stories.tsx +++ b/tools/ui-components/src/alert/alert.stories.tsx @@ -7,8 +7,7 @@ const story = { component: Alert, argTypes: { children: { control: { type: 'text' } }, - className: { control: { type: 'text' } }, - dismissLabel: { control: { type: 'text' } } + className: { control: { type: 'text' } } } }; @@ -67,12 +66,4 @@ WithHeadingAndParagraphs.args = { ) }; -export const Dismissable = Template.bind({}); -Dismissable.args = { - children: 'Hello, Alert!', - variant: 'success', - dismissLabel: 'Close alert', - onDismiss: () => console.log('Close alert!') -}; - export default story; diff --git a/tools/ui-components/src/alert/alert.test.tsx b/tools/ui-components/src/alert/alert.test.tsx index 66df359e38..e1ba7b145d 100644 --- a/tools/ui-components/src/alert/alert.test.tsx +++ b/tools/ui-components/src/alert/alert.test.tsx @@ -1,5 +1,4 @@ import { render, screen } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; import React from 'react'; import { Alert } from './alert'; @@ -31,41 +30,4 @@ describe('', () => { expect(screen.getByRole('alert')).toHaveClass(expectedClass); }); - - it(`renders a button when "onDismiss" prop is present, and calls "onDismiss" when the button is clicked`, () => { - const onDismiss = jest.fn(); - render( - - Hello - - ); - const closeButton = screen.getByRole('button'); - - expect(screen.getByRole('alert')).toBeInTheDocument(); - expect(closeButton).toBeInTheDocument(); - - userEvent.click(closeButton); - - expect(onDismiss).toHaveBeenCalledTimes(1); - }); - - it('does NOT render a close button, when "onDismiss" prop is NOT used', () => { - render(Hello); - - expect(screen.getByRole('alert')).toBeInTheDocument(); - expect(screen.queryByRole('button')).not.toBeInTheDocument(); - }); - - it('sets "aria-label" of close button to "dismissText" prop', () => { - const expectedLabel = 'custom dismiss alert message'; - render( - - Hello - - ); - - expect( - screen.getByRole('button', { name: expectedLabel }) - ).toBeInTheDocument(); - }); }); diff --git a/tools/ui-components/src/alert/alert.tsx b/tools/ui-components/src/alert/alert.tsx index 865942111e..28e7331402 100644 --- a/tools/ui-components/src/alert/alert.tsx +++ b/tools/ui-components/src/alert/alert.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import { CloseButton } from '../close-button'; type AlertVariant = 'success' | 'info' | 'warning' | 'danger'; @@ -7,8 +6,6 @@ export interface AlertProps { children: React.ReactNode; className?: string; variant: AlertVariant; - dismissLabel?: string; - onDismiss?: () => void; } const variantClasses: Record = { @@ -19,30 +16,26 @@ const variantClasses: Record = { }; /** - * Basic UI component that provides contextual feedback + * `Alert` is used to display a short, important message that does not interrupt the user's workflow. + * + * `Alert` is not dismissable. */ export function Alert({ children, className, - variant, - dismissLabel = 'Close', - onDismiss + variant }: AlertProps): JSX.Element { - const isDismissable = !!onDismiss; const variantClass = variantClasses[variant]; const classes = [ - 'flex items-start p-4 mb-6 border border-transparent break-words', + 'p-4 mb-6 border border-transparent break-words', variantClass, className ].join(' '); return (
-
{children}
- {isDismissable && ( - - )} + {children}
); } diff --git a/tools/ui-components/src/alert/index.tsx b/tools/ui-components/src/alert/index.ts similarity index 100% rename from tools/ui-components/src/alert/index.tsx rename to tools/ui-components/src/alert/index.ts