diff --git a/packages/react-core/src/components/Alert/Alert.tsx b/packages/react-core/src/components/Alert/Alert.tsx index fc59afd826b..b3dcf425923 100644 --- a/packages/react-core/src/components/Alert/Alert.tsx +++ b/packages/react-core/src/components/Alert/Alert.tsx @@ -35,6 +35,13 @@ export interface AlertProps extends Omit, 'actio isLiveRegion?: boolean; } +interface AlertContext { + title: React.ReactNode; + variantLabel?: string; +} + +export const AlertContext = React.createContext(null); + const Alert: React.FunctionComponent = ({ variant = AlertVariant.info, isInline = false, @@ -49,7 +56,7 @@ const Alert: React.FunctionComponent = ({ ouiaId = null, ...props }: AlertProps & InjectedOuiaProps) => { - const readerTitle = ( + const getHeadingContent = ( {variantLabel} {title} @@ -78,11 +85,13 @@ const Alert: React.FunctionComponent = ({ })} > -

{readerTitle}

+

{getHeadingContent}

{children &&
{children}
} - {action && ( -
{React.cloneElement(action as any, { title, variantLabel })}
- )} + + {action && (typeof action === 'object' || typeof action === 'string') && ( +
{action}
+ )} +
); }; diff --git a/packages/react-core/src/components/Alert/AlertActionCloseButton.tsx b/packages/react-core/src/components/Alert/AlertActionCloseButton.tsx index 5956dd268c7..e25a2752351 100644 --- a/packages/react-core/src/components/Alert/AlertActionCloseButton.tsx +++ b/packages/react-core/src/components/Alert/AlertActionCloseButton.tsx @@ -1,6 +1,7 @@ import * as React from 'react'; import { Button, ButtonVariant, ButtonProps } from '../Button'; import TimesIcon from '@patternfly/react-icons/dist/js/icons/times-icon'; +import { AlertContext } from '..'; interface AlertActionCloseButtonProps extends ButtonProps { /** Additional classes added to the AlertActionCloseButton */ @@ -18,16 +19,19 @@ export const AlertActionCloseButton = ({ className = '', onClose = () => undefined as any, 'aria-label': ariaLabel = '', - title, - variantLabel = '', + variantLabel, ...props }: AlertActionCloseButtonProps) => ( - + + {({ title, variantLabel: alertVariantLabel }) => ( + + )} + ); diff --git a/packages/react-core/src/components/Alert/AlertActionLink.tsx b/packages/react-core/src/components/Alert/AlertActionLink.tsx index 1daeeacf6fc..c947498786f 100644 --- a/packages/react-core/src/components/Alert/AlertActionLink.tsx +++ b/packages/react-core/src/components/Alert/AlertActionLink.tsx @@ -10,7 +10,7 @@ export interface AlertActionLinkProps extends ButtonProps { export const AlertActionLink: React.FunctionComponent = ({ className = '', - children = '', + children, ...props }: AlertActionLinkProps) => (