mirror of
https://github.com/strapi/strapi.git
synced 2025-08-07 00:09:23 +00:00
Unmount InputWithAutofocus after close
This commit is contained in:
parent
20d896c92a
commit
81a96bcc46
@ -1,6 +1,6 @@
|
||||
/**
|
||||
*
|
||||
* InputWithAutofocus that programatically manage the autofocus of another one
|
||||
* InputWithAutoFocus that programatically manage the autofocus of another one
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
@ -30,7 +30,7 @@ const getInputType = (attrType) => {
|
||||
};
|
||||
|
||||
|
||||
class InputWithAutofocus extends React.Component {
|
||||
class InputWithAutoFocus extends React.Component {
|
||||
componentDidMount() {
|
||||
if (this.props.filterToFocus === this.props.index) {
|
||||
return new Promise(resolve => {
|
||||
@ -63,7 +63,7 @@ class InputWithAutofocus extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
InputWithAutofocus.propTypes = {
|
||||
InputWithAutoFocus.propTypes = {
|
||||
filter: PropTypes.object.isRequired,
|
||||
filterToFocus: PropTypes.oneOfType([
|
||||
PropTypes.object,
|
||||
@ -76,4 +76,4 @@ InputWithAutofocus.propTypes = {
|
||||
schema: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
export default InputWithAutofocus;
|
||||
export default InputWithAutoFocus;
|
||||
|
@ -12,7 +12,7 @@ import InputSelect from 'components/InputSelect/Loadable';
|
||||
|
||||
import Add from './Add';
|
||||
import Div from './Div';
|
||||
import InputWithAutofocus from './InputWithAutofocus';
|
||||
import InputWithAutoFocus from './InputWithAutoFocus';
|
||||
import InputWrapper from './InputWrapper';
|
||||
import Remove from './Remove';
|
||||
|
||||
@ -50,7 +50,7 @@ function FilterOptions({ filter, filterToFocus, index, onChange, onClickAdd, onC
|
||||
/>
|
||||
<Wrapper>
|
||||
{show && (
|
||||
<InputWithAutofocus
|
||||
<InputWithAutoFocus
|
||||
filter={filter}
|
||||
filterToFocus={filterToFocus}
|
||||
index={index}
|
||||
|
@ -22,6 +22,8 @@ import SpanStyled from './SpanStyled';
|
||||
import Wrapper from './Wrapper';
|
||||
|
||||
class FiltersPickWrapper extends React.PureComponent {
|
||||
state = { showInput: false };
|
||||
|
||||
componentDidMount() {
|
||||
// Display the first filter
|
||||
if (this.props.appliedFilters.length === 0) {
|
||||
@ -36,6 +38,25 @@ class FiltersPickWrapper extends React.PureComponent {
|
||||
if (prevProps.show !== show && show && appliedFilters.length === 0) {
|
||||
this.handleClickAdd();
|
||||
}
|
||||
|
||||
if (prevProps.show !== show) {
|
||||
if (show) {
|
||||
this.mountInput();
|
||||
} else {
|
||||
this.unmountInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mountInput = () => this.setState({ showInput: true });
|
||||
|
||||
unmountInput = () => {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
this.setState({ showInput: false });
|
||||
resolve();
|
||||
}, 500);
|
||||
});
|
||||
}
|
||||
|
||||
generateActions = () => ([
|
||||
@ -137,7 +158,7 @@ class FiltersPickWrapper extends React.PureComponent {
|
||||
onClickAdd={this.handleClickAdd}
|
||||
onClickRemove={this.handleClickRemove}
|
||||
schema={schema}
|
||||
show={show}
|
||||
show={this.state.showInput}
|
||||
showAddButton={this.shouldDisplayAddButton(key)}
|
||||
/>
|
||||
))}
|
||||
|
Loading…
x
Reference in New Issue
Block a user