Skip to content

Commit

Permalink
adding allowAutoComplete ui option
Browse files Browse the repository at this point in the history
  • Loading branch information
luisrudge committed Jun 9, 2017
1 parent af93b1d commit e8e6287
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ The appearance of the widget and the mechanics of authentication can be customiz
- **flashMessage {Object}**: Shows an `error` or `success` flash message when Lock is shown.
+ **type {String}**: The message type, it should be `error` or `success`.
+ **text {String}**: The text to show.
- **allowAutocomplete {Boolean}**: Determines whether or not the the email or username inputs will allow autocomplete (`<input autocomplete />`). Defaults to `false`.

#### Theming options

Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/field/__snapshots__/email_pane.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Array [
exports[`EmailPane renders correctly 1`] = `
<div
data-__type="email_input"
data-autoComplete={false}
data-invalidHint="invalidErrorHint"
data-isValid={false}
data-onChange={[Function]}
Expand All @@ -24,6 +25,7 @@ exports[`EmailPane renders correctly 1`] = `
exports[`EmailPane sets \`blankErrorHint\` when username is empty 1`] = `
<div
data-__type="email_input"
data-autoComplete={false}
data-invalidHint="blankErrorHint"
data-isValid={false}
data-onChange={[Function]}
Expand All @@ -32,9 +34,22 @@ exports[`EmailPane sets \`blankErrorHint\` when username is empty 1`] = `
/>
`;

exports[`EmailPane sets autoComplete to true when \`allowAutocomplete\` is true 1`] = `
<div
data-__type="email_input"
data-autoComplete={true}
data-invalidHint="invalidErrorHint"
data-isValid={false}
data-onChange={[Function]}
data-placeholder="placeholder"
data-value="[email protected]"
/>
`;

exports[`EmailPane sets isValid as true when \`isFieldVisiblyInvalid\` is false 1`] = `
<div
data-__type="email_input"
data-autoComplete={false}
data-invalidHint="invalidErrorHint"
data-isValid={true}
data-onChange={[Function]}
Expand Down
16 changes: 16 additions & 0 deletions src/__tests__/field/__snapshots__/username_pane.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Array [
exports[`UsernamePane renders correctly 1`] = `
<div
data-__type="username_input"
data-autoComplete={false}
data-invalidHint="invalidErrorHint"
data-isValid={false}
data-onChange={[Function]}
Expand All @@ -26,6 +27,7 @@ exports[`UsernamePane renders correctly 1`] = `
exports[`UsernamePane sets \`blankErrorHint\` when username is empty 1`] = `
<div
data-__type="username_input"
data-autoComplete={false}
data-invalidHint="blankErrorHint"
data-isValid={false}
data-onChange={[Function]}
Expand All @@ -37,6 +39,7 @@ exports[`UsernamePane sets \`blankErrorHint\` when username is empty 1`] = `
exports[`UsernamePane sets \`usernameFormatErrorHint\` when usernameLooksLikeEmail() returns false and \`validateFormat\` is true 1`] = `
<div
data-__type="username_input"
data-autoComplete={false}
data-invalidHint="usernameFormatErrorHint,min,max"
data-isValid={false}
data-onChange={[Function]}
Expand All @@ -45,9 +48,22 @@ exports[`UsernamePane sets \`usernameFormatErrorHint\` when usernameLooksLikeEma
/>
`;

exports[`UsernamePane sets autoComplete to true when \`allowAutocomplete\` is true 1`] = `
<div
data-__type="username_input"
data-autoComplete={true}
data-invalidHint="invalidErrorHint"
data-isValid={false}
data-onChange={[Function]}
data-placeholder="placeholder"
data-value="username"
/>
`;

exports[`UsernamePane sets isValid as true when \`isFieldVisiblyInvalid\` is false 1`] = `
<div
data-__type="username_input"
data-autoComplete={false}
data-invalidHint="invalidErrorHint"
data-isValid={true}
data-onChange={[Function]}
Expand Down
9 changes: 8 additions & 1 deletion src/__tests__/field/email_pane.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ describe('EmailPane', () => {
jest.mock('core/index', () => ({
id: () => 1,
ui: {
avatar: () => false
avatar: () => false,
allowAutocomplete: () => false
}
}));

Expand Down Expand Up @@ -75,6 +76,12 @@ describe('EmailPane', () => {

expectComponent(<EmailPane {...defaultProps} />).toMatchSnapshot();
});
it('sets autoComplete to true when `allowAutocomplete` is true', () => {
require('core/index').ui.allowAutocomplete = () => true;
let EmailPane = getComponent();

expectComponent(<EmailPane {...defaultProps} />).toMatchSnapshot();
});
it('fetches the avatar on componentDidMount if ui.avatar is true and there is a username', () => {
require('core/index').ui.avatar = () => true;
let EmailPane = getComponent();
Expand Down
9 changes: 8 additions & 1 deletion src/__tests__/field/username_pane.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ describe('UsernamePane', () => {
jest.mock('core/index', () => ({
id: () => 1,
ui: {
avatar: () => false
avatar: () => false,
allowAutocomplete: () => false
}
}));

Expand Down Expand Up @@ -81,6 +82,12 @@ describe('UsernamePane', () => {

expectComponent(<UsernamePane {...defaultProps} />).toMatchSnapshot();
});
it('sets autoComplete to true when `allowAutocomplete` is true', () => {
require('core/index').ui.allowAutocomplete = () => true;
let UsernamePane = getComponent();

expectComponent(<UsernamePane {...defaultProps} />).toMatchSnapshot();
});
it('fetches the avatar on componentDidMount if ui.avatar is true and there is a username', () => {
require('core/index').ui.avatar = () => true;
let UsernamePane = getComponent();
Expand Down
7 changes: 6 additions & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function extractUIOptions(id, options) {
popupOptions: undefined === options.popupOptions ? {} : options.popupOptions,
primaryColor: typeof primaryColor === 'string' ? primaryColor : undefined,
rememberLastLogin: undefined === options.rememberLastLogin ? true : !!options.rememberLastLogin,
allowAutocomplete: !!options.allowAutocomplete,
authButtonsTheme: typeof authButtons === 'object' ? authButtons : {}
});
}
Expand Down Expand Up @@ -183,7 +184,8 @@ export const ui = {
popupOptions: lock => getUIAttribute(lock, 'popupOptions'),
primaryColor: lock => getUIAttribute(lock, 'primaryColor'),
authButtonsTheme: lock => getUIAttribute(lock, 'authButtonsTheme'),
rememberLastLogin: m => tget(m, 'rememberLastLogin', getUIAttribute(m, 'rememberLastLogin'))
rememberLastLogin: m => tget(m, 'rememberLastLogin', getUIAttribute(m, 'rememberLastLogin')),
allowAutocomplete: m => tget(m, 'allowAutocomplete', getUIAttribute(m, 'allowAutocomplete'))
};

const { get: getAuthAttribute } = dataFns(['core', 'auth']);
Expand Down Expand Up @@ -575,6 +577,9 @@ export function overrideOptions(m, opts) {
if (typeof opts.rememberLastLogin === 'boolean') {
m = tset(m, 'rememberLastLogin', opts.rememberLastLogin);
}
if (typeof opts.allowAutocomplete === 'boolean') {
m = tset(m, 'allowAutocomplete', opts.allowAutocomplete);
}

return m;
}
2 changes: 2 additions & 0 deletions src/field/email/email_pane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class EmailPane extends React.Component {

render() {
const { i18n, lock, placeholder, forceInvalidVisibility = false } = this.props;
const allowAutocomplete = l.ui.allowAutocomplete(lock);

const field = c.getField(lock, 'email');
const value = field.get('value', '');
Expand All @@ -44,6 +45,7 @@ export default class EmailPane extends React.Component {
isValid={isValid}
onChange={::this.handleChange}
placeholder={placeholder}
autoComplete={allowAutocomplete}
/>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/field/username/username_pane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default class UsernamePane extends React.Component {

render() {
const { i18n, lock, placeholder, validateFormat } = this.props;
const allowAutocomplete = l.ui.allowAutocomplete(lock);
const value = c.getFieldValue(lock, 'username');
const usernameValidation = validateFormat ? getUsernameValidation(lock) : {};

Expand Down Expand Up @@ -62,6 +63,7 @@ export default class UsernamePane extends React.Component {
isValid={!c.isFieldVisiblyInvalid(lock, 'username')}
onChange={::this.handleChange}
placeholder={placeholder}
autoComplete={allowAutocomplete}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/input/email_input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class EmailInput extends React.Component {
}

render() {
const { invalidHint, isValid, onChange, ...props } = this.props;
const { invalidHint, isValid, onChange, autoComplete, ...props } = this.props;
const { focused } = this.state;

return (
Expand All @@ -40,7 +40,7 @@ export default class EmailInput extends React.Component {
name="email"
className="auth0-lock-input"
placeholder="[email protected]"
autoComplete="off"
autoComplete={autoComplete ? 'on' : 'off'}
autoCapitalize="off"
onChange={::this.handleOnChange}
onFocus={::this.handleFocus}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/input/username_input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class UsernameInput extends React.Component {
}

render() {
const { invalidHint, isValid, onChange, ...props } = this.props;
const { invalidHint, isValid, onChange, autoComplete, ...props } = this.props;
const { focused } = this.state;

return (
Expand All @@ -40,7 +40,7 @@ export default class UsernameInput extends React.Component {
name="username"
className="auth0-lock-input"
placeholder="username"
autoComplete="off"
autoComplete={autoComplete ? 'on' : 'off'}
autoCapitalize="off"
spellCheck="off"
autoCorrect="off"
Expand Down

0 comments on commit e8e6287

Please sign in to comment.