Skip to content

Commit

Permalink
fix(OrderSummary): Add aria-labelledby, missing attributes fail A11Y …
Browse files Browse the repository at this point in the history
…tests (carbon-design-system#514)

* fix(OrderSummary): Add aria-labelledby, missing attributes fail A11Y tests, resolves carbon-design-system#513

* fix(OrderSummary): make id random to avoid duplication, resolves carbon-design-system#513

* fix(OrderSummary): default props are static, put them as default values
  • Loading branch information
zeusorion authored and tw15egan committed Jan 23, 2018
1 parent 1a0d7d8 commit 1887331
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/components/OrderSummary/OrderSummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class OrderSummaryHeader extends Component {
static propTypes = {
children: PropTypes.node,
className: PropTypes.string,
id: PropTypes.string,
title: PropTypes.string,
};

Expand All @@ -33,12 +34,22 @@ export class OrderSummaryHeader extends Component {
};

render() {
const { children, className, title, ...other } = this.props;
const {
children,
className,
id = `order__summary__header__id_${Math.random()
.toString(36)
.substr(2)}`,
title,
...other
} = this.props;
const classes = classNames('bx--order-header', className);

return (
<section className={classes} {...other}>
<p className="bx--order-header-title">{title}</p>
<section className={classes} aria-labelledby={`${id}__title`} {...other}>
<p className="bx--order-header-title" id={`${id}__title`}>
{title}
</p>
{children}
</section>
);
Expand Down Expand Up @@ -116,6 +127,7 @@ export class OrderSummaryTotal extends Component {
static propTypes = {
children: PropTypes.node,
className: PropTypes.string,
id: PropTypes.string,
summaryText: PropTypes.string,
summaryPrice: PropTypes.string,
summaryDetails: PropTypes.string,
Expand All @@ -131,6 +143,9 @@ export class OrderSummaryTotal extends Component {
const {
children,
className,
id = `order__summary__total__id_${Math.random()
.toString(36)
.substr(2)}`,
summaryText,
summaryPrice,
summaryDetails,
Expand All @@ -139,9 +154,11 @@ export class OrderSummaryTotal extends Component {
const classes = classNames('bx--order-total-container', className);

return (
<section className={classes} {...other}>
<section className={classes} aria-labelledby={`${id}__title`} {...other}>
<div className="bx--order-total">
<p className="bx--order-total-text">{summaryText}</p>
<p className="bx--order-total-text" id={`${id}__title`}>
{summaryText}
</p>
<p className="bx--order-total-price">
{summaryPrice}
<span>{summaryDetails}</span>
Expand All @@ -156,6 +173,7 @@ export class OrderSummaryTotal extends Component {
export class OrderSummaryFooter extends Component {
static propTypes = {
className: PropTypes.string,
id: PropTypes.string,
linkText: PropTypes.string,
href: PropTypes.string,
target: PropTypes.string,
Expand All @@ -173,6 +191,9 @@ export class OrderSummaryFooter extends Component {
render() {
const {
className,
id = `order__summary__footer__id_${Math.random()
.toString(36)
.substr(2)}`,
footerText,
linkText,
href,
Expand All @@ -183,8 +204,10 @@ export class OrderSummaryFooter extends Component {
const classes = classNames('bx--order-footer', className);

return (
<section className={classes} {...other}>
<p className="bx--order-footer-text">{footerText}</p>
<section className={classes} aria-labelledby={`${id}__title`} {...other}>
<p className="bx--order-footer-text" id={`${id}__title`}>
{footerText}
</p>
&nbsp;
<Link href={href} target={target} rel={rel}>
{linkText}
Expand Down

0 comments on commit 1887331

Please sign in to comment.