Skip to content

Commit

Permalink
fix(status-alert): fix add ability to set close button aria-label
Browse files Browse the repository at this point in the history
  • Loading branch information
AlasdairSwan committed Apr 4, 2018
1 parent dd3949e commit a7535a0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .storybook/__snapshots__/Storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18143,6 +18143,34 @@ exports[`Storyshots StatusAlert alert invoked via a button 1`] = `
</div>
`;

exports[`Storyshots StatusAlert alert with a custom aria-label on the close button 1`] = `
<div
className="alert fade alert-dismissible alert-info show"
hidden={false}
role="alert"
>
<button
aria-label="Dismiss this very specific information."
className="btn close"
onBlur={[Function]}
onClick={[Function]}
onKeyDown={[Function]}
type="button"
>
<span
aria-hidden="true"
>
×
</span>
</button>
<div
className="alert-dialog"
>
Some very specific information.
</div>
</div>
`;

exports[`Storyshots StatusAlert alert with a link 1`] = `
<div
className="alert fade alert-dismissible alert-info show"
Expand Down
9 changes: 9 additions & 0 deletions src/StatusAlert/StatusAlert.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ storiesOf('StatusAlert', module)
open
/>
))
.add('alert with a custom aria-label on the close button', () => (
<StatusAlert
alertType="info"
dialog="Some very specific information."
onClose={() => {}}
open
closeButtonAriaLabel="Dismiss this very specific information."
/>
))
.add('Non-dismissible alert', () => (
<StatusAlert
alertType="danger"
Expand Down
8 changes: 8 additions & 0 deletions src/StatusAlert/StatusAlert.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ describe('<StatusAlert />', () => {
expect(statusAlertDialog.text()).toEqual(dialog);
expect(wrapper.find('button')).toHaveLength(0);
});

it('renders custom aria-label view', () => {
const customLabel = 'Dismiss this alert post-haste!';
wrapper = mount(<StatusAlert {...defaultProps} closeButtonAriaLabel={customLabel} />);
const button = wrapper.find('button').at(0);

expect(button.prop('aria-label')).toEqual(customLabel);
});
});

describe('props received correctly', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/StatusAlert/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ class StatusAlert extends React.Component {
}

renderDismissible() {
const { dismissible } = this.props;
const { closeButtonAriaLabel, dismissible } = this.props;

return (dismissible) ? (
<Button
aria-label="Close"
aria-label={closeButtonAriaLabel}
inputRef={(input) => { this.xButton = input; }}
onClick={this.close}
onKeyDown={this.handleKeyDown}
Expand Down Expand Up @@ -110,13 +110,15 @@ StatusAlert.propTypes = {
dialog: PropTypes.oneOfType([PropTypes.string, PropTypes.element]).isRequired,
dismissible: PropTypes.bool,
/* eslint-disable react/require-default-props */
closeButtonAriaLabel: PropTypes.string,
onClose: isRequiredIf(PropTypes.func, props => props.dismissible),
open: PropTypes.bool,
};

StatusAlert.defaultProps = {
alertType: 'warning',
className: [],
closeButtonAriaLabel: 'Close',
dismissible: true,
open: false,
};
Expand Down

0 comments on commit a7535a0

Please sign in to comment.