Skip to content

Commit

Permalink
Add invalidHint to phoneNumberInput (#1837)
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Hobbs <[email protected]>
  • Loading branch information
blankg and Steve Hobbs authored Apr 2, 2020
1 parent 3fbb95c commit 1faf464
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ exports[`PhoneNumberPane disables input when submitting 1`] = `
<div
data-__type="phone_number_input"
data-disabled={true}
data-invalidHint={undefined}
data-isValid={false}
data-onChange={[Function]}
data-placeholder="placeholder"
Expand All @@ -55,6 +56,7 @@ exports[`PhoneNumberPane renders correctly 1`] = `
<div
data-__type="phone_number_input"
data-disabled={false}
data-invalidHint={undefined}
data-isValid={false}
data-onChange={[Function]}
data-placeholder="placeholder"
Expand All @@ -77,6 +79,7 @@ exports[`PhoneNumberPane sets isValid as true when \`isFieldVisiblyInvalid\` is
<div
data-__type="phone_number_input"
data-disabled={false}
data-invalidHint={undefined}
data-isValid={true}
data-onChange={[Function]}
data-placeholder="placeholder"
Expand Down Expand Up @@ -104,6 +107,7 @@ exports[`PhoneNumberPane shows header when instructions are available 1`] = `
<div
data-__type="phone_number_input"
data-disabled={false}
data-invalidHint={undefined}
data-isValid={false}
data-onChange={[Function]}
data-placeholder="placeholder"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Component = ({ i18n, model }) => {
instructions={i18n.html(phoneNumberInstructionsI18nKey)}
lock={model}
placeholder={i18n.str('phoneNumberInputPlaceholder')}
invalidHint={i18n.str('phoneNumberInputInvalidHint')}
/>
) : null;

Expand Down
6 changes: 4 additions & 2 deletions src/field/phone-number/phone_number_pane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class PhoneNumberPane extends React.Component {
}

render() {
const { instructions, lock, placeholder } = this.props;
const { instructions, lock, placeholder, invalidHint } = this.props;
const headerText = instructions || null;
const header = headerText && <p>{headerText}</p>;

Expand All @@ -38,6 +38,7 @@ export default class PhoneNumberPane extends React.Component {
<PhoneNumberInput
value={c.phoneNumber(lock)}
isValid={!c.isFieldVisiblyInvalid(lock, 'phoneNumber')}
invalidHint={invalidHint}
onChange={::this.handlePhoneNumberChange}
placeholder={placeholder}
disabled={l.submitting(lock)}
Expand All @@ -50,5 +51,6 @@ export default class PhoneNumberPane extends React.Component {
PhoneNumberPane.propTypes = {
instructions: PropTypes.element,
lock: PropTypes.object.isRequired,
placeholder: PropTypes.string.isRequired
placeholder: PropTypes.string.isRequired,
invalidHint: PropTypes.string
};
13 changes: 11 additions & 2 deletions src/ui/input/phone_number_input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ export default class PhoneNumberInput extends React.Component {
}

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

return (
<InputWrap focused={focused} isValid={isValid} name="phone-number" icon={svg}>
<InputWrap
focused={focused}
isValid={isValid}
invalidHint={invalidHint}
name="phone-number"
icon={svg}
>
<input
ref="input"
type="tel"
Expand All @@ -26,6 +32,9 @@ export default class PhoneNumberInput extends React.Component {
onBlur={::this.handleBlur}
aria-label="Telephone number"
aria-invalid={!isValid}
aria-describedby={
!isValid && invalidHint ? `auth0-lock-error-msg-phone-number` : undefined
}
{...props}
/>
</InputWrap>
Expand Down

0 comments on commit 1faf464

Please sign in to comment.