File tree Expand file tree Collapse file tree 2 files changed +30
-6
lines changed Expand file tree Collapse file tree 2 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -7,13 +7,15 @@ const Alert = React.createClass({
77
88 propTypes : {
99 onDismiss : React . PropTypes . func ,
10- dismissAfter : React . PropTypes . number
10+ dismissAfter : React . PropTypes . number ,
11+ closeLabel : React . PropTypes . string
1112 } ,
1213
1314 getDefaultProps ( ) {
1415 return {
1516 bsClass : 'alert' ,
16- bsStyle : 'info'
17+ bsStyle : 'info' ,
18+ closeLabel : 'Close Alert'
1719 } ;
1820 } ,
1921
@@ -22,9 +24,9 @@ const Alert = React.createClass({
2224 < button
2325 type = "button"
2426 className = "close"
25- onClick = { this . props . onDismiss }
26- aria-hidden = "true" >
27- ×
27+ aria-label = { this . props . closeLabel }
28+ onClick = { this . props . onDismiss } >
29+ < span aria-hidden = "true" > ×</ span >
2830 </ button >
2931 ) ;
3032 } ,
@@ -36,7 +38,7 @@ const Alert = React.createClass({
3638 classes [ 'alert-dismissable' ] = isDismissable ;
3739
3840 return (
39- < div { ...this . props } className = { classNames ( this . props . className , classes ) } >
41+ < div { ...this . props } role = 'alert' className = { classNames ( this . props . className , classes ) } >
4042 { isDismissable ? this . renderDismissButton ( ) : null }
4143 { this . props . children }
4244 </ div >
Original file line number Diff line number Diff line change @@ -71,4 +71,26 @@ describe('Alert', function () {
7171 ) ;
7272 assert . ok ( React . findDOMNode ( instance ) . className . match ( / \b a l e r t - d a n g e r \b / ) ) ;
7373 } ) ;
74+
75+ describe ( 'Web Accessibility' , function ( ) {
76+ it ( 'Should have alert role' , function ( ) {
77+ let instance = ReactTestUtils . renderIntoDocument (
78+ < Alert > Message</ Alert >
79+ ) ;
80+
81+ assert . equal ( React . findDOMNode ( instance ) . getAttribute ( 'role' ) , 'alert' ) ;
82+ } ) ;
83+
84+ it ( 'Should have add ARIAs to button' , function ( ) {
85+ let instance = ReactTestUtils . renderIntoDocument (
86+ < Alert onDismiss = { ( ) => { } } closeLabel = 'close' > Message</ Alert >
87+ ) ;
88+
89+ let button = ReactTestUtils . findRenderedDOMComponentWithTag ( instance , 'button' ) ;
90+
91+ assert . equal ( React . findDOMNode ( button ) . getAttribute ( 'aria-label' ) , 'close' ) ;
92+ assert . equal ( React . findDOMNode ( button ) . children [ 0 ] . getAttribute ( 'aria-hidden' ) , 'true' ) ;
93+ } ) ;
94+
95+ } ) ;
7496} ) ;
You can’t perform that action at this time.
0 commit comments