【发布时间】:2023-01-13 20:53:03
【问题描述】:
你好开发社区我在这里有另一个问题需要你的帮助。
我想根据布尔状态禁用输入字段,如果状态为真,则输入字段应禁用,否则它可以编辑。
我的状态变量是 True,它可以是 true 或 false,这是代码
export function InputFiled(props) {
return (
<>
<input
className="py-2 pl-3 rounded-[14px] border-[1.3px] border-red-500"
placeholder={"Name"}
onChange={(e) => props.setData(e.target.value)}
value={props.data}
{...(!props.isTrue && "disabled")}
// here (below) it works fine but it is permanently disabled option
// disabled
/>
</>
);
}
我从附件 (Conditional disabling of button) 问题中得到的解决方案是:
export function InputFiled(props) {
return (
<>
<input
className="py-2 pl-3 rounded-[14px] border-[1.3px] border-red-500"
placeholder={"Name"}
onChange={(e) => props.setData(e.target.value)}
value={props.data}
disabled={props.isTrue? true : false}
/>
</>
);
}
【问题讨论】:
标签: javascript reactjs tailwind-in-js tailwind