是否可以在onClick
物质用户界面helperText
中添加TextField
事件?我可以在1 helperText
中添加2 TextField
吗?
<TextField
variant="outlined"
placeholder="Write a comment..."
fullWidth
multiline
className={classes.tfCmt}
onChange={this.handleAddComment}
onFocus={this.handleAppearSaveBtn}
helperText={visibleSaveBtn && "Save"}
FormHelperTextProps={{
className: classes.btnAction
}}
/>
答案 0 :(得分:2)
是否可以在helpertext材质用户界面TextField中添加onClick事件?
是的。您可以在onClick
上包含一个FormHelperTextProps
函数。
...
<TextField
variant="outlined"
placeholder="Write a comment..."
fullWidth
multiline
helperText="Hello world"
FormHelperTextProps={{
onClick: () => alert("Clicked!")
}}
/>
我可以在1个TextField中添加2个帮助文本吗?
如果我的理解正确,您希望有2个用于辅助文本的元素。您可以创建一个组件并将其作为helperText
道具传递给TextField
组件。
...
function HelperTexts() {
const helperTexts = [
{
id: 1,
value: "helper text 1"
},
{
id: 2,
value: "helper text 2"
}
];
return helperTexts.map((text) => (
<span key={text.id} data-id={text.id} className="helper-text">
{text.value}
</span>
));
}
return (
<TextField
variant="outlined"
placeholder="Write a comment..."
fullWidth
multiline
helperText={<HelperTexts />}
/>
);