Skip to content

Commit

Permalink
Pr/2395 updated (#2584)
Browse files Browse the repository at this point in the history
* Correct tabindex on alert modal close button

* combine dismiss buttons

* fix react/no-unknown-property

* rm doc comment

* fix modal close button

* add CloseButton

* wtf
  • Loading branch information
jquense committed Apr 24, 2017
1 parent 9a4895a commit a781222
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 48 deletions.
5 changes: 0 additions & 5 deletions docs/src/sections/AlertsSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ export default function AlertsSection() {
<p>just pass in a <code>onDismiss</code> function.</p>
<ReactPlayground codeText={Samples.AlertDismissable} />

<div className="bs-callout bs-callout-info">
<h4>Screen Reader Accessibility</h4>
<p>Unlike regular Bootstrap, alerts have an sr-only dismiss button after the content.</p>
</div>

<h3><Anchor id="alert-props">Props</Anchor></h3>
<PropTable component="Alert"/>
</div>
Expand Down
35 changes: 7 additions & 28 deletions src/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
import { bsClass, bsStyles, getClassSet, prefix, splitBsProps }
from './utils/bootstrapUtils';
import { State } from './utils/StyleConfig';
import CloseButton from './CloseButton';

const propTypes = {
onDismiss: PropTypes.func,
Expand All @@ -16,32 +17,6 @@ const defaultProps = {
};

class Alert extends React.Component {
renderDismissButton(onDismiss) {
return (
<button
type="button"
className="close"
onClick={onDismiss}
aria-hidden="true"
tabIndex="-1"
>
<span>&times;</span>
</button>
);
}

renderSrOnlyDismissButton(onDismiss, closeLabel) {
return (
<button
type="button"
className="close sr-only"
onClick={onDismiss}
>
{closeLabel}
</button>
);
}

render() {
const { onDismiss, closeLabel, className, children, ...props } =
this.props;
Expand All @@ -59,9 +34,13 @@ class Alert extends React.Component {
role="alert"
className={classNames(className, classes)}
>
{dismissable && this.renderDismissButton(onDismiss)}
{dismissable && (
<CloseButton
onClick={onDismiss}
label={closeLabel}
/>
)}
{children}
{dismissable && this.renderSrOnlyDismissButton(onDismiss, closeLabel)}
</div>
);
}
Expand Down
27 changes: 27 additions & 0 deletions src/CloseButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as PropTypes from 'prop-types';
import React from 'react';

const propTypes = {
label: PropTypes.string.isRequired,
onClick: PropTypes.func,
};

class CloseButton extends React.Component {
render() {
const { label, onClick } = this.props;
return (
<button
type="button"
className="close"
onClick={onClick}
>
<span aria-hidden="true">&times;</span>
<span className="sr-only">{label}</span>
</button>
);
}
}

CloseButton.propTypes = propTypes;

export default CloseButton;
25 changes: 10 additions & 15 deletions src/ModalHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import PropTypes from 'prop-types';

import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
import createChainedFunction from './utils/createChainedFunction';
import CloseButton from './CloseButton';

// TODO: `aria-label` should be `closeLabel`.

const propTypes = {
/**
* The 'aria-label' attribute provides an accessible label for the close
* Provides an accessible label for the close
* button. It is used for Assistive Technology when the label text is not
* readable.
*/
'aria-label': PropTypes.string,
closeLabel: PropTypes.string,

/**
* Specify whether the Component should contain a close button
Expand All @@ -29,7 +30,7 @@ const propTypes = {
};

const defaultProps = {
'aria-label': 'Close',
closeLabel: 'Close',
closeButton: false,
};

Expand All @@ -42,7 +43,7 @@ const contextTypes = {
class ModalHeader extends React.Component {
render() {
const {
'aria-label': label,
closeLabel,
closeButton,
onHide,
className,
Expand All @@ -61,18 +62,12 @@ class ModalHeader extends React.Component {
{...elementProps}
className={classNames(className, classes)}
>
{closeButton &&
<button
type="button"
className="close"
aria-label={label}
{closeButton && (
<CloseButton
label={closeLabel}
onClick={createChainedFunction(modal && modal.onHide, onHide)}
>
<span aria-hidden="true">
&times;
</span>
</button>
}
/>
)}

{children}
</div>
Expand Down

0 comments on commit a781222

Please sign in to comment.