This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
re: #51
These behaviors (except form submission on Enter; see below) already exist in Selectr.
To enable them, you should set
config.nativeKeyboard = true
.Personally, I would be in favor of enabling them by default, which might also prevent confusion like this in the future.
Unfortunately, these changes did not simply duplicate existing behavior, but caused some problems as well:
The event listeners that were added/modified were previously only set up when the
nativeDropdown
option was enabled, but are now set up unconditionally.This causes conflicts and duplicated events when
nativeKeyboard
is enabled.Making Enter submit the form when a
<select>
element is focused is unexpected and often undesired.When a select box is focused, normal browser behavior when pressing Enter is to open the select box (or select an option if already open).
Implicit form submission should only happen when a form
<input>
is in focus.See the whatwg standard for more info: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#implicit-submission
returning focus to the select container when closing it is also (imo) unexpected, but, more importantly, cause focus to become "stuck" on the selectr in some cases.
For example, if an
onBlur
event listener callsclose()
on the select, then focus will immediately return to it, and the form (potentially, the entire page) becomes unusable.When using
nativeKeyboard
, closing the select via Enter or Escape does not cause focus to be lost.Suggestions for future changes:
If there is some standard keyboard behavior that is missing from Selectr, if should be added behind the
nativeKeyboard
config option.If there is some nonstandard keyboard behavior that is deemed desirable, it should be added behind its own config option, or, if added globally, should be disabled when the
nativeKeyboard
option is enabled.TL;DR:
Set
config.nativeKeyboard = true
instead.