Skip to content

Commit bf32da9

Browse files
committed
Only use a tags in tab when an href or onClick is supplied.
1 parent e870622 commit bf32da9

File tree

1 file changed

+18
-22
lines changed
  • client/my-sites/stats/stats-tabs

1 file changed

+18
-22
lines changed

client/my-sites/stats/stats-tabs/tab.jsx

+18-22
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@ export default React.createClass( {
2323
value: PropTypes.number
2424
},
2525

26-
getDefaultProps() {
27-
return {
28-
tabClick: () => {}
29-
}
30-
},
31-
3226
clickHandler( event ) {
33-
event.preventDefault();
34-
this.props.tabClick( this.props );
27+
if ( this.props.tabClick ) {
28+
event.preventDefault();
29+
this.props.tabClick( this.props );
30+
}
3531
},
3632

3733
ensureValue( value ) {
@@ -42,14 +38,8 @@ export default React.createClass( {
4238
return String.fromCharCode( 8211 );
4339
},
4440

45-
handleLinkClick( event ) {
46-
if ( ! this.props.href ) {
47-
event.preventDefault();
48-
}
49-
},
50-
5141
render() {
52-
const { className, children, gridicon, href, label, loading, selected, value } = this.props;
42+
const { className, children, gridicon, href, label, loading, selected, tabClick, value } = this.props;
5343

5444
const tabClass = classNames(
5545
'stats-tab',
@@ -60,16 +50,22 @@ export default React.createClass( {
6050
'is-low': ! value
6151
} );
6252

63-
const linkClass = ! href ? 'no-link' : null;
53+
const tabIcon = gridicon ? <Gridicon icon={ gridicon } size={ 18 } /> : null;
54+
const tabLabel = <span className="label">{ label }</span>;
55+
const tabValue = <span className="value">{ this.ensureValue( value ) }</span>;
56+
const hasClickAction = href || tabClick;
6457

6558
return (
6659
<li className={ tabClass } onClick={ this.clickHandler } >
67-
<a href={ href } className={ linkClass } onClick={ this.handleLinkClick }>
68-
{ gridicon ? <Gridicon icon={ gridicon } size={ 18 } /> : null }
69-
<span className="label">{ label }</span>
70-
<span className="value">{ this.ensureValue( value ) }</span>
71-
{ children }
72-
</a>
60+
{
61+
hasClickAction
62+
? <a href={ href }>
63+
{ tabIcon }{ tabLabel }{ tabValue }{ children }
64+
</a>
65+
: <span className="no-link">
66+
{ tabIcon }{ tabLabel }{ tabValue }{ children }
67+
</span>
68+
}
7369
</li>
7470
);
7571
}

0 commit comments

Comments
 (0)