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

Set a font size of at least 16px for inputs on mobile #1816

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

robertknight
Copy link
Member

@robertknight robertknight commented Dec 3, 2024

To prevent iOS from zooming into input and textarea fields when tapped, set a font size that is the maximum of 16px and the size inherited from the parent element.

This has no effect in the pattern library website, because the inputs there already inherited a font size of 16px. It does however make a difference in other downstream UIs like new groups forms in h which use a smaller size. We may wish to change the base size for text to 16px in those UIs in future, but that is a global change which has more complexity. The change here ensures that this size threshold is always met.

To prevent iOS from zooming into `input` and `textarea` fields when tapped, set
a font size that is the maximum of 16px and the size inherited from the parent
element.
@@ -70,6 +70,13 @@ export default /** @type {Partial<import('tailwindcss').Config>} */ ({
inverted: '#f2f2f2',
},
},
fontSize: {
// Set font size to the maximum of 16px and the inherited size.
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm just spelling out here what "100%" does.

@robertknight robertknight requested a review from acelaya December 3, 2024 09:39
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (10d70bc) to head (ac181d6).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1816   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           68        68           
  Lines         1234      1234           
  Branches       468       468           
=========================================
  Hits          1234      1234           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

//
// On iOS, the input font size must be at least 16px to prevent the
// browser from zooming into it on touch.
'at-least-16px': 'max(16px, 100%)',
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we could use a name which does not include the 16px value, as that's a detail that we may want/have to change in future.

Perhaps something that makes it clear that there won't be zoom in touch devices, something in the lines of prevent-zoom, so that we can use it as touch:text-prevent-zoom.

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered something like this but at-least-16px makes it more obvious at a glance what the visual effect is. The 16px value has been shipped in WebKit for years so I think is unlikely to change. They can't make it larger without breaking a lot of sites and if they made it smaller, it would be a long time before we could make a change.

Copy link
Member Author

Choose a reason for hiding this comment

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

We do have a touch-minimum size that we use, and this is analogous, except that here we are saying "at least the minimum touch size". I suppose at-least-min-input-size would work, albeit a bit verbose.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, thanks for the clarification. I think you are right.

@acelaya
Copy link
Contributor

acelaya commented Dec 3, 2024

We may wish to change the base size for text to 16px in those UIs in future, but that is a global change which has more complexity

Agree. Specially in LMS the font size is pretty small, and it's always tricky to experiment with things here, then move them there just too find out they might be too small.

@robertknight robertknight merged commit f9dfa46 into main Dec 3, 2024
4 checks passed
@robertknight robertknight deleted the use-16px-font-for-inputs-on-mobile branch December 3, 2024 11:13
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