1
0
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:
Michael An 2023-09-22 15:29:32 +08:00 committed by GitHub
parent cf0b854b98
commit c36e98cd39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}