gpt4 book ai didi

material-ui - 如何在 helpertext Material UI TextField 中添加 onClick 事件?

转载 作者:行者123 更新时间:2023-12-05 02:50:25 28 4
gpt4 key购买 nike

是否可以在 helperText Material UI TextField 中添加 onClick 事件?我可以在 1 个 TextField 中添加 2 个 helperText 吗?

<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
}}
/>

最佳答案

Is possible to add onClick event in helpertext Material UI TextField?

是的。您可以在 FormHelperTextProps 上包含一个 onClick 函数。

...
<TextField
variant="outlined"
placeholder="Write a comment..."
fullWidth
multiline
helperText="Hello world"
FormHelperTextProps={{
onClick: () => alert("Clicked!")
}}
/>

And can I add 2 helptext in 1 TextField?

如果我没理解错的话,您希望辅助文本有 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 />}
/>
);

Edit friendly-greider-iyvkz

关于material-ui - 如何在 helpertext Material UI TextField 中添加 onClick 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63683267/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com