-
Notifications
You must be signed in to change notification settings - Fork 350
refactor(text-input): migrate TextInput from Flow to TypeScript #4760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mergify
merged 1 commit into
box:master
from
bonchevskyi:refactor/flow-to-ts-text-input
Aug 12, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
1 change: 0 additions & 1 deletion
1
...omponents/text-input/TextInput.stories.js → ...mponents/text-input/TextInput.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| // @flow | ||
| /* eslint-disable react-hooks/rules-of-hooks */ | ||
| import * as React from 'react'; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import * as React from 'react'; | ||
| import classNames from 'classnames'; | ||
| import uniqueId from 'lodash/uniqueId'; | ||
|
|
||
| import IconVerified from '../../icons/general/IconVerified'; | ||
|
|
||
| import Label from '../label'; | ||
| import LoadingIndicator from '../loading-indicator'; | ||
| import Tooltip, { TooltipPosition, TooltipTheme, type TooltipProps } from '../tooltip'; | ||
|
|
||
| import './TextInput.scss'; | ||
|
|
||
| export interface TextInputProps extends React.InputHTMLAttributes<HTMLInputElement> { | ||
| /** Add a class to the component */ | ||
| className?: string; | ||
| /** Description shown below the label */ | ||
| description?: React.ReactNode; | ||
| /** Error message shown in the error tooltip */ | ||
| error?: React.ReactNode; | ||
| /** Renders error tooltip at the specified position (positions are those from Tooltip) */ | ||
| errorPosition?: NonNullable<TooltipProps['position']>; | ||
| /** Hides the label */ | ||
| hideLabel?: boolean; | ||
| /** Hides (optional) text from the label */ | ||
| hideOptionalLabel?: boolean; | ||
| /** Icon to display in the input field */ | ||
| icon?: React.ReactNode; | ||
| /** Ref to the underlying input element. @TODO: eventually rename to innerRef for consistancy across all form elements */ | ||
| inputRef?: React.Ref<HTMLInputElement>; | ||
| /** Renders a loading indicator within the component when true */ | ||
| isLoading?: boolean; | ||
| /** Makes the input value required */ | ||
| isRequired?: boolean; | ||
| /** Renders a green verified checkmark within the component when true */ | ||
| isValid?: boolean; | ||
| /** Label displayed for the text input */ | ||
| label: React.ReactNode; | ||
| /** Tooltip shown on the label */ | ||
| labelTooltip?: React.ReactNode; | ||
| /** A CSS class for the tooltip's tether element component */ | ||
| tooltipTetherClassName?: string; | ||
| /** A CSS class for the tooltip's target wrapper element */ | ||
| tooltipWrapperClassName?: string; | ||
| } | ||
|
|
||
| const TextInput = ({ | ||
| className = '', | ||
| description, | ||
| error, | ||
| errorPosition, | ||
| hideLabel, | ||
| hideOptionalLabel, | ||
| icon, | ||
| inputRef, | ||
| isLoading, | ||
| isRequired, | ||
| isValid, | ||
| label, | ||
| labelTooltip, | ||
| tooltipTetherClassName: tetherElementClassName, | ||
| tooltipWrapperClassName, | ||
| ...rest | ||
| }: TextInputProps) => { | ||
| const hasError = !!error; | ||
| const classes = classNames(className, 'text-input-container', { | ||
| 'show-error': hasError, | ||
| }); | ||
|
|
||
| const descriptionID = React.useRef(uniqueId('description')).current; | ||
|
|
||
| const ariaAttrs = { | ||
| 'aria-invalid': hasError, | ||
| 'aria-required': isRequired, | ||
| 'aria-describedby': description ? descriptionID : undefined, | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={classes}> | ||
| <Label | ||
| hideLabel={hideLabel} | ||
| showOptionalText={!hideOptionalLabel && !isRequired} | ||
| text={label} | ||
| tooltip={labelTooltip} | ||
| > | ||
| <> | ||
| {!!description && ( | ||
| <div id={descriptionID} className="text-input-description"> | ||
| {description} | ||
| </div> | ||
| )} | ||
| <Tooltip | ||
| isShown={hasError} | ||
| position={errorPosition || TooltipPosition.MIDDLE_RIGHT} | ||
| targetWrapperClassName={tooltipWrapperClassName} | ||
| tetherElementClassName={tetherElementClassName} | ||
| text={error || ''} | ||
| theme={TooltipTheme.ERROR} | ||
| > | ||
| <input ref={inputRef} required={isRequired} {...ariaAttrs} {...rest} /> | ||
| </Tooltip> | ||
| {isLoading && !isValid && <LoadingIndicator className="text-input-loading" />} | ||
| {isValid && !isLoading && <IconVerified className="text-input-verified" />} | ||
| {!isLoading && !isValid && icon ? icon : null} | ||
| </> | ||
| </Label> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| TextInput.displayName = 'TextInput'; | ||
|
|
||
| export default TextInput; | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import * as React from 'react'; | ||
| import getProp from 'lodash/get'; | ||
| import type { FieldProps } from 'formik'; | ||
|
|
||
| import TextInputPrimitive from './TextInput'; | ||
| import type { TextInputProps } from './TextInput'; | ||
|
|
||
| export interface TextInputFieldProps extends Omit<TextInputProps, 'form'>, FieldProps { | ||
| /** Ref forwarded to the underlying input element as inputRef */ | ||
| innerRef?: (instance: HTMLInputElement | null) => void; | ||
| } | ||
|
|
||
| const TextInputField = ({ field, form, innerRef, isRequired, ...rest }: TextInputFieldProps) => { | ||
| const { name } = field; | ||
| const { errors, touched } = form; | ||
| const isTouched = getProp(touched, name); | ||
| const error = isTouched ? getProp(errors, name) : null; | ||
| return ( | ||
| <TextInputPrimitive | ||
| {...field} | ||
| {...rest} | ||
| inputRef={innerRef} | ||
| error={error as React.ReactNode} | ||
| hideOptionalLabel={isRequired} | ||
| /> | ||
|
bonchevskyi marked this conversation as resolved.
|
||
| ); | ||
| }; | ||
|
|
||
| export default TextInputField; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
...xt-input/__tests__/TextInputField.test.js → ...t-input/__tests__/TextInputField.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export { default } from './TextInput'; | ||
| export { default as TextInputField } from './TextInputField'; | ||
| export type { TextInputProps } from './TextInput'; | ||
| export type { TextInputFieldProps } from './TextInputField'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.