Skip to content

Commit 2d5b964

Browse files
committed
add onErrored prop
1 parent 06b9b60 commit 2d5b964

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Other properties can be used to customise the rendering.
4545
| type | enum | *optional* `image` or `audio` The type of initial captcha *(__defaults:__ image)*
4646
| tabindex | number | *optional* The tabindex on the element *(__default:__ 0)*
4747
| onExpired | func | *optional* callback when the challenge is expired and has to be redone by user. By default it will call the onChange with null to signify expired callback. |
48+
| onErrored | func | *optional* callback when the challenge errored, most likely due to network issues. |
4849
| stoken | string | *optional* set the stoken parameter, which allows the captcha to be used from different domains, see [reCAPTCHA secure-token] |
4950
| size | enum | *optional* `compact`, `normal` or `invisible`. This allows you to change the size or do an invisible captcha |
5051
| badge | enum | *optional* `bottomright`, `bottomleft` or `inline`. Positions reCAPTCHA badge. *Only for invisible reCAPTCHA* |

src/recaptcha.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export default class ReCAPTCHA extends React.Component {
4545
this.props.onChange(null);
4646
}
4747
}
48+
handleErrored() {
49+
if (this.props.onErrored) this.props.onErrored();
50+
}
4851

4952
explicitRender() {
5053
if (this.props.grecaptcha && this.props.grecaptcha.render && this._widgetId === undefined) {
@@ -56,6 +59,7 @@ export default class ReCAPTCHA extends React.Component {
5659
type: this.props.type,
5760
tabindex: this.props.tabindex,
5861
"expired-callback": this.handleExpired,
62+
"error-callback": this.handleErrored,
5963
size: this.props.size,
6064
stoken: this.props.stoken,
6165
badge: this.props.badge,
@@ -99,6 +103,7 @@ export default class ReCAPTCHA extends React.Component {
99103
type,
100104
tabindex,
101105
onExpired,
106+
onErrored,
102107
size,
103108
stoken,
104109
grecaptcha,
@@ -119,6 +124,7 @@ ReCAPTCHA.propTypes = {
119124
type: PropTypes.oneOf(["image", "audio"]),
120125
tabindex: PropTypes.number,
121126
onExpired: PropTypes.func,
127+
onErrored: PropTypes.func,
122128
size: PropTypes.oneOf(["compact", "normal", "invisible"]),
123129
stoken: PropTypes.string,
124130
badge: PropTypes.oneOf(["bottomright", "bottomleft", "inline"]),

test/recaptcha.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,7 @@ describe("ReCAPTCHA", () => {
100100
it("should call onChange with null when response is expired");
101101
it("should call onExpired when response is expired");
102102
});
103+
describe.skip("Errored", () => {
104+
it("should call onErrored when grecaptcha errored");
105+
});
103106
});

0 commit comments

Comments
 (0)