File tree Expand file tree Collapse file tree 11 files changed +157
-35
lines changed Expand file tree Collapse file tree 11 files changed +157
-35
lines changed Original file line number Diff line number Diff line change 1
1
import React , { cloneElement } from 'react' ;
2
2
import BootstrapMixin from './BootstrapMixin' ;
3
3
import classNames from 'classnames' ;
4
-
4
+ import SafeAnchor from './SafeAnchor' ;
5
5
6
6
const ListGroupItem = React . createClass ( {
7
7
mixins : [ BootstrapMixin ] ,
@@ -51,12 +51,12 @@ const ListGroupItem = React.createClass({
51
51
52
52
renderAnchor ( classes ) {
53
53
return (
54
- < a
54
+ < SafeAnchor
55
55
{ ...this . props }
56
56
className = { classNames ( this . props . className , classes ) }
57
57
>
58
58
{ this . props . header ? this . renderStructuredContent ( ) : this . props . children }
59
- </ a >
59
+ </ SafeAnchor >
60
60
) ;
61
61
} ,
62
62
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import classNames from 'classnames' ;
3
+ import SafeAnchor from './SafeAnchor' ;
3
4
4
5
const MenuItem = React . createClass ( {
5
6
propTypes : {
@@ -15,7 +16,6 @@ const MenuItem = React.createClass({
15
16
16
17
getDefaultProps ( ) {
17
18
return {
18
- href : '#' ,
19
19
active : false
20
20
} ;
21
21
} ,
@@ -29,9 +29,9 @@ const MenuItem = React.createClass({
29
29
30
30
renderAnchor ( ) {
31
31
return (
32
- < a onClick = { this . handleClick } href = { this . props . href } target = { this . props . target } title = { this . props . title } tabIndex = "-1" >
32
+ < SafeAnchor onClick = { this . handleClick } href = { this . props . href } target = { this . props . target } title = { this . props . title } tabIndex = "-1" >
33
33
{ this . props . children }
34
- </ a >
34
+ </ SafeAnchor >
35
35
) ;
36
36
} ,
37
37
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import classNames from 'classnames' ;
3
3
import BootstrapMixin from './BootstrapMixin' ;
4
+ import SafeAnchor from './SafeAnchor' ;
4
5
5
6
const NavItem = React . createClass ( {
6
7
mixins : [ BootstrapMixin ] ,
@@ -15,12 +16,6 @@ const NavItem = React.createClass({
15
16
target : React . PropTypes . string
16
17
} ,
17
18
18
- getDefaultProps ( ) {
19
- return {
20
- href : '#'
21
- } ;
22
- } ,
23
-
24
19
render ( ) {
25
20
let {
26
21
disabled,
@@ -38,8 +33,7 @@ const NavItem = React.createClass({
38
33
href,
39
34
title,
40
35
target,
41
- onClick : this . handleClick ,
42
- ref : 'anchor'
36
+ onClick : this . handleClick
43
37
} ;
44
38
45
39
if ( href === '#' ) {
@@ -48,9 +42,9 @@ const NavItem = React.createClass({
48
42
49
43
return (
50
44
< li { ...props } className = { classNames ( props . className , classes ) } >
51
- < a { ...linkProps } >
45
+ < SafeAnchor { ...linkProps } >
52
46
{ children }
53
- </ a >
47
+ </ SafeAnchor >
54
48
</ li >
55
49
) ;
56
50
} ,
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import classNames from 'classnames' ;
3
+ import SafeAnchor from './SafeAnchor' ;
3
4
4
5
const PageItem = React . createClass ( {
5
6
@@ -14,12 +15,6 @@ const PageItem = React.createClass({
14
15
eventKey : React . PropTypes . any
15
16
} ,
16
17
17
- getDefaultProps ( ) {
18
- return {
19
- href : '#'
20
- } ;
21
- } ,
22
-
23
18
render ( ) {
24
19
let classes = {
25
20
'disabled' : this . props . disabled ,
@@ -31,14 +26,13 @@ const PageItem = React.createClass({
31
26
< li
32
27
{ ...this . props }
33
28
className = { classNames ( this . props . className , classes ) } >
34
- < a
29
+ < SafeAnchor
35
30
href = { this . props . href }
36
31
title = { this . props . title }
37
32
target = { this . props . target }
38
- onClick = { this . handleSelect }
39
- ref = "anchor" >
33
+ onClick = { this . handleSelect } >
40
34
{ this . props . children }
41
- </ a >
35
+ </ SafeAnchor >
42
36
</ li >
43
37
) ;
44
38
} ,
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ /**
4
+ * Note: This is intended as a stop-gap for accessibility concerns that the
5
+ * Bootstrap CSS does not address as they have styled anchors and not buttons
6
+ * in many cases.
7
+ */
8
+ export default class SafeAnchor extends React . Component {
9
+ constructor ( props ) {
10
+ super ( props ) ;
11
+
12
+ this . handleClick = this . handleClick . bind ( this ) ;
13
+ }
14
+
15
+ handleClick ( event ) {
16
+ if ( this . props . href === undefined ) {
17
+ event . preventDefault ( ) ;
18
+ }
19
+
20
+ if ( this . props . onClick ) {
21
+ this . props . onClick ( event ) ;
22
+ }
23
+ }
24
+
25
+ render ( ) {
26
+ return (
27
+ < a role = { this . props . href ? undefined : 'button' }
28
+ { ...this . props }
29
+ onClick = { this . handleClick }
30
+ href = { this . props . href || '' } />
31
+ ) ;
32
+ }
33
+ }
34
+
35
+ SafeAnchor . propTypes = {
36
+ href : React . PropTypes . string ,
37
+ onClick : React . PropTypes . func
38
+ } ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import classNames from 'classnames';
4
4
import ValidComponentChildren from './utils/ValidComponentChildren' ;
5
5
import createChainedFunction from './utils/createChainedFunction' ;
6
6
import BootstrapMixin from './BootstrapMixin' ;
7
+ import SafeAnchor from './SafeAnchor' ;
7
8
8
9
const SubNav = React . createClass ( {
9
10
mixins : [ BootstrapMixin ] ,
@@ -99,14 +100,13 @@ const SubNav = React.createClass({
99
100
100
101
return (
101
102
< li { ...this . props } className = { classNames ( this . props . className , classes ) } >
102
- < a
103
+ < SafeAnchor
103
104
href = { this . props . href }
104
105
title = { this . props . title }
105
106
target = { this . props . target }
106
- onClick = { this . handleClick }
107
- ref = "anchor" >
107
+ onClick = { this . handleClick } >
108
108
{ this . props . text }
109
- </ a >
109
+ </ SafeAnchor >
110
110
< ul className = "nav" >
111
111
{ ValidComponentChildren . map ( this . props . children , this . renderNavItem ) }
112
112
</ ul >
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import classSet from 'classnames' ;
3
3
import BootstrapMixin from './BootstrapMixin' ;
4
+ import SafeAnchor from './SafeAnchor' ;
4
5
5
6
const Thumbnail = React . createClass ( {
6
7
mixins : [ BootstrapMixin ] ,
@@ -16,9 +17,9 @@ const Thumbnail = React.createClass({
16
17
17
18
if ( this . props . href ) {
18
19
return (
19
- < a { ...this . props } href = { this . props . href } className = { classSet ( this . props . className , classes ) } >
20
+ < SafeAnchor { ...this . props } href = { this . props . href } className = { classSet ( this . props . className , classes ) } >
20
21
< img src = { this . props . src } alt = { this . props . alt } />
21
- </ a >
22
+ </ SafeAnchor >
22
23
) ;
23
24
}
24
25
else {
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ import Pager from './Pager';
42
42
import Popover from './Popover' ;
43
43
import ProgressBar from './ProgressBar' ;
44
44
import Row from './Row' ;
45
+ import SafeAnchor from './SafeAnchor' ;
45
46
import SplitButton from './SplitButton' ;
46
47
import SubNav from './SubNav' ;
47
48
import TabbedArea from './TabbedArea' ;
@@ -97,6 +98,7 @@ export default {
97
98
Popover,
98
99
ProgressBar,
99
100
Row,
101
+ SafeAnchor,
100
102
SplitButton,
101
103
SubNav,
102
104
TabbedArea,
Original file line number Diff line number Diff line change @@ -83,9 +83,9 @@ describe('Nav', function () {
83
83
</ Nav >
84
84
) ;
85
85
86
- let items = ReactTestUtils . scryRenderedComponentsWithType ( instance , NavItem ) ;
86
+ let items = ReactTestUtils . scryRenderedDOMComponentsWithTag ( instance , 'A' ) ;
87
87
88
- ReactTestUtils . Simulate . click ( items [ 1 ] . refs . anchor ) ;
88
+ ReactTestUtils . Simulate . click ( items [ 1 ] ) ;
89
89
} ) ;
90
90
91
91
it ( 'Should set the correct item active by href' , function ( ) {
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ describe('PageItem', function () {
36
36
it ( 'Should call "onSelect" when item is clicked' , function ( done ) {
37
37
function handleSelect ( key , href ) {
38
38
assert . equal ( key , 1 ) ;
39
- assert . equal ( href , '#' ) ;
39
+ assert . equal ( href , undefined ) ;
40
40
done ( ) ;
41
41
}
42
42
let instance = ReactTestUtils . renderIntoDocument (
You can’t perform that action at this time.
0 commit comments