From 1887ea345941080fa07eb153773826bcfe67e916 Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Mon, 24 Oct 2022 10:32:04 -0400 Subject: [PATCH] Updated logic for rendering sr text --- .../src/components/Banner/Banner.tsx | 10 ++++----- .../Banner/__tests__/Banner.test.tsx | 22 +++---------------- .../__snapshots__/Banner.test.tsx.snap | 5 ----- .../src/components/Banner/examples/Banner.md | 6 ++--- .../Banner/examples/BannerBasic.tsx | 18 +++++---------- .../Banner/examples/BannerStatus.tsx | 10 ++++----- 6 files changed, 20 insertions(+), 51 deletions(-) diff --git a/packages/react-core/src/components/Banner/Banner.tsx b/packages/react-core/src/components/Banner/Banner.tsx index ef0e3a648a9..1e2db401c5c 100644 --- a/packages/react-core/src/components/Banner/Banner.tsx +++ b/packages/react-core/src/components/Banner/Banner.tsx @@ -9,12 +9,10 @@ export interface BannerProps extends React.HTMLProps { className?: string; /** If set to true, the banner sticks to the top of its container */ isSticky?: boolean; - /** Text announced by screen readers to indicate the type of banner. Defaults to "${variant} banner" - * if this property is not passed in. - * - * Pass in null to omit this text from the banner when the banner does not convey status/severity. + /** Text announced by screen readers to indicate the type of banner. This prop should only + * be passed in when the banner conveys status/severity. */ - screenReaderText?: string | null; + screenReaderText?: string; /** Variant styles for the banner. */ variant?: 'default' | 'info' | 'danger' | 'success' | 'warning'; } @@ -36,7 +34,7 @@ export const Banner: React.FunctionComponent = ({ )} {...props} > - {screenReaderText !== null && {screenReaderText || `${variant} banner`}} + {screenReaderText && {screenReaderText}} {children} ); diff --git a/packages/react-core/src/components/Banner/__tests__/Banner.test.tsx b/packages/react-core/src/components/Banner/__tests__/Banner.test.tsx index b1befa38c9a..894f6ec2ae0 100644 --- a/packages/react-core/src/components/Banner/__tests__/Banner.test.tsx +++ b/packages/react-core/src/components/Banner/__tests__/Banner.test.tsx @@ -51,32 +51,16 @@ test('Renders with class name pf-m-info when "info" is passed to variant prop', expect(screen.getByText('Test')).toHaveClass('pf-m-info'); }); -test('Renders pf-u-screen-reader class by default for screenReaderText', () => { +test('Does not render pf-u-screen-reader class by default', () => { render(Test); - expect(screen.getByText('default banner')).toHaveClass('pf-u-screen-reader', { exact: true }); + expect(screen.getByText('Test')).not.toContainHTML(''); }); -test('Renders screenReaderText as "default banner" by default', () => { - render(Test); - expect(screen.getByText('default banner')).toBeInTheDocument(); -}); - -test('Renders screenReaderText as "success banner" when variant="success"', () => { - render(Test); - expect(screen.getByText('success banner')).toBeInTheDocument(); -}); - -test('Renders custom screenReaderText passed via prop', () => { +test('Renders screenReaderText passed via prop', () => { render(Test); expect(screen.getByText('Custom screen reader text')).toBeInTheDocument(); }); -test('Does not render with screen reader text when screenReaderText = null', () => { - render(Banner text); - - expect(screen.queryByText('default banner')).not.toBeInTheDocument(); -}); - test('Renders without pf-m-sticky by default', () => { render(Test); expect(screen.getByText('Test')).not.toHaveClass('pf-m-sticky'); diff --git a/packages/react-core/src/components/Banner/__tests__/__snapshots__/Banner.test.tsx.snap b/packages/react-core/src/components/Banner/__tests__/__snapshots__/Banner.test.tsx.snap index bd9c2619021..d595c3708d2 100644 --- a/packages/react-core/src/components/Banner/__tests__/__snapshots__/Banner.test.tsx.snap +++ b/packages/react-core/src/components/Banner/__tests__/__snapshots__/Banner.test.tsx.snap @@ -5,11 +5,6 @@ exports[`Matches the snapshot 1`] = `
- - default banner - Test
diff --git a/packages/react-core/src/components/Banner/examples/Banner.md b/packages/react-core/src/components/Banner/examples/Banner.md index ed9039eaf66..49876b514a6 100644 --- a/packages/react-core/src/components/Banner/examples/Banner.md +++ b/packages/react-core/src/components/Banner/examples/Banner.md @@ -17,16 +17,16 @@ import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon'; Banners can be styled with one of 5 different colors. A basic banner should only be used when the banner color does not represent status or severity. -The following example also passes in the `screenReaderText` property with a value of `null` to prevent visually hidden text meant for screen readers from rendering. When using a basic banner, a value of `null` or text that does not convey status/severity should be passed into `screenReaderText`. - ```ts file="./BannerBasic.tsx" + ``` ### Status -When a banner is used to convey status, it is advised to pass in an icon inside the banner to convey the status in a way besides just color. +When a banner is used to convey status, it is advised to pass in an icon inside the banner to convey the status in a way besides just color. The `screenReaderText` prop should also be passed in to convey the status/severity of the banner to users of certain assistive technologies such as screen readers. In the following example, a flex layout is used inside the banner content to show one possible way to create spacing between the icons and banner text. ```ts file="./BannerStatus.tsx" + ``` diff --git a/packages/react-core/src/components/Banner/examples/BannerBasic.tsx b/packages/react-core/src/components/Banner/examples/BannerBasic.tsx index c783287e59b..31ad5034525 100644 --- a/packages/react-core/src/components/Banner/examples/BannerBasic.tsx +++ b/packages/react-core/src/components/Banner/examples/BannerBasic.tsx @@ -3,22 +3,14 @@ import { Banner } from '@patternfly/react-core'; export const BannerBasic: React.FunctionComponent = () => ( <> - Default banner + Default banner
- - Blue banner - + Blue banner
- - Red banner - + Red banner
- - Green banner - + Green banner
- - Gold banner - + Gold banner ); diff --git a/packages/react-core/src/components/Banner/examples/BannerStatus.tsx b/packages/react-core/src/components/Banner/examples/BannerStatus.tsx index d77df9b45f0..016c067a5b0 100644 --- a/packages/react-core/src/components/Banner/examples/BannerStatus.tsx +++ b/packages/react-core/src/components/Banner/examples/BannerStatus.tsx @@ -8,7 +8,7 @@ import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon'; export const BannerStatus: React.FunctionComponent = () => ( <> - + @@ -17,7 +17,7 @@ export const BannerStatus: React.FunctionComponent = () => (
- + @@ -26,7 +26,7 @@ export const BannerStatus: React.FunctionComponent = () => (
- + @@ -35,7 +35,7 @@ export const BannerStatus: React.FunctionComponent = () => (
- + @@ -44,7 +44,7 @@ export const BannerStatus: React.FunctionComponent = () => (
- +