mirror of
https://github.com/haiwen/seahub.git
synced 2025-07-16 08:16:55 +00:00
fix rename click outside (#5656)
This commit is contained in:
parent
cf0b854b98
commit
c36e98cd39
@ -29,8 +29,22 @@ class Rename extends React.Component {
|
|||||||
} else {
|
} else {
|
||||||
this.inputRef.current.setSelectionRange(0, -1);
|
this.inputRef.current.setSelectionRange(0, -1);
|
||||||
}
|
}
|
||||||
|
// ensure real dom has been rendered, then listen the click event
|
||||||
|
setTimeout(() => {
|
||||||
|
document.addEventListener('click', this.onClick);
|
||||||
|
}, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
document.removeEventListener('click', this.onClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
onClick = (e) => {
|
||||||
|
if (!this.inputRef.current.contains(e.target)) {
|
||||||
|
this.onRenameConfirm();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
onChange = (e) => {
|
onChange = (e) => {
|
||||||
this.setState({name: e.target.value});
|
this.setState({name: e.target.value});
|
||||||
};
|
};
|
||||||
@ -45,7 +59,7 @@ class Rename extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onRenameConfirm = (e) => {
|
onRenameConfirm = (e) => {
|
||||||
e.nativeEvent.stopImmediatePropagation();
|
e && e.nativeEvent.stopImmediatePropagation();
|
||||||
let newName = this.state.name.trim();
|
let newName = this.state.name.trim();
|
||||||
if (newName === this.props.name) {
|
if (newName === this.props.name) {
|
||||||
this.props.onRenameCancel();
|
this.props.onRenameCancel();
|
||||||
@ -55,6 +69,7 @@ class Rename extends React.Component {
|
|||||||
let { isValid, errMessage } = this.validateInput();
|
let { isValid, errMessage } = this.validateInput();
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
toaster.danger(errMessage);
|
toaster.danger(errMessage);
|
||||||
|
this.props.onRenameCancel();
|
||||||
} else {
|
} else {
|
||||||
this.props.onRenameConfirm(newName);
|
this.props.onRenameConfirm(newName);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user