Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Added onClick prop
Browse files Browse the repository at this point in the history
  • Loading branch information
willemliu committed Nov 27, 2017
1 parent 05d6c77 commit 43f8cb2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions dist/A.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/// <reference types="react" />
import * as React from 'react';
import { MouseEvent } from 'react';
export interface Props {
ariaLabel?: string;
children?: JSX.Element[] | HTMLElement[] | string | number;
className?: string;
href?: string;
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
target?: string;
tabIndex?: number;
title?: string;
Expand Down
2 changes: 1 addition & 1 deletion dist/A.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var A = /** @class */ (function (_super) {
return ariaLabel;
};
A.prototype.render = function () {
return (React.createElement("a", { href: this.props.href, className: this.props.className, "aria-label": this.getAriaLabel(), target: this.props.target, tabIndex: this.props.tabIndex ? this.props.tabIndex : 0, title: this.props.title }, this.props.children));
return (React.createElement("a", { href: this.props.href, className: this.props.className, "aria-label": this.getAriaLabel(), target: this.props.target, tabIndex: this.props.tabIndex ? this.props.tabIndex : 0, title: this.props.title, onClick: this.props.onClick }, this.props.children));
};
return A;
}(React.Component));
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "fdmg-ts-react-anchor",
"version": "1.0.0",
"version": "1.0.1",
"description": "ReactJS Anchor component",
"main": "dist/A.js",
"types": "dist/A.d.ts",
"scripts": {
"release": "tsc -d",
"release": "tsc -d && npm install",
"test": "jest",
"updateSnapshot": "jest --updateSnapshot",
"u": "npm test -- -u"
Expand Down
6 changes: 5 additions & 1 deletion src/A.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as React from 'react';
import {MouseEvent} from 'react';

export interface Props {
ariaLabel?: string;
children?: JSX.Element[]|HTMLElement[]|string|number;
className?: string;
href?: string;
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
target?: string;
tabIndex?: number;
title?: string;
Expand Down Expand Up @@ -47,7 +49,9 @@ export default class A extends React.Component<Props, any> {
return (
<a href={this.props.href} className={this.props.className} aria-label={this.getAriaLabel()}
target={this.props.target} tabIndex={this.props.tabIndex?this.props.tabIndex:0}
title={this.props.title}>{this.props.children}</a>
title={this.props.title} onClick={this.props.onClick}>
{this.props.children}
</a>
);
}
}
12 changes: 12 additions & 0 deletions test/__snapshots__/A.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports[`A renders correctly 1`] = `
aria-label={undefined}
className={undefined}
href={undefined}
onClick={undefined}
tabIndex={0}
target={undefined}
title={undefined}
Expand All @@ -16,6 +17,7 @@ exports[`A renders correctly 2`] = `
aria-label={undefined}
className={undefined}
href={undefined}
onClick={undefined}
tabIndex={0}
target={undefined}
title={undefined}
Expand All @@ -34,6 +36,7 @@ exports[`A renders correctly with ARIA-label 1`] = `
aria-label="anchor text as ARIA-label"
className={undefined}
href={undefined}
onClick={undefined}
tabIndex={0}
target={undefined}
title={undefined}
Expand All @@ -47,6 +50,7 @@ exports[`A renders correctly with ARIA-label 2`] = `
aria-label="ARIA-label"
className={undefined}
href={undefined}
onClick={undefined}
tabIndex={0}
target={undefined}
title={undefined}
Expand All @@ -60,6 +64,7 @@ exports[`A renders correctly with ARIA-label 3`] = `
aria-label="title shown as ARIA-label"
className={undefined}
href={undefined}
onClick={undefined}
tabIndex={0}
target={undefined}
title="title shown as ARIA-label"
Expand All @@ -73,6 +78,7 @@ exports[`A renders correctly with ARIA-label 4`] = `
aria-label="ariaLabel shown as ARIA-label"
className={undefined}
href={undefined}
onClick={undefined}
tabIndex={0}
target={undefined}
title="this should not be shown as ARIA-label"
Expand All @@ -86,6 +92,7 @@ exports[`A renders correctly with ARIA-label 5`] = `
aria-label="title shown as ARIA-label"
className={undefined}
href={undefined}
onClick={undefined}
tabIndex={0}
target={undefined}
title="title shown as ARIA-label"
Expand All @@ -104,6 +111,7 @@ exports[`A renders correctly with ARIA-label 6`] = `
aria-label="ariaLabel shown as ARIA-label"
className={undefined}
href={undefined}
onClick={undefined}
tabIndex={0}
target={undefined}
title={undefined}
Expand All @@ -122,6 +130,7 @@ exports[`A renders correctly with CSS class 1`] = `
aria-label="test anchor"
className="css-class-name"
href={undefined}
onClick={undefined}
tabIndex={0}
target={undefined}
title={undefined}
Expand All @@ -135,6 +144,7 @@ exports[`A renders correctly with href 1`] = `
aria-label="test anchor"
className={undefined}
href="https://fd.nl"
onClick={undefined}
tabIndex={0}
target={undefined}
title={undefined}
Expand All @@ -148,6 +158,7 @@ exports[`A renders correctly with tabIndex 1`] = `
aria-label="test anchor"
className={undefined}
href={undefined}
onClick={undefined}
tabIndex="2"
target={undefined}
title={undefined}
Expand All @@ -161,6 +172,7 @@ exports[`A renders correctly with tabIndex 2`] = `
aria-label="test anchor"
className={undefined}
href={undefined}
onClick={undefined}
tabIndex="-1"
target={undefined}
title={undefined}
Expand Down

0 comments on commit 43f8cb2

Please sign in to comment.