mirror of
https://github.com/haiwen/seahub.git
synced 2025-07-15 16:04:01 +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 {
|
||||
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) => {
|
||||
this.setState({name: e.target.value});
|
||||
};
|
||||
@ -45,7 +59,7 @@ class Rename extends React.Component {
|
||||
};
|
||||
|
||||
onRenameConfirm = (e) => {
|
||||
e.nativeEvent.stopImmediatePropagation();
|
||||
e && e.nativeEvent.stopImmediatePropagation();
|
||||
let newName = this.state.name.trim();
|
||||
if (newName === this.props.name) {
|
||||
this.props.onRenameCancel();
|
||||
@ -55,6 +69,7 @@ class Rename extends React.Component {
|
||||
let { isValid, errMessage } = this.validateInput();
|
||||
if (!isValid) {
|
||||
toaster.danger(errMessage);
|
||||
this.props.onRenameCancel();
|
||||
} else {
|
||||
this.props.onRenameConfirm(newName);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user