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

fix(number-field): show decimal on iPad minimized keyboard #4784

Merged
merged 7 commits into from
Oct 10, 2024

Conversation

mizgaionutalexandru
Copy link
Contributor

@mizgaionutalexandru mizgaionutalexandru commented Sep 25, 2024

Description

This PR changes the inputMode of the NumberField's input to decimal on iPad so the minimized keyboard can show the decimal point.

Related issue(s)

Motivation and context

Currently an iPad user can't use the minimized keyboard to type in decimal values (i.e. 2.5).

How has this been tested?

  • Test case 1

    1. Go to the decimals numberfield storybook (here)
    2. Click on the input itself to see the iPad's keyboard
    3. Pinch the keyboard to minimize it
    4. Observe that the keyboard now shows a decimal point
  • Test case 2

    1. Go to an editable slider's storybook (here)
    2. Click on the input itself to see the iPad's keyboard
    3. Pinch the keyboard to minimize it
    4. Observe that the keyboard now shows a decimal point
  • Did it pass in Desktop?

  • Did it pass in Mobile?

  • Did it pass in iPad?

Screenshots (if appropriate)

simulator_screenshot_A78C42F2-2EBC-452B-8564-CE398B04C020

simulator_screenshot_6D7D8B36-1359-4B82-B172-619A0627EF13

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Checklist

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • If my change required a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices

Best practices

This repository uses conventional commit syntax for each commit message; note that the GitHub UI does not use this by default so be cautious when accepting suggested changes. Avoid the "Update branch" button on the pull request and opt instead for rebasing your branch against main.

Copy link

Branch preview

Visual regression test results

When a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:

Copy link

github-actions bot commented Sep 25, 2024

Lighthouse scores

Category Latest (report) Main (report) Branch (report)
Performance 0.99 0.99 0.99
Accessibility 1 1 1
Best Practices 1 1 1
SEO 1 0.92 0.92
PWA 1 1 1
What is this?

Lighthouse scores comparing the documentation site built from the PR ("Branch") to that of the production documentation site ("Latest") and the build currently on main ("Main"). Higher scores are better, but note that the SEO scores on Netlify URLs are artifically constrained to 0.92.

Transfer Size

Category Latest Main Branch
Total 229.945 kB 217.113 kB 🏆 217.258 kB
Scripts 58.986 kB 52.526 kB 🏆 52.675 kB
Stylesheet 34.765 kB 30.118 kB 30.118 kB
Document 6.236 kB 5.458 kB 🏆 5.482 kB
Font 127.007 kB 126.596 kB 🏆 126.633 kB

Request Count

Category Latest Main Branch
Total 52 52 52
Scripts 41 41 41
Stylesheet 5 5 5
Document 1 1 1
Font 2 2 2

@coveralls
Copy link
Collaborator

coveralls commented Sep 25, 2024

Pull Request Test Coverage Report for Build 11269966342

Details

  • 22 of 22 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.005%) to 98.23%

Totals Coverage Status
Change from base Build 11269962048: -0.005%
Covered Lines: 32942
Relevant Lines: 33354

💛 - Coveralls

Copy link

github-actions bot commented Sep 25, 2024

Tachometer results

Chrome

number-field permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 538 kB 69.92ms - 71.61ms - faster ✔
13% - 16%
10.18ms - 13.45ms
branch 516 kB 81.18ms - 83.98ms slower ❌
14% - 19%
10.18ms - 13.45ms
-

slider permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 494 kB 78.62ms - 80.91ms - faster ✔
2% - 6%
1.74ms - 4.59ms
branch 472 kB 82.07ms - 83.78ms slower ❌
2% - 6%
1.74ms - 4.59ms
-
Firefox

number-field permalink

basic-test

Version Bytes Avg Time vs remote vs branch
npm latest 538 kB 145.37ms - 151.67ms - faster ✔
11% - 15%
18.36ms - 26.32ms
branch 516 kB 168.43ms - 173.29ms slower ❌
12% - 18%
18.36ms - 26.32ms
-

slider permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 494 kB 160.15ms - 167.89ms - unsure 🔍
-6% - +0%
-9.66ms - +0.90ms
branch 472 kB 164.82ms - 171.98ms unsure 🔍
-1% - +6%
-0.90ms - +9.66ms
-

@mizgaionutalexandru mizgaionutalexandru force-pushed the imizga/iPadOS-decimal-missing branch from bc1fe4d to f40e01b Compare September 25, 2024 12:04
@mizgaionutalexandru mizgaionutalexandru force-pushed the imizga/iPadOS-decimal-missing branch from f40e01b to 2906995 Compare September 25, 2024 12:05
@mizgaionutalexandru mizgaionutalexandru marked this pull request as ready for review September 25, 2024 12:08
@mizgaionutalexandru mizgaionutalexandru requested a review from a team as a code owner September 25, 2024 12:08
Copy link
Contributor

@TarunAdobe TarunAdobe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible for us to add a test for this fix so that we don't mess it up in the future?

@mizgaionutalexandru
Copy link
Contributor Author

is it possible for us to add a test for this fix so that we don't mess it up in the future?

Currently all the tests I know in SWC that are device specific (for example this iPhone decimals on number-field) are skipped, so it wouldn't catch the issue if it comes up again. I don't yet see a reason to create these tests just for the sake of it.
If it is required and you see the value in it, I can add some tests similar to the mentioned one, to check the component's inputMode. How do you feel about this @TarunAdobe, am I missing something?

@@ -802,30 +803,21 @@ export class NumberField extends TextfieldBase {
}

if (changes.has('min') || changes.has('formatOptions')) {
let inputMode = 'numeric';
const hasNegative = typeof this.min !== 'undefined' && this.min < 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if min is not defined but the current value is negative?, would it make sense to add this to the condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently that's not taken into account but I see some value in it. I also see some concerns after a minimal PoC - if we do this at (every) value update it might confuse users to show different keyboards based on the component's value. Therefore I really am not sure if we want something like this.

Do you want to further investigate/ talk more about this in a new issue?
I also opened a new one for a visual bug I found during this investigation.

Copy link
Collaborator

@rubencarvalho rubencarvalho Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also see some concerns after a minimal PoC - if we do this at (every) value update it might confuse users to show different keyboards based on the component's value

Right, one approach could be to implement this as a flag at the component level, which remains fixed once toggled. I don’t have a strong preference here, but it might be helpful to emphasize in our documentation the importance of setting the minimum value explicitly. Currently, if negative numbers are allowed but no minimum value is set, users on iOS won’t see the minus key on the keyboard.

Do you want to further investigate/ talk more about this in a new issue?

Not sure, maybe we can find a compromise with either one (or both?) of the approaches above.

I also opened a #4788 for a visual bug I found during this investigation.

Oof! Thanks for finding and reporting it!

Copy link
Contributor Author

@mizgaionutalexandru mizgaionutalexandru Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, maybe we can find a compromise with either one (or both?) of the approaches above.

What if we use something like this instead:

Suggested change
const hasNegative = typeof this.min !== 'undefined' && this.min < 0;
const hasNegative = typeof this.min === 'undefined' || this.min < 0;

This way I think it aligns more with the current documentation saying:

If a valid range is known ahead of time, it is a good idea to provide it to <sp-number-field> so it can optimize the experience. For example, when the minimum value is greater than or equal to zero, it is possible to use a numeric keyboard on iOS rather than a full text keyboard (necessary to enter a minus sign).

Now we always assume that the user can type in negative values (which he would've gotten to using the decrement button multiple times), easing the experience and opening the keyboard that allows the most flexibility.
This way we also don't need "hack-ish" flags or workarounds. If a consumer knows that he wants only positive values, he can simply set the min to zero and the keyboard will adapt and not try to force-show a minus sign, but will show the minus sign when no min is provided.

Does this make sense for you, @rubencarvalho ?

Copy link
Collaborator

@rubencarvalho rubencarvalho Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your approach, and it does align better with the documentation!
But since we are assuming the number field can have negative numbers by default unless the min is greater than 0, what do you think about re-writing the condition to be more explicit:

const hasOnlyPositive = typeof this.min !== 'undefined' && this.min >= 0;

(and refactoring the rest of the method accordingly)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I think going for default false values is better for boolean variables and using hasOnlyPositives it would be false by default (with no properties provided by the consumer).
I updated the logic. Thank you for pointing this out! 🙏🏻

@rubencarvalho
Copy link
Collaborator

is it possible for us to add a test for this fix so that we don't mess it up in the future?

Currently all the tests I know in SWC that are device specific (for example this iPhone decimals on number-field) are skipped, so it wouldn't catch the issue if it comes up again. I don't yet see a reason to create these tests just for the sake of it. If it is required and you see the value in it, I can add some tests similar to the mentioned one, to check the component's inputMode. How do you feel about this @TarunAdobe, am I missing something?

Maybe this is outside the scope of this PR, but I'm curious—why are these tests being skipped? Is there something specific preventing us from unskipping them?

@mizgaionutalexandru
Copy link
Contributor Author

mizgaionutalexandru commented Sep 30, 2024

Maybe this is outside the scope of this PR, but I'm curious—why are these tests being skipped? Is there something specific preventing us from unskipping them?

AFAIK so far there were very few cases where setting the user agent was neccessary (but playwright doesn't seem to support it). As I see from the @web/test-runner-playwright docs we can create different contexts, for an Iphone for example, as per these contexts created in SWC, but I haven't yet found a way to use specific contexts for only a subset of tests. Is there any chance you can help me with this? there are a lot of unknowns for me here.

I've encountered this issue in this PR as well.

Nevertheless I will create an iPad test similar to these, maybe we will enable iPhone/iPad/Android contexts or something similar in the future.

@rubencarvalho
Copy link
Collaborator

Maybe this is outside the scope of this PR, but I'm curious—why are these tests being skipped? Is there something specific preventing us from unskipping them?

AFAIK so far there were very few cases where setting the user agent was neccessary (but playwright doesn't seem to support it). As I see from the @web/test-runner-playwright docs we can create different contexts, for an Iphone for example, as per these contexts created in SWC, but I haven't yet found a way to use specific contexts for only a subset of tests. Is there any chance you can help me with this? there are a lot of unknowns for me here.

I've encountered this issue in this PR as well.

Nevertheless I will create an iPad test similar to these, maybe we will enable iPhone/iPad/Android contexts or something similar in the future.

Thanks for the context! 👍 I am OK with keeping this outside the scope of this PR for now. I’ve noted it down, and it’s also implicitly part of our ongoing and upcoming efforts to improve mobile support in the future.

TarunAdobe
TarunAdobe previously approved these changes Oct 1, 2024
Copy link
Collaborator

@rubencarvalho rubencarvalho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the patience! :D LGTM!

@rubencarvalho rubencarvalho merged commit deb7a1c into main Oct 10, 2024
56 of 61 checks passed
@rubencarvalho rubencarvalho deleted the imizga/iPadOS-decimal-missing branch October 10, 2024 09:24
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.

[Bug]: decimal point missing on iPad soft keyboard on a number field with decimals
4 participants