-
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
[HOLD for payment 2024-03-11] [HOLD for payment 2024-02-20][$1000] Form: Inconsistent text input submitting experience between mWeb and Native #31433
Comments
Triggered auto assignment to @conorpendergrast ( |
Job added to Upwork: https://www.upwork.com/jobs/~01d451a9a0af00ce03 |
Bug0 Triage Checklist (Main S/O)
|
Triggered auto assignment to Contributor-plus team member for initial proposal review - @cubuspl42 ( |
ProposalPlease re-state the problem that we are trying to solve in this issue.Typing status and pressing What is the root cause of that problem?As you can see below, we disabled the App/src/components/Form/FormWrapper.js Line 154 in 69a3358
How does 'Enter' key works on web? App/src/components/Form/FormWrapper.js Lines 109 to 113 in 6ea4539
And FormSubmit button has keydown handler on web as belowApp/src/components/FormSubmit/index.js Lines 22 to 26 in 6ea4539
That's why pressing Enter calls onSubmit for web, but doesn't for native
This is the root cause What changes do you think we should make in order to solve the problem?This issue happens wherever In order to solve this issue, we can enable
This works as expected Result31433.mp4What alternative solutions did you explore? (Optional) |
ProposalPlease re-state the problem that we are trying to solve in this issue.Entering status message & tapping enter show different behaviour in mWeb and Android What is the root cause of that problem?When we tap App/src/components/Form/FormWrapper.js Lines 109 to 113 in 6ea4539
What changes do you think we should make in order to solve the problem?We can take advantage of the This will take care of both web and native implementation Complete Explanation We have 2 ways to go about this Option A (Nuking the submit logic inside
|
const submitForm = (event: KeyboardEvent) => { | |
// ENTER is pressed with modifier key or during text composition, do not submit the form | |
if (event.shiftKey || event.key !== CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey || isEnterWhileComposition(event)) { | |
return; | |
} | |
const eventTarget = event.target as HTMLElement; | |
const tagName = eventTarget?.tagName ?? ''; | |
// ENTER is pressed on INPUT or SELECT element, call the submit callback. | |
if (tagName === 'INPUT' || tagName === 'SELECT') { | |
onSubmit(); | |
return; | |
} | |
// Pressing Enter on TEXTAREA element adds a new line. When `dataset.submitOnEnter` prop is passed, call the submit callback. | |
if (tagName === 'TEXTAREA' && (eventTarget?.dataset?.submitOnEnter ?? 'false') === 'true') { | |
event.preventDefault(); | |
onSubmit(); | |
return; | |
} | |
// ENTER is pressed on checkbox element, call the submit callback. | |
if (eventTarget?.role === 'checkbox') { | |
onSubmit(); | |
} | |
}; | |
const preventDefaultFormBehavior = (e: SubmitEvent) => e.preventDefault(); | |
useEffect(() => { | |
if (!(ref && 'current' in ref)) { | |
return; | |
} | |
const form = ref.current as HTMLFormElement | null; | |
if (!form) { | |
return; | |
} | |
// Prevent the browser from applying its own validation, which affects the email input | |
form.setAttribute('novalidate', ''); | |
form.addEventListener('submit', preventDefaultFormBehavior); | |
return () => { | |
if (!form) { | |
return; | |
} | |
form.removeEventListener('submit', preventDefaultFormBehavior); | |
}; | |
}, [ref]); |
and also onKeyDownCapture={submitForm}
This logic is getting removed as it is spitting image of react-native-web
implementation of onSubmitEditing
, except for multiline behavior, which will be taken care inside onSubmitEditing
implementation described later.
And now instead will use onSubmitEditing
prop which will be introduced inside
App/src/components/Form/FormProvider.js
Line 240 in 1f8e365
const registerInput = useCallback( |
As registerInput
function returns props to the component which we desire to use inside of the component of the Form Inputs.
For adhering to the guidelines of the FORMS.md
, we will not pass onSubmitEditing
prop when we use multiline
or autoGrowHeight
prop for TextInput
(only exception is submitOnEnter
is passed as true). See
App/src/components/TextInput/BaseTextInput/index.tsx
Lines 384 to 386 in 1f8e365
// FormSubmit Enter key handler does not have access to direct props. | |
// `dataset.submitOnEnter` is used to indicate that pressing Enter on this input should call the submit callback. | |
dataSet={{submitOnEnter: isMultiline && submitOnEnter}} |
(Extra Note - This can be condensed to disableSubmit
prop as this can be easily defined on dev side when defining form inputs (not compulsory step))
Pros of this approach -
- This approach will get rid of extra listener on
FormSubmit
, which will give some performance based boost on lower end device - This will fix the bug when we use StatePicker as form input, and press enter on search text input, it will submit the form which is not ideal here. This happens due to assumption that we define TextInput inside a form as a form element only.
- This approach will be robust as custom component can use the
onSubmitEditing
prop as it will be available with all form input element. Examples are provided in [HOLD for payment 2024-03-11] [HOLD for payment 2024-02-20][$1000] Form: Inconsistent text input submitting experience between mWeb and Native #31433 (comment).
Cons -
The only con will be we have to be extra careful as this can introduced unintentional bugs. I am hopeful that no bugs/ small bugs will arise as this logic is approximately 1.5 years old, and was used during old Form
component, which are now being deprecated.
Test Branch - https://github.com/shubham1206agra/App/tree/test-form-sub-a
Option B (Relatively safe option - only using onSubmitEditing
prop on native platforms only, and not touching submit logic inside FormSubmit
)
This is relatively safe approach from option A, but will lose all the pros of option A.
Test Branch - https://github.com/shubham1206agra/App/tree/test-form-sub
Common to both
- We can define returnKeyType
to make button common to both platforms (web, and native).
What alternative solutions did you explore? (Optional)
NA
@shubham1206agra Your proposal sounds interesting, but I'm not quite sure if I understand the whole plan. Could you expand on...
...? |
See https://reactnative.dev/docs/textinput#onsubmitediting In App/src/components/Form/FormProvider.js Line 202 in 8c909d1
We can give the onSubmitEditing function definition, which submits the form if required since registerInput function returns props to the component which we desire to render there. For the custom component, we can create a custom onSubmitEditing prop, which gives us flexibility for the future. @cubuspl42 If you have any specific questions, you can ask them here. |
📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸 |
Looks like we're making our way through proposals here still 👍 |
@shubham1206agra Do you maybe have a Git branch with your proposed changes? If so, would you share a link? |
I don't have one right now, but I will make one and update you here |
@shubham1206agra Do you have an ETA on the branch with the proposed changes? Thanks! |
@shubham1206agra The solution depending on |
We're awaiting checklist and payment here |
@cubuspl42 can you please finish the checklist so we can pay and close this issue |
|
Contributor: @cubuspl42 paid $1000 via Upwork. TestRail GH Thanks! |
@mallenexpensify Is there a reason I am not being paid here? |
It must be a misunderstanding, maybe because we're both from the C+ team? @shubham1206agra was in the Contributor (PR author) role. |
@shubham1206agra can you please accept the job and reply here once you have? Apologies for the oversight. |
Done |
All paid! Sorry again for missing ya @shubham1206agra |
The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.46-2 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue: If no regressions arise, payment will be issued on 2024-03-11. 🎊 For reference, here are some details about the assignees on this issue:
|
BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:
|
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: 1.4.0-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause-Internal Team
Slack conversation: @
Action Performed:
Expected Result:
Entering status message&tapping enter must show same behaviour in mweb and android.
Actual Result:
In mweb, entering status message and tapping enter, user is navigated to previous "set your status" page but in Android, user stays in the same status page.
Entering status message&tapping enter shows different behaviour in mweb and android.
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Screenshots/Videos
Bug6278848_1700128093817.status.mp4
View all open jobs on GitHub
Upwork Automation - Do Not Edit
The text was updated successfully, but these errors were encountered: