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 -webkit-appearance: button on file upload so text is aligned in Safari #2201

Merged
merged 2 commits into from
Apr 26, 2021

Conversation

vanitabarrett
Copy link
Contributor

@vanitabarrett vanitabarrett commented Apr 22, 2021

Fixes #2194

Screenshot 2021-04-23 at 10 36 29

What

In Safari, the text of the file upload component was mis-aligned with the upload button on desktop, due to the font-size not being properly applied to the button. Safari say:

We've had this behavior for a long time, since the native rounded button style does not support variable sizes. It works when you specify a "background-color", since that drops us out of the native appearance. A workaround, if you do not require a native appearance, would be to specify "-webkit-appearance: none".

Setting -webkit-appearance: none

Setting -webkit-appearance: none fixes the alignment issue as the font-size can now be set correctly. However, setting appearance to none suggests the element has no "special" appearance - "No special styling is applied. This is the default." (https://developer.mozilla.org/en-US/docs/Web/CSS/appearance).

Screenshot 2021-04-23 at 10 35 16

Setting -webkit-appearance: button

Setting appearance to button means that "the element is drawn like a button", which is more appropriate for our use case.

Screenshot 2021-04-23 at 10 48 23

However, the button goes grey with white text when pressed, which fails colour contrast recommendations (2.09:1 instead of 4.5:1). So we need to also set the text colour for the button.

Screenshot 2021-04-23 at 10 51 31

Cross-browser testing

Because we're nesting -webkit-appearance within a ::-webkit-file-upload-button selector, this doesn't have any effect in the majority of browsers. The only change I observed was in Safari (Mac). Full selection of screenshots here

  • IE11
  • Edge
  • Chrome
  • Firefox
  • Safari
  • Safari (iOS)
  • Chrome (iOS)
  • Chrome (Android)
  • Samsung Internet (Android)
  • Windows High Contrast Mode (Edge)

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2201 April 22, 2021 15:17 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2201 April 23, 2021 10:13 Inactive
@vanitabarrett vanitabarrett changed the title [WIP][DO NOT MERGE] File upload safari workaround Set -webkit-appearance: button on file upload so text is aligned Apr 23, 2021
@vanitabarrett vanitabarrett changed the title Set -webkit-appearance: button on file upload so text is aligned Set -webkit-appearance: button on file upload so text is aligned in Safari Apr 23, 2021
@vanitabarrett vanitabarrett marked this pull request as ready for review April 23, 2021 10:20
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2201 April 23, 2021 10:20 Inactive
Copy link
Contributor

@36degrees 36degrees left a comment

Choose a reason for hiding this comment

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

Great fix, and really thorough write up – thanks! Got a couple of suggestions, but also happy for this to merge as is.

src/govuk/components/file-upload/_index.scss Outdated Show resolved Hide resolved
src/govuk/components/file-upload/_index.scss Show resolved Hide resolved
Vanita Barrett added 2 commits April 26, 2021 10:42
The default file upload button in Safari does not support setting a custom font-size, which pushes
the text out of alignment on desktop.

Set `-webkit-appearance` to `button` to drop out of the native appearance so the
font-size is set to 19px

https://bugs.webkit.org/show_bug.cgi?id=224746
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-2201 April 26, 2021 09:42 Inactive
@vanitabarrett vanitabarrett added this to the v3.12.0 milestone Apr 26, 2021
@vanitabarrett vanitabarrett merged commit a42f4ae into master Apr 26, 2021
@vanitabarrett vanitabarrett deleted the file-upload-safari branch April 26, 2021 10:33
@vanitabarrett vanitabarrett removed this from the v3.12.0 milestone Apr 26, 2021
@36degrees 36degrees mentioned this pull request May 13, 2021
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.

Safari browser choose file text not aligned correctly when page maximised
3 participants