Skip to content
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

InputNumber: On mobile, the focus on input makes using increment / decrement buttons difficult #2843

Closed
sleepybjr opened this issue May 5, 2022 · 13 comments · Fixed by #2846
Assignees
Labels
Device: Mobile Issue or pull request is *only* related to Mobile device Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@sleepybjr
Copy link

sleepybjr commented May 5, 2022

Describe the bug

  1. Open InputNumber on mobile.
    https://www.primefaces.org/primereact/inputnumber/

  2. Click on the increment / decrement buttons.

Button press causes the input box to focus causing the mobile keyboard to be shown and hidden repeatedly on multiple clicks. Also, mobile will zoom in and make using the button difficult.

Also, buttons don’t use the spinner on mobile.

Reproducer

https://www.primefaces.org/primereact/inputnumber/

PrimeReact version

8.0.1

React version

18.x

Language

ES6

Build / Runtime

Next.js

Browser(s)

iOS 15.4

Steps to reproduce the behavior

  1. Open InputNumber on mobile.
    https://www.primefaces.org/primereact/inputnumber/

  2. Click on the increment / decrement buttons.

Expected behavior

Using buttons on mobile shouldn't make the keyboard appear but should change the value.

@sleepybjr sleepybjr added the Type: Bug Issue contains a defect related to a specific component. label May 5, 2022
melloware added a commit to melloware/primereact that referenced this issue May 5, 2022
@melloware melloware self-assigned this May 5, 2022
@melloware melloware added this to the 8.1.0 milestone May 5, 2022
@melloware
Copy link
Member

melloware commented May 5, 2022

I submitted a PR that turns this off by default and if someone wants the behavior they can use the autoFocus property to enable it.

For example:

<InputNumber inputId="minmax-buttons" 
value={value20} 
onValueChange={(e) => setValue20(e.value)} 
showButtons min={0} max={100} 
autoFocus />

@sleepybjr
Copy link
Author

The current fix only seems to change desktop browser. I did some digging and it seems setSelectionRange causes the input box to focus on iOS, thus bringing up the keyboard.

Also, the click and hold spin doesn't seem to work on iOS. I tried adding similar functions as onMouseDown and onMouseUp to onTouchStart and onTouchEnd but it causes a double-click issue with onMouseDown / onTouchStart. Not sure if you would like another ticket created for that one.

I can also look into it later.

Thanks for the quick response!

@melloware
Copy link
Member

Yeah let me know what you find out setSelectionRange looks like its used everywhere in this component.

@melloware
Copy link
Member

And yes the click and hold should be a separate issue I think from this focus issue?

@sleepybjr
Copy link
Author

Awesome, sounds good.

In addition to your current changes, adding the if statement to this line to wrap updateInput seems to fix the issue for me:

updateInput(newValue, null, 'spin');

if (props.autoFocus) { updateInput(newValue, null, 'spin'); }

@melloware
Copy link
Member

ok let me update my PR

melloware added a commit to melloware/primereact that referenced this issue May 5, 2022
@melloware
Copy link
Member

OK PR updated!

@melloware melloware added the Device: Mobile Issue or pull request is *only* related to Mobile device label May 5, 2022
@sleepybjr
Copy link
Author

Awesome, looks good to me!

@melloware
Copy link
Member

The only thing I am not sure about is props.autoFocus && updateInput(newValue, null, 'spin');

So that won't update the input field at all while spinning right? So how does the Input field gets its new value?

melloware added a commit to melloware/primereact that referenced this issue May 6, 2022
@melloware
Copy link
Member

I changed my mind and went with this instead:

 // touch devices trigger the keyboard to display because of setSelectionRange
!DomHandler.isTouchDevice() && updateInput(newValue, null, 'spin');

@sleepybjr
Copy link
Author

Even better. From my understanding, the value is updated using handleOnChange. The updateInput function just moves the cursor selection on the input.

@silviagreen
Copy link

I tried today using primereact 10.7.0 on an Iphone 12, latest OS and the keyboard still appears everytime I click the increment/decrement button.

@melloware
Copy link
Member

@silviagreen please open a new ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Device: Mobile Issue or pull request is *only* related to Mobile device Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants