1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 07:55:36 +00:00

change rename UI (#5625)

This commit is contained in:
Michael An
2023-09-05 20:21:24 +08:00
committed by GitHub
parent cb6b60d301
commit ae90c40dde
3 changed files with 15 additions and 28 deletions

View File

@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { gettext } from '../utils/constants';
import { Utils } from '../utils/utils';
import toaster from './toast';
const propTypes = {
@@ -17,15 +18,16 @@ class Rename extends React.Component {
this.state = {
name: props.name
};
this.inputRef = React.createRef();
}
componentDidMount() {
this.refs.renameInput.focus();
this.inputRef.current.focus();
if (this.props.hasSuffix) {
var endIndex = this.props.name.lastIndexOf('.');
this.refs.renameInput.setSelectionRange(0, endIndex, 'forward');
this.inputRef.current.setSelectionRange(0, endIndex, 'forward');
} else {
this.refs.renameInput.setSelectionRange(0, -1);
this.inputRef.current.setSelectionRange(0, -1);
}
}
@@ -33,14 +35,13 @@ class Rename extends React.Component {
this.setState({name: e.target.value});
}
onClick = (e) => {
e.nativeEvent.stopImmediatePropagation();
}
onKeyPress = (e) => {
if (e.key === 'Enter') {
onKeyDown = (e) => {
if (e.keyCode === Utils.keyCodes.enter) {
this.onRenameConfirm(e);
} else if (e.keyCode === Utils.keyCodes.esc) {
this.onRenameCancel(e);
}
e.nativeEvent.stopImmediatePropagation();
}
onRenameConfirm = (e) => {
@@ -87,14 +88,11 @@ class Rename extends React.Component {
return (
<div className="rename-container">
<input
ref="renameInput"
ref={this.inputRef}
value={this.state.name}
onChange={this.onChange}
onKeyPress={this.onKeyPress}
onClick={this.onClick}
onKeyDown={this.onKeyDown}
/>
<button className="btn btn-secondary sf2-icon-confirm confirm" onClick={this.onRenameConfirm}></button>
<button className="btn btn-secondary sf2-icon-cancel cancel" onClick={this.onRenameCancel}></button>
</div>
);
}