Skip to content

Commit 5621e9d

Browse files
committed
adding allowAutoComplete ui option
1 parent 4cdffbc commit 5621e9d

10 files changed

+62
-7
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ The appearance of the widget and the mechanics of authentication can be customiz
187187
- **flashMessage {Object}**: Shows an `error` or `success` flash message when Lock is shown.
188188
+ **type {String}**: The message type, it should be `error` or `success`.
189189
+ **text {String}**: The text to show.
190+
- **allowAutocomplete {Boolean}**: Determines whether or not the the email or username inputs will allow autocomplete (`<input autocomplete />`). Defaults to `false`.
190191

191192
#### Theming options
192193

src/__tests__/field/__snapshots__/email_pane.test.jsx.snap

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Array [
1313
exports[`EmailPane renders correctly 1`] = `
1414
<div
1515
data-__type="email_input"
16+
data-autoComplete={false}
1617
data-invalidHint="invalidErrorHint"
1718
data-isValid={false}
1819
data-onChange={[Function]}
@@ -24,6 +25,7 @@ exports[`EmailPane renders correctly 1`] = `
2425
exports[`EmailPane sets \`blankErrorHint\` when username is empty 1`] = `
2526
<div
2627
data-__type="email_input"
28+
data-autoComplete={false}
2729
data-invalidHint="blankErrorHint"
2830
data-isValid={false}
2931
data-onChange={[Function]}
@@ -32,9 +34,22 @@ exports[`EmailPane sets \`blankErrorHint\` when username is empty 1`] = `
3234
/>
3335
`;
3436

37+
exports[`EmailPane sets autoComplete to true when \`allowAutocomplete\` is true 1`] = `
38+
<div
39+
data-__type="email_input"
40+
data-autoComplete={true}
41+
data-invalidHint="invalidErrorHint"
42+
data-isValid={false}
43+
data-onChange={[Function]}
44+
data-placeholder="placeholder"
45+
data-value="user@example.com"
46+
/>
47+
`;
48+
3549
exports[`EmailPane sets isValid as true when \`isFieldVisiblyInvalid\` is false 1`] = `
3650
<div
3751
data-__type="email_input"
52+
data-autoComplete={false}
3853
data-invalidHint="invalidErrorHint"
3954
data-isValid={true}
4055
data-onChange={[Function]}

src/__tests__/field/__snapshots__/username_pane.test.jsx.snap

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Array [
1515
exports[`UsernamePane renders correctly 1`] = `
1616
<div
1717
data-__type="username_input"
18+
data-autoComplete={false}
1819
data-invalidHint="invalidErrorHint"
1920
data-isValid={false}
2021
data-onChange={[Function]}
@@ -26,6 +27,7 @@ exports[`UsernamePane renders correctly 1`] = `
2627
exports[`UsernamePane sets \`blankErrorHint\` when username is empty 1`] = `
2728
<div
2829
data-__type="username_input"
30+
data-autoComplete={false}
2931
data-invalidHint="blankErrorHint"
3032
data-isValid={false}
3133
data-onChange={[Function]}
@@ -37,6 +39,7 @@ exports[`UsernamePane sets \`blankErrorHint\` when username is empty 1`] = `
3739
exports[`UsernamePane sets \`usernameFormatErrorHint\` when usernameLooksLikeEmail() returns false and \`validateFormat\` is true 1`] = `
3840
<div
3941
data-__type="username_input"
42+
data-autoComplete={false}
4043
data-invalidHint="usernameFormatErrorHint,min,max"
4144
data-isValid={false}
4245
data-onChange={[Function]}
@@ -45,9 +48,22 @@ exports[`UsernamePane sets \`usernameFormatErrorHint\` when usernameLooksLikeEma
4548
/>
4649
`;
4750

51+
exports[`UsernamePane sets autoComplete to true when \`allowAutocomplete\` is true 1`] = `
52+
<div
53+
data-__type="username_input"
54+
data-autoComplete={true}
55+
data-invalidHint="invalidErrorHint"
56+
data-isValid={false}
57+
data-onChange={[Function]}
58+
data-placeholder="placeholder"
59+
data-value="username"
60+
/>
61+
`;
62+
4863
exports[`UsernamePane sets isValid as true when \`isFieldVisiblyInvalid\` is false 1`] = `
4964
<div
5065
data-__type="username_input"
66+
data-autoComplete={false}
5167
data-invalidHint="invalidErrorHint"
5268
data-isValid={true}
5369
data-onChange={[Function]}

src/__tests__/field/email_pane.test.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ describe('EmailPane', () => {
3838
jest.mock('core/index', () => ({
3939
id: () => 1,
4040
ui: {
41-
avatar: () => false
41+
avatar: () => false,
42+
allowAutocomplete: () => false
4243
}
4344
}));
4445

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

7677
expectComponent(<EmailPane {...defaultProps} />).toMatchSnapshot();
7778
});
79+
it('sets autoComplete to true when `allowAutocomplete` is true', () => {
80+
require('core/index').ui.allowAutocomplete = () => true;
81+
let EmailPane = getComponent();
82+
83+
expectComponent(<EmailPane {...defaultProps} />).toMatchSnapshot();
84+
});
7885
it('fetches the avatar on componentDidMount if ui.avatar is true and there is a username', () => {
7986
require('core/index').ui.avatar = () => true;
8087
let EmailPane = getComponent();

src/__tests__/field/username_pane.test.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ describe('UsernamePane', () => {
4040
jest.mock('core/index', () => ({
4141
id: () => 1,
4242
ui: {
43-
avatar: () => false
43+
avatar: () => false,
44+
allowAutocomplete: () => false
4445
}
4546
}));
4647

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

8283
expectComponent(<UsernamePane {...defaultProps} />).toMatchSnapshot();
8384
});
85+
it('sets autoComplete to true when `allowAutocomplete` is true', () => {
86+
require('core/index').ui.allowAutocomplete = () => true;
87+
let UsernamePane = getComponent();
88+
89+
expectComponent(<UsernamePane {...defaultProps} />).toMatchSnapshot();
90+
});
8491
it('fetches the avatar on componentDidMount if ui.avatar is true and there is a username', () => {
8592
require('core/index').ui.avatar = () => true;
8693
let UsernamePane = getComponent();

src/core/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ function extractUIOptions(id, options) {
153153
popupOptions: undefined === options.popupOptions ? {} : options.popupOptions,
154154
primaryColor: typeof primaryColor === 'string' ? primaryColor : undefined,
155155
rememberLastLogin: undefined === options.rememberLastLogin ? true : !!options.rememberLastLogin,
156+
allowAutocomplete: !!options.allowAutocomplete,
156157
authButtonsTheme: typeof authButtons === 'object' ? authButtons : {}
157158
});
158159
}
@@ -183,7 +184,8 @@ export const ui = {
183184
popupOptions: lock => getUIAttribute(lock, 'popupOptions'),
184185
primaryColor: lock => getUIAttribute(lock, 'primaryColor'),
185186
authButtonsTheme: lock => getUIAttribute(lock, 'authButtonsTheme'),
186-
rememberLastLogin: m => tget(m, 'rememberLastLogin', getUIAttribute(m, 'rememberLastLogin'))
187+
rememberLastLogin: m => tget(m, 'rememberLastLogin', getUIAttribute(m, 'rememberLastLogin')),
188+
allowAutocomplete: m => tget(m, 'allowAutocomplete', getUIAttribute(m, 'allowAutocomplete'))
187189
};
188190

189191
const { get: getAuthAttribute } = dataFns(['core', 'auth']);
@@ -575,6 +577,9 @@ export function overrideOptions(m, opts) {
575577
if (typeof opts.rememberLastLogin === 'boolean') {
576578
m = tset(m, 'rememberLastLogin', opts.rememberLastLogin);
577579
}
580+
if (typeof opts.allowAutocomplete === 'boolean') {
581+
m = tset(m, 'allowAutocomplete', opts.allowAutocomplete);
582+
}
578583

579584
return m;
580585
}

src/field/email/email_pane.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default class EmailPane extends React.Component {
2626

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

3031
const field = c.getField(lock, 'email');
3132
const value = field.get('value', '');
@@ -44,6 +45,7 @@ export default class EmailPane extends React.Component {
4445
isValid={isValid}
4546
onChange={::this.handleChange}
4647
placeholder={placeholder}
48+
autoComplete={allowAutocomplete}
4749
/>
4850
);
4951
}

src/field/username/username_pane.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default class UsernamePane extends React.Component {
3434

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

@@ -62,6 +63,7 @@ export default class UsernamePane extends React.Component {
6263
isValid={!c.isFieldVisiblyInvalid(lock, 'username')}
6364
onChange={::this.handleChange}
6465
placeholder={placeholder}
66+
autoComplete={allowAutocomplete}
6567
/>
6668
);
6769
}

src/ui/input/email_input.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class EmailInput extends React.Component {
2323
}
2424

2525
render() {
26-
const { invalidHint, isValid, onChange, ...props } = this.props;
26+
const { invalidHint, isValid, onChange, autoComplete, ...props } = this.props;
2727
const { focused } = this.state;
2828

2929
return (
@@ -40,7 +40,7 @@ export default class EmailInput extends React.Component {
4040
name="email"
4141
className="auth0-lock-input"
4242
placeholder="yours@example.com"
43-
autoComplete="off"
43+
autoComplete={autoComplete ? 'on' : 'off'}
4444
autoCapitalize="off"
4545
onChange={::this.handleOnChange}
4646
onFocus={::this.handleFocus}

src/ui/input/username_input.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class UsernameInput extends React.Component {
2323
}
2424

2525
render() {
26-
const { invalidHint, isValid, onChange, ...props } = this.props;
26+
const { invalidHint, isValid, onChange, autoComplete, ...props } = this.props;
2727
const { focused } = this.state;
2828

2929
return (
@@ -40,7 +40,7 @@ export default class UsernameInput extends React.Component {
4040
name="username"
4141
className="auth0-lock-input"
4242
placeholder="username"
43-
autoComplete="off"
43+
autoComplete={autoComplete ? 'on' : 'off'}
4444
autoCapitalize="off"
4545
spellCheck="off"
4646
autoCorrect="off"

0 commit comments

Comments
 (0)