mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-16 02:08:59 +05:30
Вызов фокуса после окончания анимации
This commit is contained in:
parent
64d8388a73
commit
3d0f8aa9c0
@ -42,34 +42,11 @@ export default class BaseAuthBody extends Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
autoFocus() {
|
||||||
* Fixes some issues with scroll, when input beeing focused
|
const fieldId = this.autoFocusField;
|
||||||
*
|
|
||||||
* When an element is focused, by default browsers will scroll its parents to display
|
|
||||||
* focused item to user. This behavior may cause unexpected visual effects, when
|
|
||||||
* you animating apearing of an input (e.g. transform) and auto focusing it. In
|
|
||||||
* that case the browser will scroll the parent container so that input will be
|
|
||||||
* visible.
|
|
||||||
* This method will fix that issue by finding parent with overflow: hidden and
|
|
||||||
* reseting its scrollLeft value to 0.
|
|
||||||
*
|
|
||||||
* Usage:
|
|
||||||
* <input autoFocus onFocus={this.fixAutoFocus} />
|
|
||||||
*
|
|
||||||
* @param {Object} event
|
|
||||||
*/
|
|
||||||
fixAutoFocus = (event) => {
|
|
||||||
let el = event.target;
|
|
||||||
|
|
||||||
while (el.parentNode) {
|
fieldId && this.form[fieldId] && this.form[fieldId].focus();
|
||||||
el = el.parentNode;
|
}
|
||||||
|
|
||||||
if (getComputedStyle(el).overflow === 'hidden') {
|
|
||||||
el.scrollLeft = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
serialize() {
|
serialize() {
|
||||||
return Object.keys(this.form).reduce((acc, key) => {
|
return Object.keys(this.form).reduce((acc, key) => {
|
||||||
|
@ -134,6 +134,8 @@ class PanelTransition extends Component {
|
|||||||
height: forceHeight ? common.style.switchContextHeightSpring : 'auto'
|
height: forceHeight ? common.style.switchContextHeightSpring : 'auto'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.tryToAutoFocus(panels.length);
|
||||||
|
|
||||||
const bodyHeight = {
|
const bodyHeight = {
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
height: `${canAnimateHeight ? common.style.heightSpring : formHeight}px`
|
height: `${canAnimateHeight ? common.style.heightSpring : formHeight}px`
|
||||||
@ -253,6 +255,26 @@ class PanelTransition extends Component {
|
|||||||
authFlow.goBack();
|
authFlow.goBack();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to auto focus form fields after transition end
|
||||||
|
*
|
||||||
|
* @param {number} length number of panels transitioned
|
||||||
|
*/
|
||||||
|
tryToAutoFocus(length) {
|
||||||
|
if (!this.body) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length === 1) {
|
||||||
|
if (!this.wasAutoFocused) {
|
||||||
|
this.body.autoFocus();
|
||||||
|
}
|
||||||
|
this.wasAutoFocused = true;
|
||||||
|
} else if (this.wasAutoFocused) {
|
||||||
|
this.wasAutoFocused = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getHeader({key, style, data}) {
|
getHeader({key, style, data}) {
|
||||||
const {Title, hasBackButton} = data;
|
const {Title, hasBackButton} = data;
|
||||||
const {transformSpring} = style;
|
const {transformSpring} = style;
|
||||||
|
@ -14,6 +14,8 @@ class Body extends BaseAuthBody {
|
|||||||
static displayName = 'ActivationBody';
|
static displayName = 'ActivationBody';
|
||||||
static panelId = 'activation';
|
static panelId = 'activation';
|
||||||
|
|
||||||
|
autoFocusField = 'key';
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -32,8 +34,6 @@ class Body extends BaseAuthBody {
|
|||||||
<Input {...this.bindField('key')}
|
<Input {...this.bindField('key')}
|
||||||
color="blue"
|
color="blue"
|
||||||
className={styles.activationCodeInput}
|
className={styles.activationCodeInput}
|
||||||
autoFocus
|
|
||||||
onFocus={this.fixAutoFocus}
|
|
||||||
required
|
required
|
||||||
placeholder={messages.enterTheCode}
|
placeholder={messages.enterTheCode}
|
||||||
/>
|
/>
|
||||||
|
@ -15,6 +15,8 @@ class Body extends BaseAuthBody {
|
|||||||
static displayName = 'ChangePasswordBody';
|
static displayName = 'ChangePasswordBody';
|
||||||
static panelId = 'changePassword';
|
static panelId = 'changePassword';
|
||||||
|
|
||||||
|
autoFocusField = 'password';
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -32,8 +34,6 @@ class Body extends BaseAuthBody {
|
|||||||
icon="key"
|
icon="key"
|
||||||
color="darkBlue"
|
color="darkBlue"
|
||||||
type="password"
|
type="password"
|
||||||
autoFocus
|
|
||||||
onFocus={this.fixAutoFocus}
|
|
||||||
required
|
required
|
||||||
placeholder={messages.currentPassword}
|
placeholder={messages.currentPassword}
|
||||||
/>
|
/>
|
||||||
|
@ -16,6 +16,8 @@ class Body extends BaseAuthBody {
|
|||||||
static panelId = 'forgotPassword';
|
static panelId = 'forgotPassword';
|
||||||
static hasGoBack = true;
|
static hasGoBack = true;
|
||||||
|
|
||||||
|
autoFocusField = 'email';
|
||||||
|
|
||||||
// Если юзер вводил своё мыло во время попытки авторизации, то почему бы его сюда автоматически не подставить?
|
// Если юзер вводил своё мыло во время попытки авторизации, то почему бы его сюда автоматически не подставить?
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -29,8 +31,6 @@ class Body extends BaseAuthBody {
|
|||||||
<Input {...this.bindField('email')}
|
<Input {...this.bindField('email')}
|
||||||
icon="envelope"
|
icon="envelope"
|
||||||
color="lightViolet"
|
color="lightViolet"
|
||||||
autoFocus
|
|
||||||
onFocus={this.fixAutoFocus}
|
|
||||||
required
|
required
|
||||||
placeholder={messages.accountEmail}
|
placeholder={messages.accountEmail}
|
||||||
/>
|
/>
|
||||||
|
@ -15,6 +15,8 @@ class Body extends BaseAuthBody {
|
|||||||
static displayName = 'LoginBody';
|
static displayName = 'LoginBody';
|
||||||
static panelId = 'login';
|
static panelId = 'login';
|
||||||
|
|
||||||
|
autoFocusField = 'login';
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -22,8 +24,6 @@ class Body extends BaseAuthBody {
|
|||||||
|
|
||||||
<Input {...this.bindField('login')}
|
<Input {...this.bindField('login')}
|
||||||
icon="envelope"
|
icon="envelope"
|
||||||
autoFocus
|
|
||||||
onFocus={this.fixAutoFocus}
|
|
||||||
required
|
required
|
||||||
placeholder={messages.emailOrUsername}
|
placeholder={messages.emailOrUsername}
|
||||||
/>
|
/>
|
||||||
|
@ -17,6 +17,8 @@ class Body extends BaseAuthBody {
|
|||||||
static panelId = 'password';
|
static panelId = 'password';
|
||||||
static hasGoBack = true;
|
static hasGoBack = true;
|
||||||
|
|
||||||
|
autoFocusField = 'password';
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {user} = this.context;
|
const {user} = this.context;
|
||||||
|
|
||||||
@ -38,8 +40,6 @@ class Body extends BaseAuthBody {
|
|||||||
<Input {...this.bindField('password')}
|
<Input {...this.bindField('password')}
|
||||||
icon="key"
|
icon="key"
|
||||||
type="password"
|
type="password"
|
||||||
autoFocus
|
|
||||||
onFocus={this.fixAutoFocus}
|
|
||||||
required
|
required
|
||||||
placeholder={messages.accountPassword}
|
placeholder={messages.accountPassword}
|
||||||
/>
|
/>
|
||||||
|
@ -16,6 +16,8 @@ class Body extends BaseAuthBody {
|
|||||||
static displayName = 'RegisterBody';
|
static displayName = 'RegisterBody';
|
||||||
static panelId = 'register';
|
static panelId = 'register';
|
||||||
|
|
||||||
|
autoFocusField = 'username';
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -25,8 +27,6 @@ class Body extends BaseAuthBody {
|
|||||||
icon="user"
|
icon="user"
|
||||||
color="blue"
|
color="blue"
|
||||||
type="text"
|
type="text"
|
||||||
autoFocus
|
|
||||||
onFocus={this.fixAutoFocus}
|
|
||||||
required
|
required
|
||||||
placeholder={messages.yourNickname}
|
placeholder={messages.yourNickname}
|
||||||
/>
|
/>
|
||||||
|
@ -56,6 +56,11 @@ export class Input extends Component {
|
|||||||
getValue() {
|
getValue() {
|
||||||
return this.el.value;
|
return this.el.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
focus() {
|
||||||
|
this.el.focus();
|
||||||
|
setTimeout(this.el.focus.bind(this.el), 10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Checkbox extends Component {
|
export class Checkbox extends Component {
|
||||||
@ -86,6 +91,10 @@ export class Checkbox extends Component {
|
|||||||
getValue() {
|
getValue() {
|
||||||
return this.el.checked ? 1 : 0;
|
return this.el.checked ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
focus() {
|
||||||
|
this.el.focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Form extends Component {
|
export class Form extends Component {
|
||||||
|
Loading…
Reference in New Issue
Block a user