Skip to content

Commit

Permalink
fix: Type the ref properly in the Input component (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
jherdman committed Mar 13, 2024
1 parent 9b8a0bb commit f8eb1fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
22 changes: 10 additions & 12 deletions src/Input/Input.tsx
Expand Up @@ -14,18 +14,16 @@ type InputProps = InputFieldProps &
className?: string;
};

const Input: React.FC<InputProps> = forwardRef<HTMLInputElement, InputProps>(
({ errorMessage, errorList, className, ...props }, ref) => {
const spaceProps = getSubset(props, propTypes.space);
const restProps = omitSubset(props, propTypes.space);
const Input = forwardRef<HTMLInputElement, InputProps>(({ errorMessage, errorList, className, ...props }, ref) => {
const spaceProps = getSubset(props, propTypes.space);
const restProps = omitSubset(props, propTypes.space);

return (
<Field className={className} {...spaceProps}>
<InputField {...restProps} error={!!(errorMessage || errorList)} ref={ref} />
<InlineValidation mt="x1" errorMessage={errorMessage} errorList={errorList} />
</Field>
);
}
);
return (
<Field className={className} {...spaceProps}>
<InputField {...restProps} error={!!(errorMessage || errorList)} ref={ref} />
<InlineValidation mt="x1" errorMessage={errorMessage} errorList={errorList} />
</Field>
);
});

export default Input;
8 changes: 4 additions & 4 deletions src/Input/InputField.tsx
Expand Up @@ -7,14 +7,14 @@ import { Box } from "../Box";
import { Flex } from "../Flex";
import { subPx } from "../utils";
import { MaybeFieldLabel } from "../FieldLabel";
import { DefaultNDSThemeType } from "../theme.type";
import type { DefaultNDSThemeType } from "../theme.type";
import { ComponentSize, useComponentSize } from "../NDSProvider/ComponentSizeContext";
import Prefix from "./Prefix";
import Suffix from "./Suffix";

type NativeInputProps = Omit<React.ComponentPropsWithRef<"input">, "size">;

export type InputFieldProps = NativeInputProps & {
export interface InputFieldProps extends NativeInputProps {
htmlSize?: number;
size?: ComponentSize;
icon?: string;
Expand All @@ -30,9 +30,9 @@ export type InputFieldProps = NativeInputProps & {
prefixAlignment?: "left" | "right";
iconSize?: string;
inputWidth?: string;
};
}

export const InputField: React.FC<InputFieldProps> = forwardRef<HTMLInputElement, InputFieldProps>(
export const InputField = forwardRef<HTMLInputElement, InputFieldProps>(
(
{
icon,
Expand Down

0 comments on commit f8eb1fa

Please sign in to comment.