Blur Magic Code input when click outside#24012
Conversation
|
@Santhosh-Sellavel Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Workswell, so far so good. But will continue testing this further |
|
Resolve conflicts, thanks! |
|
Tests well mostly one issue I spotted here, tab/shift+tab does not focus on the next/previous code input like we have arrow navigation Screen.Recording.2023-08-08.at.12.29.58.AM.movcc: @dangrous |
|
What should we do here @dangrous? |
|
Oh hm, because it's one big input, yeah. Can we add a listener for the tab key if the focus is in the component? |
|
I tested it and it seems like it's kinda hard to change behaviour of |
Not sure about this though. What we do here, is a kind of magic trick creating impression that there a six input to get each value of the code. But behind the scenes, there is a different story right, can we call it a hack?
Yes, It should be like how it was before.
No,For each number, we have a separate field for a customer POV, so the tab/shift-tab should focus on the next/prev field, that's the basic expectation
We don't need to compare arrow/tab. Arrow is an addon to navigate through the field, the tab is an accessibility feature cc: @dangrous thoughts? |
|
Santhosh-Sellavel I see it differently. From my perspective customer is entering one value - namely magic code. Hence, navigating between characters within one field is based on arrows. Tab press in my mind switches to next input, which should logically correspond to next inputed value. Here - it should go from Magic Code to whatever is next. The way I look at it is that Magic Code Input in my mind is in fact ONE input but with styling that underlines each character separately. Even from code perspective it is actually one input, so I believe it should be treated as such. If we look at it as a reusable component, it could theoretically be used as part of some screen that contains more than one input - say for entering postal code or phone number somewhere. Wouldn't you expect then Tab to switch you to next field of form, rather than next character of input? Having said all that, I think that IDEAL solution would be to have it configurable with some prop. But given it might be hard and not really used ever, I'd stick to what we've got. |
|
Yeah that's an interesting point. Because tab is primarily used for accessibility, and from an accessibility perspective, for example a blind user would actively want it to act as one input, vs. 6. I think you've swayed me, @mczernek! I don't think we have to worry about that issue. |
Cool, then. If it haunts back us let's handle it along with accessibility milestones. As I see accessibility is not a priority ATM. |
|
That works for me! |
|
Moved here |
|
Bug: Backspace not working on mWeb Safari after unfocusing and focusing the input. Screen.Recording.2023-08-12.at.2.17.57.AM.mov |
|
bump @wojtus7 |
|
I'm afraid we can't do much about placement of the paste button without some hacky solution 😞 But I am working rn to fix keyboard behaviour and make it uniform on web and native |
|
@dangrous while trying to disable focus after error I found this code and comment: I can remove it but just want to make sure we don't regress pretty fresh fix here, and maybe we should just fix highlight of the selected input? |
|
Hey @wotjus try pulling main - I don't see that comment any more (so maybe it's okay for us to unfocus)
That's fine, that was a relatively minor issue. As long as it still pops up wherever you click (which it seems like it does), fine by me. |
|
Now with refocus logic removed, all platforms behave the same: (No keyboard, all digits red - user has to touch/click some space to edit it) Nagranie.z.ekranu.2023-09-25.o.20.25.05.mov@dangrous can you confirm this is what we wanted? |
|
Yes this is what we wanted. |
|
All good, tests well for me! |
|
Nice! Yep that's what I think expected behavior should be. Will look through this in a moment, and we can merge! |
dangrous
left a comment
There was a problem hiding this comment.
Looking great! One tiny change, then ready to merge!
Co-authored-by: Daniel Gale-Rosen <5487802+dangrous@users.noreply.github.com>
dangrous
left a comment
There was a problem hiding this comment.
Thanks for pushing this over the line!
|
Congrats, that’s your 5th PR merged! 🎉 Do you know about the ContributorPlus role? It’s an opportunity to earn more in the Expensify Open Source community. Keep up the great work - thanks! |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/dangrous in version: 1.3.75-0 🚀
|
|
🚀 Deployed to production by https://github.com/mountiny in version: 1.3.75-12 🚀
|
|
🚀 Deployed to staging by https://github.com/dangrous in version: 1.3.76-0 🚀
|
|
🚀 Deployed to production by https://github.com/mountiny in version: 1.3.76-6 🚀
|
| function MagicCodeInput(props) { | ||
| const inputRefs = useRef([]); | ||
| const [input, setInput] = useState(''); | ||
| const inputRefs = useRef(); |
There was a problem hiding this comment.
When we change from array to single inputRefs here, we forgot to update those lines as well
App/src/components/MagicCodeInput.tsx
Lines 280 to 281 in 4a3f2da
It caused a bug here #50315. More details: #50315 (comment)

Details
In order to make blur possible I needed to refactor the magic component. Instead of 6 separate text inputs there is only one wrapped inside TapGestureHandler that determine which number should be inputed. This resulted is some code that is simpler, taps are handled by gesture handler and right-click/context menu/context is handled by native text input. but at the same time created small issue that paste button shows only on the beginning of the input.
Fixed Issues
$ #18244
PROPOSAL: #18244 (comment)
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Web
bez.nazwy.mov
Mobile Web - Chrome
Screenrecorder-2023-08-01-17-22-47-275.mp4
Mobile Web - Safari
Nagranie.z.ekranu.2023-08-1.o.14.42.25.mov
Desktop
bez.nazwy.mov
iOS
Nagranie.z.ekranu.2023-08-1.o.14.44.35.mov
Android
Nagranie.z.ekranu.2023-08-1.o.14.41.23.mov