Skip to content

Commit

Permalink
fix: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimao committed Feb 5, 2024
1 parent 807e22a commit a35fe77
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/components/src/Input/BaseInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
useRef,
useState
} from 'react';
import { ElementTypeProp } from 'src/utils/types';

import { ElementTypeProp } from '../utils/types';
import { Field, FieldProps, useFieldProps } from '../Field';
import { HelperTextProps } from '../HelperText';
import { LabelProps } from '../Label';
Expand Down
9 changes: 7 additions & 2 deletions packages/components/src/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ type Props = {
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
};

type InheritAttrs = Omit<BaseInputProps, keyof Props | 'errorMessageProps' | 'descriptionProps' | 'inputProps'>;
type InheritAttrs = Omit<
BaseInputProps,
keyof Props | 'errorMessageProps' | 'descriptionProps' | 'inputProps' | 'elementType'
>;

type AriaAttrs = Omit<AriaTextFieldOptions<'input'>, (keyof Props & InheritAttrs) | 'onChange'>;

type InputProps = Props & InheritAttrs & AriaAttrs;

const elementType = 'input';

const Input = forwardRef<HTMLInputElement, InputProps>(
({ isInvalid, onValueChange, onChange, elementType = 'input', ...props }, ref): JSX.Element => {
({ isInvalid, onValueChange, onChange, ...props }, ref): JSX.Element => {
const inputRef = useDOMRef(ref);
// We are specifing `validationState` so that when there are errors, `aria-invalid` is set to `true`
const { inputProps, descriptionProps, errorMessageProps, labelProps } = useTextField(
Expand Down
12 changes: 10 additions & 2 deletions packages/components/src/NumberInput/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ type Props = {
value?: string | number;
defaultValue?: string | number;
onValueChange?: (value: string | number) => void;
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
inputMode?: 'numeric' | 'decimal';
};

type InheritAttrs = Omit<BaseInputProps, keyof Props | 'errorMessageProps' | 'descriptionProps' | 'inputProps'>;
type InheritAttrs = Omit<
BaseInputProps,
keyof Props | 'errorMessageProps' | 'descriptionProps' | 'inputProps' | 'elementType'
>;

type AriaAttrs = Omit<AriaTextFieldOptions<'input'>, keyof (Props & InheritAttrs)>;

type NumberInputProps = Props & InheritAttrs & AriaAttrs;

const elementType = 'input';

// FIXME: some event are running duplicate
const NumberInput = forwardRef<HTMLInputElement, NumberInputProps>(
(
Expand Down Expand Up @@ -56,7 +62,8 @@ const NumberInput = forwardRef<HTMLInputElement, NumberInputProps>(
inputMode,
isInvalid: isInvalid || !!props.errorMessage,
value: value,
autoComplete: 'off'
autoComplete: 'off',
inputElementType: elementType
},
inputRef
);
Expand All @@ -72,6 +79,7 @@ const NumberInput = forwardRef<HTMLInputElement, NumberInputProps>(
ref={inputRef}
autoCorrect='off'
descriptionProps={descriptionProps}
elementType={elementType}
errorMessageProps={errorMessageProps}
inputProps={mergeProps(inputProps, { onChange: handleChange })}
labelProps={labelProps}
Expand Down
9 changes: 7 additions & 2 deletions packages/components/src/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ type Props = {
onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
};

type InheritAttrs = Omit<BaseInputProps, keyof Props | 'errorMessageProps' | 'descriptionProps' | 'inputProps'>;
type InheritAttrs = Omit<
BaseInputProps,
keyof Props | 'errorMessageProps' | 'descriptionProps' | 'inputProps' | 'elementType'
>;

type AriaAttrs = Omit<AriaTextFieldOptions<'textarea'>, (keyof Props & InheritAttrs) | 'onChange'>;

type TextAreaProps = Props & InheritAttrs & AriaAttrs;

const elementType = 'textarea';

const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
({ isInvalid, onValueChange, onChange, elementType = 'textarea', ...props }, ref): JSX.Element => {
({ isInvalid, onValueChange, onChange, ...props }, ref): JSX.Element => {
const inputRef = useDOMRef(ref);
// We are specifing `validationState` so that when there are errors, `aria-invalid` is set to `true`
const { inputProps, descriptionProps, errorMessageProps, labelProps } = useTextField(
Expand Down

0 comments on commit a35fe77

Please sign in to comment.