Skip to content

Commit

Permalink
feat(Alert): add sr variant customization (patternfly#1056)
Browse files Browse the repository at this point in the history
defaults to current label if undefined
  • Loading branch information
kmcfaul authored and tlabaj committed Dec 19, 2018
1 parent f38c10a commit 0b8d241
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/patternfly-4/react-core/src/components/Alert/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,36 @@ const propTypes = {
/** additional classes added to the Alert */
className: PropTypes.string,
/** Adds accessible text to the Alert */
'aria-label': PropTypes.string
'aria-label': PropTypes.string,
/** Variant label text for screen readers */
variantLabel: PropTypes.string
};

const defaultProps = {
'aria-label': undefined,
action: null,
title: '',
children: '',
className: ''
className: '',
variantLabel: null
};

const getDefaultAriaLabel = variant => `${capitalize(AlertVariant[variant])} Notification`;

const Alert = ({
variant,
variantLabel,
'aria-label': ariaLabel = getDefaultAriaLabel(variant),
action,
title,
children,
className,
...props
}) => {
variantLabel = variantLabel || capitalize(AlertVariant[variant]);
const readerTitle = (
<React.Fragment>
<span className={css(accessibleStyles.srOnly)}>{capitalize(AlertVariant[variant])}: </span>
<span className={css(accessibleStyles.srOnly)}>{variantLabel}: </span>
{title}
</React.Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ exports[`Alert - danger Action 1`] = `
className=""
title=""
variant="danger"
variantLabel={null}
>
<div
aria-label="Danger Notification"
Expand Down Expand Up @@ -168,6 +169,7 @@ exports[`Alert - danger Action and Title 1`] = `
className=""
title="Some title"
variant="danger"
variantLabel={null}
>
<div
aria-label="Danger Notification"
Expand Down Expand Up @@ -289,6 +291,7 @@ exports[`Alert - danger Body 1`] = `
className=""
title=""
variant="danger"
variantLabel={null}
>
<div
aria-label="Danger Notification"
Expand Down Expand Up @@ -406,6 +409,7 @@ exports[`Alert - danger Custom aria label 1`] = `
className=""
title="Some title"
variant="danger"
variantLabel={null}
>
<div
aria-label="Custom aria label for danger"
Expand Down Expand Up @@ -527,6 +531,7 @@ exports[`Alert - danger Title 1`] = `
className=""
title="Some title"
variant="danger"
variantLabel={null}
>
<div
aria-label="Danger Notification"
Expand Down Expand Up @@ -644,6 +649,7 @@ exports[`Alert - info Action 1`] = `
className=""
title=""
variant="info"
variantLabel={null}
>
<div
aria-label="Info Notification"
Expand Down Expand Up @@ -769,6 +775,7 @@ exports[`Alert - info Action and Title 1`] = `
className=""
title="Some title"
variant="info"
variantLabel={null}
>
<div
aria-label="Info Notification"
Expand Down Expand Up @@ -890,6 +897,7 @@ exports[`Alert - info Body 1`] = `
className=""
title=""
variant="info"
variantLabel={null}
>
<div
aria-label="Info Notification"
Expand Down Expand Up @@ -1007,6 +1015,7 @@ exports[`Alert - info Custom aria label 1`] = `
className=""
title="Some title"
variant="info"
variantLabel={null}
>
<div
aria-label="Custom aria label for info"
Expand Down Expand Up @@ -1128,6 +1137,7 @@ exports[`Alert - info Title 1`] = `
className=""
title="Some title"
variant="info"
variantLabel={null}
>
<div
aria-label="Info Notification"
Expand Down Expand Up @@ -1245,6 +1255,7 @@ exports[`Alert - success Action 1`] = `
className=""
title=""
variant="success"
variantLabel={null}
>
<div
aria-label="Success Notification"
Expand Down Expand Up @@ -1370,6 +1381,7 @@ exports[`Alert - success Action and Title 1`] = `
className=""
title="Some title"
variant="success"
variantLabel={null}
>
<div
aria-label="Success Notification"
Expand Down Expand Up @@ -1491,6 +1503,7 @@ exports[`Alert - success Body 1`] = `
className=""
title=""
variant="success"
variantLabel={null}
>
<div
aria-label="Success Notification"
Expand Down Expand Up @@ -1608,6 +1621,7 @@ exports[`Alert - success Custom aria label 1`] = `
className=""
title="Some title"
variant="success"
variantLabel={null}
>
<div
aria-label="Custom aria label for success"
Expand Down Expand Up @@ -1729,6 +1743,7 @@ exports[`Alert - success Title 1`] = `
className=""
title="Some title"
variant="success"
variantLabel={null}
>
<div
aria-label="Success Notification"
Expand Down Expand Up @@ -1846,6 +1861,7 @@ exports[`Alert - warning Action 1`] = `
className=""
title=""
variant="warning"
variantLabel={null}
>
<div
aria-label="Warning Notification"
Expand Down Expand Up @@ -1971,6 +1987,7 @@ exports[`Alert - warning Action and Title 1`] = `
className=""
title="Some title"
variant="warning"
variantLabel={null}
>
<div
aria-label="Warning Notification"
Expand Down Expand Up @@ -2092,6 +2109,7 @@ exports[`Alert - warning Body 1`] = `
className=""
title=""
variant="warning"
variantLabel={null}
>
<div
aria-label="Warning Notification"
Expand Down Expand Up @@ -2209,6 +2227,7 @@ exports[`Alert - warning Custom aria label 1`] = `
className=""
title="Some title"
variant="warning"
variantLabel={null}
>
<div
aria-label="Custom aria label for warning"
Expand Down Expand Up @@ -2330,6 +2349,7 @@ exports[`Alert - warning Title 1`] = `
className=""
title="Some title"
variant="warning"
variantLabel={null}
>
<div
aria-label="Warning Notification"
Expand Down

0 comments on commit 0b8d241

Please sign in to comment.