diff --git a/packages/react-core/src/components/NotificationBadge/NotificationBadge.tsx b/packages/react-core/src/components/NotificationBadge/NotificationBadge.tsx index 34d00d83357..4bedc1d1f4e 100644 --- a/packages/react-core/src/components/NotificationBadge/NotificationBadge.tsx +++ b/packages/react-core/src/components/NotificationBadge/NotificationBadge.tsx @@ -1,7 +1,5 @@ import * as React from 'react'; import { Button, ButtonVariant, ButtonProps } from '../Button'; -import { css } from '@patternfly/react-styles'; -import styles from '@patternfly/react-styles/css/components/NotificationBadge/notification-badge'; import AttentionBellIcon from '@patternfly/react-icons/dist/esm/icons/attention-bell-icon'; import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon'; @@ -42,20 +40,26 @@ export const NotificationBadge: React.FunctionComponent isExpanded = false, ...props }: NotificationBadgeProps) => { - let notificationChild = icon; - if (children !== undefined) { - notificationChild = children; - } else if (variant === NotificationBadgeVariant.attention) { - notificationChild = attentionIcon; - } + const hasCount = count > 0; + const hasChildren = children !== undefined; + const isAttention = variant === NotificationBadgeVariant.attention; + + const notificationIcon = isAttention ? attentionIcon : icon; + const notificationContent = hasChildren ? children : notificationIcon; + + const [iconProp, notificationChild] = hasCount ? [notificationContent, count] : [undefined, notificationContent]; + return ( - ); }; diff --git a/packages/react-core/src/components/NotificationBadge/__tests__/NotificationBadge.test.tsx b/packages/react-core/src/components/NotificationBadge/__tests__/NotificationBadge.test.tsx index 9090d062955..d94a1c45ff6 100644 --- a/packages/react-core/src/components/NotificationBadge/__tests__/NotificationBadge.test.tsx +++ b/packages/react-core/src/components/NotificationBadge/__tests__/NotificationBadge.test.tsx @@ -30,14 +30,14 @@ test('Renders with aria-expanded="true" when isExpanded is passed in.', () => { expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'true'); }); -test('Does not render with .pf-m-expanded when isExpanded is not passed in.', () => { +test('Does not render with .pf-m-clicked when isExpanded is not passed in.', () => { render(); - expect(screen.getByRole('button').firstChild).not.toHaveClass('pf-m-expanded'); + expect(screen.getByRole('button')).not.toHaveClass('pf-m-clicked'); }); -test('Renders with .pf-m-expanded when isExpanded is passed in.', () => { +test('Renders with .pf-m-clicked when isExpanded is passed in.', () => { render(); - expect(screen.getByRole('button').firstChild).toHaveClass('pf-m-expanded'); + expect(screen.getByRole('button')).toHaveClass('pf-m-clicked'); }); diff --git a/packages/react-core/src/components/NotificationBadge/__tests__/__snapshots__/NotificationBadge.test.tsx.snap b/packages/react-core/src/components/NotificationBadge/__tests__/__snapshots__/NotificationBadge.test.tsx.snap index 4b10037ed99..861ea96ea4a 100644 --- a/packages/react-core/src/components/NotificationBadge/__tests__/__snapshots__/NotificationBadge.test.tsx.snap +++ b/packages/react-core/src/components/NotificationBadge/__tests__/__snapshots__/NotificationBadge.test.tsx.snap @@ -5,14 +5,14 @@ exports[`NotificationBadge count 1`] = ` `; @@ -42,17 +38,13 @@ exports[`false NotificationBadge needs attention 1`] = ` `; @@ -62,17 +54,13 @@ exports[`true NotificationBadge needs attention 1`] = ` `; diff --git a/packages/react-core/src/components/NotificationBadge/examples/NotificationBadge.md b/packages/react-core/src/components/NotificationBadge/examples/NotificationBadge.md index 6b0ebe5e526..f3a0c72d4f6 100644 --- a/packages/react-core/src/components/NotificationBadge/examples/NotificationBadge.md +++ b/packages/react-core/src/components/NotificationBadge/examples/NotificationBadge.md @@ -6,7 +6,6 @@ propComponents: ['NotificationBadge'] --- import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon'; -import './notificationBadge.css'; ## Examples diff --git a/packages/react-core/src/components/NotificationBadge/examples/NotificationBadgeBasic.tsx b/packages/react-core/src/components/NotificationBadge/examples/NotificationBadgeBasic.tsx index eeffbdd6d43..510ce8c4376 100644 --- a/packages/react-core/src/components/NotificationBadge/examples/NotificationBadgeBasic.tsx +++ b/packages/react-core/src/components/NotificationBadge/examples/NotificationBadgeBasic.tsx @@ -19,7 +19,7 @@ export const NotificationBadgeBasic: React.FunctionComponent = () => { }; return ( -
+ <> { aria-label="Basic notification badge with attention variant" isExpanded={attentionExpanded} /> -
+ ); }; diff --git a/packages/react-core/src/components/NotificationBadge/examples/NotificationBadgeWithCount.tsx b/packages/react-core/src/components/NotificationBadge/examples/NotificationBadgeWithCount.tsx index 411c2ce5fc1..68c1b0220c5 100644 --- a/packages/react-core/src/components/NotificationBadge/examples/NotificationBadgeWithCount.tsx +++ b/packages/react-core/src/components/NotificationBadge/examples/NotificationBadgeWithCount.tsx @@ -19,7 +19,7 @@ export const NotificationBadgeWithCount: React.FunctionComponent = () => { }; return ( -
+ <> { isExpanded={attentionExpanded} count={10} /> -
+ ); }; diff --git a/packages/react-core/src/components/NotificationBadge/examples/notificationBadge.css b/packages/react-core/src/components/NotificationBadge/examples/notificationBadge.css deleted file mode 100644 index 562a46f51c3..00000000000 --- a/packages/react-core/src/components/NotificationBadge/examples/notificationBadge.css +++ /dev/null @@ -1,4 +0,0 @@ -#ws-react-c-notification-badge-basic, -#ws-react-c-notification-badge-with-count { - background-color: var(--pf-v5-global--BackgroundColor--dark-100); -} diff --git a/packages/react-integration/cypress/integration/notificationbadge.spec.ts b/packages/react-integration/cypress/integration/notificationbadge.spec.ts index a19465a314d..21472dff214 100644 --- a/packages/react-integration/cypress/integration/notificationbadge.spec.ts +++ b/packages/react-integration/cypress/integration/notificationbadge.spec.ts @@ -4,15 +4,15 @@ describe('Notification Badge Demo Test', () => { }); it('Verify notification badge is unread', () => { - cy.get('.pf-v5-c-notification-badge').first().should('have.class', 'pf-m-unread'); - cy.get('.pf-v5-c-notification-badge').last().should('have.class', 'pf-m-attention'); - cy.get('.pf-v5-c-notification-badge__count').contains('30'); + cy.get('#notification-demo-badge1').should('have.class', 'pf-m-unread'); + cy.get('#notification-demo-badge2').should('have.class', 'pf-m-attention'); + cy.get('#notification-demo-badge2').contains('30'); }); it('Verify notification badge is read after click', () => { cy.get('#notification-demo-badge1').click(); - cy.get('.pf-v5-c-notification-badge').first().should('have.class', 'pf-m-read'); + cy.get('#notification-demo-badge1').should('have.class', 'pf-m-read'); cy.get('#notification-demo-badge2').click(); - cy.get('.pf-v5-c-notification-badge').last().should('have.class', 'pf-m-read'); + cy.get('#notification-demo-badge2').should('have.class', 'pf-m-read'); }); });