Skip to content

Commit

Permalink
Input forwardRef
Browse files Browse the repository at this point in the history
  • Loading branch information
vhande committed Jun 27, 2024
1 parent 410fd61 commit 46f085b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions resources/ts/Components/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import type { ComponentProps } from "react";
import React, { forwardRef } from "react";
import type { ComponentProps, ForwardedRef } from "react";
import { classNames } from "../utils/classNames";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import type { IconProp } from "@fortawesome/fontawesome-svg-core";
Expand All @@ -9,14 +9,10 @@ type Props = ComponentProps<"input"> & {
inputId?: string;
};

export const Input = ({
children,
className,
iconBack,
disabled,
inputId,
...props
}: Props) => {
const InputComponent = (
{ children, className, iconBack, disabled, inputId, ...props }: Props,
ref: ForwardedRef<HTMLInputElement>
) => {
return (
<div className={classNames("block relative w-full", className)}>
<input
Expand All @@ -27,6 +23,7 @@ export const Input = ({
)}
disabled={disabled}
id={inputId}
ref={ref}
{...props}
>
{children}
Expand All @@ -40,3 +37,5 @@ export const Input = ({
</div>
);
};

export const Input = forwardRef(InputComponent);

0 comments on commit 46f085b

Please sign in to comment.