From ae90c40ddea7b9082d776ec2178a839fadbcecca Mon Sep 17 00:00:00 2001 From: Michael An <2331806369@qq.com> Date: Tue, 5 Sep 2023 20:21:24 +0800 Subject: [PATCH] change rename UI (#5625) --- frontend/src/components/rename.js | 26 ++++++++++++-------------- frontend/src/utils/utils.js | 1 + media/css/seahub_react.css | 16 ++-------------- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/frontend/src/components/rename.js b/frontend/src/components/rename.js index 23dba50365..cd1530bbf5 100644 --- a/frontend/src/components/rename.js +++ b/frontend/src/components/rename.js @@ -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 (
- -
); } diff --git a/frontend/src/utils/utils.js b/frontend/src/utils/utils.js index 6acf7cf93b..a3484b7544 100644 --- a/frontend/src/utils/utils.js +++ b/frontend/src/utils/utils.js @@ -8,6 +8,7 @@ import { compareTwoString } from './compare-two-string'; export const Utils = { keyCodes: { + enter: 13, esc: 27, space: 32, tab: 9, diff --git a/media/css/seahub_react.css b/media/css/seahub_react.css index 236a743aff..677ce185ad 100644 --- a/media/css/seahub_react.css +++ b/media/css/seahub_react.css @@ -984,7 +984,8 @@ table td { .rename-container input { box-sizing: content-box; padding: 2px 3px; - width: 10rem; + width: 20rem; + max-width: 100%; height: 22px; line-height: 19px; border-radius: 2px; @@ -1000,19 +1001,6 @@ table td { box-shadow: 0 0 0 2px rgba(70, 127, 207, 0.25); } -.rename-container button { - margin-left: 0.25rem; - padding: 5px 6px; - font-size: 1rem; - line-height: 1; - color: #666; - min-width: 0; -} - -.rename-container .confirm { - color: green; -} - @media (max-width: 767px) { .rename-container input { width: 10rem;