Skip to content

Conversation

@bact
Copy link
Contributor

@bact bact commented Oct 5, 2025

Chrome, Firefox, and Safari have small differences when it comes to behaviour of datalist. This PR makes the behaviour more predictable and more convenient for a user to select licenses:

  • Can click on list and immediately confirm the selection of the license (without having to hit Enter again, as it normally be on Firefox)
  • Can type license ID, in any casing, and hit Tab/Enter one time to confirm the selection of the license (on Safari the user have to hit Enter twice)
  • Duplicated license will not be added

Tested with Chrome, Firefox, and Safari.
Demo: https://bact.github.io/codemeta-generator/

Implementation

  • License field now listens to three events: input, change (existing), and keydown
    • Enter/Tab only available to check in keystroke events such as keydown
  • See code comments for implementation details

bact added 4 commits October 5, 2025 15:40
Chrome, Firefox, and Safari have small differences when it comes to behaviour of datalist. This PR makes the behaviour more predictable and more convenient for a user to select licenses:

- Can click on list and immediately confirm the selection of the license (without having to hit Enter again, as it normally be on Firefox)

- Can type license ID, in any casing, and hit Tab/Enter one time to confirm the selection of the license

Tested with Chrome, Firefox, and Safari

License field now listens to three events (Enter/Tab only available to check in keystroke events such as 'keydown').

See code comments for implementation details.

Signed-off-by: Arthit Suriyawongkul <[email protected]>
Signed-off-by: Arthit Suriyawongkul <[email protected]>
@progval
Copy link
Member

progval commented Oct 5, 2025

I don't think consistency across browsers is a goal in itself (because then the app is inconsistent with the rest of the user's browser/OS, which is what matters the most).

But this PR definitely makes the license selector more usable, so that's good.

Could you add Cypress tests?

@bact
Copy link
Contributor Author

bact commented Oct 5, 2025

Thank you, I have never used Cypress before but will try.

bact added 6 commits October 5, 2025 20:53
There's still a different behaviour of typing to be debug

Signed-off-by: Arthit Suriyawongkul <[email protected]>
Signed-off-by: Arthit Suriyawongkul <[email protected]>
@bact
Copy link
Contributor Author

bact commented Oct 6, 2025

Cypress tests added. Cover duplication test, casing test, mouse click (simulated) test, and confirmation test ("MIT-0" vs "MIT") test.

@bact bact changed the title Make license selector behaviour consistent across browsers Make license field easier to use in browsers Oct 6, 2025
Comment on lines 99 to 107
// Chrome: Detach/re-attach the datalist to hide the popup after insertion.
var ua = (navigator.userAgent || '');
var isChrome = /Chrome/.test(ua) && !/Edg|OPR|Brave|CriOS/.test(ua);
if (isChrome) {
licenseField.removeAttribute('list');
setTimeout(() => {
licenseField.setAttribute('list', 'licenses');
}, 0);
}
Copy link
Member

Choose a reason for hiding this comment

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

what happens if we do this unconditionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you explain more about it please? What condition? Around which lines of code please? Thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you mean !isChrome, non-Chrome browsers don't have this issue. The popup immediately disappear after insertion.

Copy link
Member

@progval progval Oct 6, 2025

Choose a reason for hiding this comment

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

I did mean isChrome. If we remove it, it will automatically work for all Chromium derivatives not explicitly listed here (plus WebKit browsers like Safari?), and there is no harm in removing for non-Chromium browsers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oddly, on Safari, the reattachment of the datalist will force the list to popup again :(

I will put this in the code comment.

Copy link
Member

Choose a reason for hiding this comment

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

🤦

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the code and the comment after manually tested it additionally with Chromium, Brave, and Vivaldi.

Copy link
Member

Choose a reason for hiding this comment

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

thanks!

@progval
Copy link
Member

progval commented Oct 7, 2025

Is this good to merge?

@bact
Copy link
Contributor Author

bact commented Oct 7, 2025

It's good now :)

@progval progval merged commit c5d5b80 into codemeta:master Oct 7, 2025
1 check passed
@progval
Copy link
Member

progval commented Oct 7, 2025

thanks!

@bact bact deleted the license-selector-compatibility branch October 7, 2025 09:21
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