Skip to content

Commit 1f8be11

Browse files
refactor: disabled label animation and added props
1 parent 49b0758 commit 1f8be11

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

src/components/Input/Input.scss

+13
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ $input-placement: 16px;
8181
}
8282
}
8383
}
84+
&__fieldDisabled{
85+
width: 100%;
86+
outline: none;
87+
&::placeholder {
88+
visibility: hidden;
89+
}
90+
&:focus,
91+
&:not(:placeholder-shown) {
92+
& ~ label {
93+
visibility: hidden;
94+
}
95+
}
96+
}
8497

8598
&__label {
8699
display: inline-block;

src/components/Input/__test__/Input.test.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,10 @@ describe("Input", () => {
107107
expect(input).not.toHaveClass("deriv-input--error");
108108
expect(inputLabel).toHaveClass("deriv-input__label--disabled");
109109
});
110+
111+
it("should show disable label animation", () => {
112+
const {container}=render(<Input islabelAnimationDisabled {...props} />);
113+
const input = container.querySelector(".deriv-input__fieldDisabled");
114+
expect(input).toBeInTheDocument();
115+
});
110116
});

src/components/Input/index.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type InputVariants =
1111
| "disabled";
1212
interface InputProps extends Omit<ComponentProps<"input">, "placeholder"> {
1313
label?: string;
14+
islabelAnimationDisabled?: boolean;
1415
leftPlaceholder?: ReactNode;
1516
rightPlaceholder?: ReactNode;
1617
error?: boolean;
@@ -48,6 +49,7 @@ const LabelVariant: Record<InputVariants, string> = {
4849
* @interface InputProps
4950
* @extends {Omit<ComponentProps<"input">, "placeholder">}
5051
* @property {string} [label] - The label for the input field.
52+
* @property {boolean} [islabelAnimationDisabled] - The label for the input field.
5153
* @property {ReactNode} [leftPlaceholder] - The placeholder for the left side of the input field.
5254
* @property {ReactNode} [rightPlaceholder] - The placeholder for the right side of the input field.
5355
* @property {boolean} [error] - If true, the input field will display an error state.
@@ -86,6 +88,7 @@ export const Input = forwardRef(
8688
hideMessage,
8789
id,
8890
isFullWidth = false,
91+
islabelAnimationDisabled=false,
8992
label,
9093
leftPlaceholder,
9194
message,
@@ -123,7 +126,7 @@ export const Input = forwardRef(
123126
)}
124127
<input
125128
placeholder={label}
126-
className="deriv-input__field"
129+
className={clsx(islabelAnimationDisabled? "deriv-input__fieldDisabled" : "deriv-input__field" )}
127130
id={id}
128131
disabled={disabled}
129132
ref={ref}
@@ -147,16 +150,16 @@ export const Input = forwardRef(
147150
</div>
148151
)}
149152
</div>
150-
<div className="deriv-input__helper-message">
151153
{!hideMessage && message && (
154+
<div className="deriv-input__helper-message">
152155
<HelperMessage
153156
message={message}
154157
variant={variant}
155158
error={error}
156159
disabled={disabled}
157160
/>
161+
</div>
158162
)}
159-
</div>
160163
</div>
161164
);
162165
},

stories/Input.stories.tsx

+24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const meta = {
99
tags: ["autodocs"],
1010
args: {
1111
isFullWidth: false,
12+
islabelAnimationDisabled:false,
1213
label: "Enter Password",
1314
value: "",
1415
variant: "general",
@@ -196,3 +197,26 @@ export const RightPlaceholder: Story = {
196197
);
197198
},
198199
};
200+
201+
export const LabelAnimationDisabled: Story = {
202+
name: "Label Animation Disabled Input",
203+
args: {
204+
label: "Enter name",
205+
value: "",
206+
message: "This is a helper message",
207+
},
208+
render: (args) => {
209+
const [value, setValue] = useState("");
210+
211+
return (
212+
<div className="theme--light">
213+
<Input
214+
{...args}
215+
islabelAnimationDisabled
216+
value={value}
217+
onChange={(e) => setValue(e.target.value)}
218+
/>
219+
</div>
220+
);
221+
},
222+
};

0 commit comments

Comments
 (0)