react-data-grid
上的提交由EditorContainer處理。提交邏輯很簡單。一位編輯提交當值:
- 編輯卸除
- 按下回車鍵
- Tab鍵被按下
- 在某些情況下,當按下箭頭(將跳過這一部分是它可能沒有必要對你來說,你可以看看基於
的方式,我會建議做自動保存在EditorContainer邏輯此)是:
創建一個EditorWrapper(HOC),您希望自動編輯節省
const editorWrapper(WrappedEditor) => {
return class EditorWrapper extends Component {
constructor(props) {
base(props);
this._changeCommitted = false;
this.handleKeyDown.bind(this);
}
handleKeyDown({ key, stopPropagation }) {
if (key === 'Tab' || key === 'Enter') {
stopPropagation();
this.save();
this.props.onCommit({ key });
this._changeCommitted = true;
}
// If you need the logic for the arrows too, check the editorContainer
}
save() {
// Save logic.
}
hasEscapeBeenPressed() {
let pressed = false;
let escapeKey = 27;
if (window.event) {
if (window.event.keyCode === escapeKey) {
pressed = true;
} else if (window.event.which === escapeKey) {
pressed = true;
}
}
return pressed;
}
componentWillUnmount() {
if (!this._changeCommitted && !this.hasEscapeBeenPressed()) {
this.save();
}
}
render() {
return (
<div onKeyDown={this.handleKeyDown}>
<WrappedComponent {...this.props} />
</div>);
}
}
}
被關在導出您編輯只是包裝他們與EditorWrapper
const Editor = ({ name }) => <div>{ name }</div>
export default EditorWrapper(Editor);
'事件。目標'應該有一個參考輸入? –