Skip to content

Commit

Permalink
[TextInput] Certain props should be optional (#381)
Browse files Browse the repository at this point in the history
[Short description explaining the high-level reason for the pull
request]

## Changes

- TextInput.tsx: Updated the property typing to fix an issue which
caused properties that should be optional, to be considered mandatory
instead.

## How to test this PR

1. View and verify the the deploy preview
2. Pull **308-ts-error-fix**
3. Run **yarn lint** against the branch
4. Verify that **TextInput.tsx** has no errors
5. Run **yarn test** against the branch and verify that everything
passes
6. Build the package
7. Update the **package.json** in **sbl-frontend** to include
**"design-system-react": "file:./<path-to-package.tgz>/package.tgz"**
8. Run **yarn install**
9. Pull **986-default-max-length** in **sbl-frontend**
10. Verify that **TextInput.tsx** in **sbl-frontend** has no errors
  • Loading branch information
tanner-ricks authored Oct 17, 2024
1 parent 546477b commit 7cfc2c1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/components/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classnames from 'classnames';
import type { Ref } from 'react';
import type { ComponentPropsWithoutRef } from 'react';
import { forwardRef, type ReactNode } from 'react';
import type { TextInputStatusType } from './TextInputStatus';
import { getTextInputStatusClass } from './TextInputStatus';
Expand All @@ -20,7 +20,7 @@ interface RequiredTextInputProperties {
name: string;
}

interface CustomTextInputProperties {
interface CustomTextInputProperties extends ComponentPropsWithoutRef<'input'> {
className?: string;
inputProps?: JSX.IntrinsicElements['input'];
inputRef?: TextInputReference;
Expand All @@ -30,16 +30,15 @@ interface CustomTextInputProperties {
isFullWidth?: boolean;
}

export type OptionalTextInputProperties = CustomTextInputProperties &
JSX.IntrinsicElements['input'];
export type OptionalTextInputProperties = CustomTextInputProperties;

export type TextInputProperties = OptionalTextInputProperties &
RequiredTextInputProperties;

/**
* Source: <a href='https://cfpb.github.io/design-system/components/text-inputs' target='_blank'> https://cfpb.github.io/design-system/components/text-inputs</a>
*/
export const TextInput = forwardRef(
export const TextInput = forwardRef<HTMLInputElement, TextInputProperties>(
(
{
className,
Expand All @@ -51,8 +50,8 @@ export const TextInput = forwardRef(
type = 'text',
isFullWidth = false,
...otherInputProperties
}: JSX.IntrinsicElements['input'] & TextInputProperties,
reference: Ref<HTMLInputElement>
},
reference
) => {
const classes = [
'a-text-input',
Expand Down

0 comments on commit 7cfc2c1

Please sign in to comment.