-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[TS migration] Migrate 'TextInput' component to TypeScript #31356
[TS migration] Migrate 'TextInput' component to TypeScript #31356
Conversation
Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers! |
…s-migration/TextInput/component
…s-migration/TextInput/component
…s-migration/TextInput/component
…s-migration/TextInput/component
…s-migration/TextInput/component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left comments.
src/components/TextInput/index.tsx
Outdated
textInputRef.current?.setAttribute('name', name); | ||
} | ||
// @ts-expect-error We need to reassign this ref to the input ref | ||
removeVisibilityListenerRef.current = Visibility.onVisibilityChange(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way you can get rid of @ts-expect-error
type RemoveVisibilityListener = () => void;
....
const removeVisibilityListenerRef = useRef<RemoveVisibilityListener>(null);
...
(removeVisibilityListenerRef.current as RemoveVisibilityListener) = Visibility.onVisibilityChange(() => {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VickyStash I fixed that using different approach since what you suggested was causing another error. Let me know what you think 😄
@fedirjh fixed! |
@fedirjh Would you be able to look at it today/tomorrow? This is blocking a ton of other TS issues 🙏 |
@blazejkustra Already started on it , I am blocked with this issue on native after last main merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on all platforms except native, it looks good and tests well, found minor bug with the input error message style.
// Add +2 to width on Safari browsers so that text is not cut off due to the cursor or when changing the value | ||
// https://github.com/Expensify/App/issues/8158 | ||
// https://github.com/Expensify/App/issues/26628 | ||
<Text | ||
style={[...props.inputStyle, props.autoGrowHeight && styles.autoGrowHeightHiddenInput(width, maxHeight), styles.hiddenElementOutsideOfWindow, styles.visibilityHidden]} | ||
style={[ | ||
inputStyle, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we did not destruct this style ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fedirjh There is no need for spreading styles props , it will work without that
<FormHelpMessage | ||
isError={!_.isEmpty(props.errorText)} | ||
isError={!errorText} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix that soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done @fedirjh
Animated.parallel([ | ||
Animated.spring(labelTranslateY, { | ||
toValue: translateY, | ||
duration: styleConst.LABEL_ANIMATION_DURATION, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this change affect the animation on native ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, actually there is no duration
option in for spring animation , so it was doing nothing
Reviewer Checklist
Screenshots/VideosAndroid: NativeCleanShot.2023-12-19.at.22.47.01.mp4iOS: NativeCleanShot.2023-12-19.at.19.42.40.mp4iOS: mWeb SafariCleanShot.2023-12-18.at.23.15.00.mp4 |
…s-migration/TextInput/component
@kubabutkiewicz Could you please merge main ? I hope that will fix this issue #31356 (comment) . |
…s-migration/TextInput/component
@fedirjh done! 😄 |
Bump @fedirjh 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and tests well.
We did not find an internal engineer to review this PR, trying to assign a random engineer to #25146 as well as to this PR... Please reach out for help on Slack if no one gets assigned! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I've got a decent amount of questions, mainly asking "why" since I'm still a typescript noob :D but one or two suggestions, and I'm recommending we can add any changes in a follow-up PR since this bad boi will unblock more issues!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB - most prop descriptions in this file are pretty weak / not descriptive. Maybe they came from somewhere else in the codebase (a.k.a. weren't added new here?) but it would be best to try to make them as clear as possible... Probably in a follow-up PR
|
||
const TextInput = forwardRef((props, ref) => { | ||
function TextInput(props: BaseTextInputProps, ref: BaseTextInputRef) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB - Question: Why aren't we destructuring props
here, but we do in other files like TextInputLabel
?
import isSelectorSupported from './isSelectorSupported'; | ||
|
||
/** | ||
* Check the input is auto filled or not | ||
*/ | ||
export default function isInputAutoFilled(input: Element): boolean { | ||
if (!input?.matches) { | ||
export default function isInputAutoFilled(input: (TextInput | HTMLElement) | null): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB - Is input: (TextInput | HTMLElement) | null
not funky? I would have expected input: (TextInput | HTMLElement | null)
to work and look better, no? I'd highly appreciate a lesson why it's necessary we do this, if anyone has the time 😅
autoCompleteType?: string; | ||
}; | ||
|
||
type BaseTextInputRef = ForwardedRef<HTMLFormElement | Component<AnimatedProps<TextInputProps>>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super NAB - can we use AnimatedTextInputRef
here like this?
type BaseTextInputRef = ForwardedRef<HTMLFormElement | Component<AnimatedProps<TextInputProps>>>; | |
type BaseTextInputRef = ForwardedRef<HTMLFormElement | AnimatedTextInputRef>; |
const onPress = (event) => { | ||
if (props.disabled) { | ||
const onPress = (event?: GestureResponderEvent | KeyboardEvent) => { | ||
if (!!inputProps.disabled || !event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB - Why do we need !!
in front of inputProps.disabled
?
|
||
if (!event.isDefaultPrevented()) { | ||
input.current.focus(); | ||
if ('isDefaultPrevented' in event && !event?.isDefaultPrevented()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like you've done this in lots of places, and forgive my ts-noobness please :D But why do we have to check 'isDefaultPrevented' in event
AND also use optional chaining event?.isDefaultPrevented
?
My guess is:
'isDefaultPrevented' in event
is to satisfy typescript- optional chaining is to make sure
isDefaultPrevented
is not undefined / null
Oh @kubabutkiewicz I would also recommend you close out old comments that don't apply anymore / are resolve, as during my review I came across some open threads and wasn't sure if you'd addressed them or forgotten about them 😅 let me know what you think! |
oops this may have broken type check on main |
@Beamanator #33796 will fix this |
Hi @Beamanator sorry I was OOO, if there is still some problem I can take a look or answer your questions! |
🚀 Deployed to staging by https://github.com/Beamanator in version: 1.4.21-0 🚀
|
🚀 Deployed to production by https://github.com/marcaaron in version: 1.4.21-4 🚀
|
1 similar comment
🚀 Deployed to production by https://github.com/marcaaron in version: 1.4.21-4 🚀
|
🚀 Deployed to production by https://github.com/marcaaron in version: 1.4.21-4 🚀
|
Details
Fixed Issues
$ #25146
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
android.mp4
Android: mWeb Chrome
iOS: Native
ios.mp4
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mp4
MacOS: Desktop
desktop.mp4