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(Select): onChange was called twice and there was an empty option in iOS #1185

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

atabel
Copy link
Collaborator

@atabel atabel commented Jul 29, 2024

WEB-1953 WEB-1954

We want to support the case of a Select without a selected initial option. To support this we are including an additional default empty <option> in the <select>.

We style this empty option with display: none to avoid this option to appear in the select list when we open it. This works as expected in Chrome:
Screenshot_20240729_093422_Chrome
But it doesn't work as expected in Safari, and the empty option is shown when the select is open:
image

The fix:

The best fix I've found is using the select's label for that empty option:
image
And once one of the options is selected, we remove the empty one. So, if we open the select again, the empty option isn't shown anymore (like in Chrome):
image

Comment on lines -341 to -343
if (onChangeValue) {
onChangeValue(e.target.value);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link

Size stats

master this branch diff
Total JS 12 MB 12 MB +541 B
JS without icons 1.98 MB 1.98 MB +541 B
Lib overhead 61.3 kB 61.3 kB 0 B
Lib overhead (gzip) 16.4 kB 16.4 kB 0 B

Copy link

Accessibility report
✔️ No issues found

ℹ️ You can run this locally by executing yarn audit-accessibility.

Copy link

Deploy preview for mistica-web ready!

✅ Preview
https://mistica-ifbfarkml-flows-projects-65bb050e.vercel.app

Built with commit 474a009.
This pull request is being automatically deployed with vercel-action

// Chrome doesn't show this option when the select menu is open (because of display: none),
// but Safari does. So we use the select's label for this option, otherwise it would be shown
// as an empty option, which is weirder.
<option value="" style={{display: 'none'}} aria-label="">
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the empty aria-label is needed to avoid screen reader to read the select label twice

Copy link
Collaborator

@marcoskolodny marcoskolodny Jul 30, 2024

Choose a reason for hiding this comment

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

Should we add screenshot tests to cover the new behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that's not possible, the new behavior only happens in iOS/Safari

@atabel atabel added this pull request to the merge queue Aug 1, 2024
Merged via the queue into master with commit c44b25b Aug 1, 2024
11 checks passed
@atabel atabel deleted the atoledano-select-fixes branch August 1, 2024 09:57
tuentisre pushed a commit that referenced this pull request Aug 1, 2024
# [15.17.0](v15.16.4...v15.17.0) (2024-08-01)

### Bug Fixes

* **Chip:** missing data-component-name when closable  ([#1191](#1191)) ([e4e284f](e4e284f))
* **Dialogs:** avoid double execution of native dialogs ([#1183](#1183)) ([68c8db7](68c8db7))
* **Select:** onChange was called twice and there was an empty option in iOS ([#1185](#1185)) ([c44b25b](c44b25b))

### Features

* **icons:** New box, High-priority and MMS icons ([#1188](#1188)) ([edff352](edff352))
* **Rows:** a11y update ([#1180](#1180)) ([5f995ad](5f995ad))
* **ThemeContextProvider:** expose TextPreset size/lineHeight tokens as css vars ([#1178](#1178)) ([921eacf](921eacf))
@tuentisre
Copy link
Collaborator

🎉 This PR is included in version 15.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

5 participants