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

iOS: Show a fully functional numeric keyboard ( input[type=number] ) #16

Merged
merged 3 commits into from
Nov 17, 2021

Conversation

georgealways
Copy link
Owner

@georgealways georgealways commented Nov 17, 2021

I was hoping to avoid <input type="number"> for NumberController. We're not using any of its stepping / clamping, the alt messages it shows on invalid entries are distracting, and there's a fair bit of CSS required to get rid of the native styles.

Still, it's important that mobile users get a numeric keyboard by default when focusing a number field. Up until now I had hoped to accomplish that with <input type="text" inputmode="decimal">. That's enough on Android, but naturally iOS must be difficult.

The iOS keyboard doesn't have a negative symbol with inputmode="decimal". Strangely, it's not required. From the MDN docs on inputmode decimal:

Fractional numeric input keyboard containing the digits and decimal separator for the user's locale (typically . or ,). Devices may or may not show a minus key (-).

The only way to default to a fully functional numeric keyboard on iOS is with <input type="number">. I'm not excited about changing something foundational like this, but so far I haven't been able to distinguish between the two input types. I wish it wasn't necessary, but I think the change is justified: iPhones are popular.

@georgealways georgealways merged commit 89917f0 into dev Nov 17, 2021
@georgealways georgealways deleted the inputtypenumber branch November 17, 2021 22:02
@georgealways georgealways mentioned this pull request Nov 22, 2021
@juliangarnier
Copy link
Contributor

@georgealways One side effect of this change is that Chrome will display decimal values using comma as a separator instead of a period depending of your OS regional settings (I think ?).
In my case I'm using macos with french keyboard settings, every number inputs in chrome show 12,34 even if the actual value of the field is 12.34.
This is really annoying as it prevents me from directly copy/pasting values from the gui to my code without having to manually replace the comma with a period.

My workaround for now is to convert the inputs back to type=text by calling

  gui.controllersRecursive().forEach(controller => {
    if (controller.$input && controller.$input.type === 'number') {
      controller.$input.type = 'text'
    }
  });

everywhere I add new controllers in my code.

But every demo on the web that use lil-gui will always show me coma separated values.
This is straight from the three.js docs :
Screenshot 2022-12-10 at 14 56 12

Do you have a better solution to my workaround?
Maybe adding a flag in the constructor to use input type text instead of number would solve this ?

Let me know if you need more info or if you're interested by a PR.

Thanks

@georgealways
Copy link
Owner Author

I see... It looks like you might be able to add a lang="en" to the input[number] elements to force it to use a period for decimals. That would be ideal because it would work for everyone, please feel free to give that a shot.

@juliangarnier
Copy link
Contributor

juliangarnier commented Dec 13, 2022

Unfortunately adding lang="en" to the input doesn't seem to have any effect.
And the document was already using <html lang="en"> so I think Chrome is using the OS settings and not the document itself.
I looked at a few other gui libraries and they all use text input apparently...

@georgealways
Copy link
Owner Author

Ah, bummer—thanks for trying that out though.

So I'm not sure what to do here yet. One of the main goals for lil-gui was being easier to use on mobile than dat-gui was. Setting this back to type=text would add an extra tap to every interaction with the number input.

Hopefully the snippet above can get you by for now. Let's leave this open if others want to chime in.

@juliangarnier
Copy link
Contributor

juliangarnier commented Dec 15, 2022

So I'm not sure what to do here yet. One of the main goals for lil-gui was being easier to use on mobile than dat-gui was.

I'm using the slider most of the time to interact with numbers, especially when I'm debugging on mobile.
Not saying that I'll never type a number manually, but copying the value from the field into my code is definitely what I do most with number inputs.
And having to re-format the value in my text editor every time is really slowing down my process.

Hopefully the snippet above can get you by for now. Let's leave this open if others want to chime in.

Well it kind of works for my own projects, but more importantly, this means that everyone browsing the three.js examples (or any other demos with lil-gui) using Chrome from a country where a comma is used as decimal mark, will get badly formatted decimal values...

Unfortunately until Chrome adds a way to chose which separator to use for decimals (like Safari or Firefox), I would recommend using an input text instead as the default for displaying numerical values.

But I can think of two workarounds that might solve the issue on mobile:

Since Chrome on iOS is running Webkit it won't be an issue to set the type to number.
The only edge case I can think of is laptops with touch screens running Chrome desktop.
Otherwise these workarounds should fix the issue for the majority of the users.

Let me know what you think and if you're interested in a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants