【发布时间】:2020-03-01 03:32:21
【问题描述】:
对于我的 React 应用程序,我正在尝试使用来自 Antd 的模板构建一个带有 浮动标签 的表单,该模板具有不同的输入类型,仅使用样式来使标签浮动。到目前为止,我已经能够将标签放在输入后面,但是当我将转换 + 转换应用于我的 css 代码时,它似乎根本不起作用。
这是我的表格的一部分:
switch (data.inputType) {
case 'input':
return (
<Form.Item key={`frmItem-${data.id}`}>
<label htmlFor={data.id} className="floating-label">
{data.label}
</label>
<Input
key={`input-${data.id}`}
id={data.id}
className="floating-label-field"
project-field={data.id}
defaultValue={projectData[data.id]}
onChange={handleUpload}
// placeholder={data.placeholder}
allowClear
/>
</Form.Item>
)
这是我的 style.js:
export const StyledFormDiv = styled.div`
.ant-form-item {
position: relative;
}
.ant-form-item-control {
height: 50px;
}
/* Floating label */
.floating-label {
/* top: 0; */
/* left: 0; */
position: absolute;
/* z-index: 500; */
/* transform: translate(0, 25px) scale(1); */
/* transition: color 200ms cubic-bezier(0, 0, 0.2, 1) 0ms, */
/* transform 200ms cubic-bezier(0, 0, 0.2, 1) 0ms; */
/* transition: width 0.4s ease; */
}
.floating-label-field {
/* position: absolute; */
/* touch-action: manipulation; */
border-bottom: 1px solid #000 !important;
border-radius: 0;
box-shadow: none;
width: 100%;
/* transition: transform 0.25s, opacity 0.25s ease-in-out; */
/* transform-origin: 0 0; */
/* opacity: 0.5; */
/* transition: padding-top 0.2s ease, margin-top 0.2s ease; */
&::placeholder {
color: transparent;
}
}
我认为 antd 可能有一些东西不允许我浮动标签,但我想要一种解决方法,不必安装另一个包或制作另一个组件。
【问题讨论】:
-
请制作一个沙盒,尝试描述“浮动标签”的含义。对您来说,它可能被称为“浮动”,请向我们展示您除了标签之外的期望行为。
-
另外,请注意,当
Form.Item的行为类似于标签时,为label设置样式是没有意义的。
标签: javascript css node.js reactjs antd