<InlineEditInput/>
用户在组件上按 Enter 后,我尝试实现 focus()<br>
尝试使用 useRef 但无法正常实现<br>
库react-continentable
const InlineEditInput = ({ onUpdate, placeholder, data, value, url, name }) => {
const classes = useStyles();
const text = useRef(value);
const onKeyPress = (e) => {
if (e.key === 'Enter') {
e.preventDefault();
}
};
const handleChange = (evt) => {
text.current = evt.target.value;
};
return (
<ContentEditable
innerRef={text}
className={classes.input}
html={text.current}
onKeyPress={onKeyPress}
onChange={handleChange}
/>
);
};
我的这张表是这样的:
<Table.Row key={ID}>
<Table.Cell>
<InlineEditInput value={`$${original_balance}`}></InlineEditInput>
</Table.Cell>
<Table.Cell>
<InlineEditInput value={`${rate}%`}></InlineEditInput>
</Table.Cell>
<Table.Cell>
<InlineEditInput value={`$${payment}`}></InlineEditInput>
</Table.Cell>
</Table.Row>