155
rated 0 times
[
162]
[
7]
/ answers: 1 / hits: 16336
/ 5 Years ago, mon, november 4, 2019, 12:00:00
For my React app, I'm trying to build a form with floating labels using a template from Antd with different input types using only styles to make the labels float. So far I've been able to put the label behind the input, but when I apply transition + transform to my css code it seems to not work at all.
This is part of my form:
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>
)
And this is my 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;
}
}
I think maybe there is something with antd not allowing me to float the labels, but I would like a workaround not having to install another package or making another component.
More From » css