diff --git a/css/index.styl b/css/index.styl index e5215ee6b..07eb0902b 100644 --- a/css/index.styl +++ b/css/index.styl @@ -491,6 +491,14 @@ loadingSize = 30px span display block margin-left 20px + .auth0-lock-input-wrap + background #ffffff + border 1px solid #ffffff + .auth0-lock-input-checkbox.auth0-lock-error + .auth0-lock-input-wrap span.no-hint + color red + .auth0-lock-error-invalid-hint + margin-left 20px // Social diff --git a/src/__tests__/field/__snapshots__/custom_input.test.jsx.snap b/src/__tests__/field/__snapshots__/custom_input.test.jsx.snap index b720024b4..e6dffc651 100644 --- a/src/__tests__/field/__snapshots__/custom_input.test.jsx.snap +++ b/src/__tests__/field/__snapshots__/custom_input.test.jsx.snap @@ -2,45 +2,129 @@ exports[`CustomInput when type == checkbox and when placeholderHTML is set renders correctly as a CheckBoxInput 1`] = `
-
+`; + +exports[`CustomInput when type == checkbox highlights placeholder text when no invalid hint is provided 1`] = ` +
+
+ +
`; exports[`CustomInput when type == checkbox renders correctly as a CheckBoxInput 1`] = `
- +
+ +
+
+`; + +exports[`CustomInput when type == checkbox shows an error when value is incorrect 1`] = ` +
+
+ +
+
`; diff --git a/src/__tests__/field/custom_input.test.jsx b/src/__tests__/field/custom_input.test.jsx index 09e55b185..b39c7fe35 100644 --- a/src/__tests__/field/custom_input.test.jsx +++ b/src/__tests__/field/custom_input.test.jsx @@ -97,6 +97,7 @@ describe('CustomInput', () => { describe('when type == checkbox', () => { beforeEach(() => (defaultProps.type = 'checkbox')); it('renders correctly as a CheckBoxInput', () => { + require('field/index').isFieldVisiblyInvalid = () => false; const CustomInput = getComponent(); expectComponent().toMatchSnapshot(); @@ -104,6 +105,8 @@ describe('CustomInput', () => { describe('and when placeholderHTML is set', () => { it('renders correctly as a CheckBoxInput', () => { + require('field/index').isFieldVisiblyInvalid = () => false; + const CustomInput = getComponent(); expectComponent( @@ -111,6 +114,24 @@ describe('CustomInput', () => { ).toMatchSnapshot(); }); }); + + it('shows an error when value is incorrect', () => { + const CustomInput = getComponent(); + + expectComponent( + Placeholder'} /> + ).toMatchSnapshot(); + }); + + it('highlights placeholder text when no invalid hint is provided', () => { + require('field/index').getFieldInvalidHint = () => undefined; + + const CustomInput = getComponent(); + + expectComponent( + Placeholder'} /> + ).toMatchSnapshot(); + }); }); describe('when type == hidden', () => { beforeEach(() => { diff --git a/src/field/custom_input.jsx b/src/field/custom_input.jsx index e29c035f4..f2525b8af 100644 --- a/src/field/custom_input.jsx +++ b/src/field/custom_input.jsx @@ -39,6 +39,7 @@ const CustomInput = ({ return ( changeField(l.id(model), name, `${e.target.checked}`, validator)} checked={getFieldValue(model, name)} placeholderHTML={placeholderHTML} diff --git a/src/ui/input/checkbox_input.jsx b/src/ui/input/checkbox_input.jsx index 5b0488295..b6bc2fac0 100644 --- a/src/ui/input/checkbox_input.jsx +++ b/src/ui/input/checkbox_input.jsx @@ -1,10 +1,28 @@ import React from 'react'; +import InputWrap from './input_wrap'; export default class CheckboxInput extends React.Component { render() { - const { lockId, name, ariaLabel, placeholder, checked, placeholderHTML } = this.props; + const { + lockId, + name, + ariaLabel, + placeholder, + checked, + placeholderHTML, + isValid, + invalidHint + } = this.props; + + const spanClass = invalidHint ? '' : 'no-hint' + return ( -
+ -
+ ); } diff --git a/src/ui/input/input_wrap.jsx b/src/ui/input/input_wrap.jsx index b1bfbac11..0d21a57d9 100644 --- a/src/ui/input/input_wrap.jsx +++ b/src/ui/input/input_wrap.jsx @@ -3,12 +3,16 @@ import React from 'react'; export default class InputWrap extends React.Component { render() { - const { after, focused, invalidHint, isValid, name, icon } = this.props; + const { after, focused, invalidHint, isValid, name, icon, className } = this.props; let blockClassName = `auth0-lock-input-block auth0-lock-input-${name}`; if (!isValid) { blockClassName += ' auth0-lock-error'; } + if (className) { + blockClassName += ` ${className}`; + } + let wrapClassName = 'auth0-lock-input-wrap'; if (focused && isValid) { wrapClassName += ' auth0-lock-focused'; diff --git a/support/index.html b/support/index.html index d2044ff0c..cfe9fb2e8 100644 --- a/support/index.html +++ b/support/index.html @@ -155,7 +155,17 @@

validator: function () { return true; } - } + }, + { + type: 'checkbox', + name: 'newsletter', + prefill: 'false', + placeholder: 'I hereby agree that I want to receive marketing emails from your company', + validator: (value) => ({ + valid: value === 'true', + hint: 'This is a mandatory field', + }), + }, ], hooks: { loggingIn: function (context, done) {