FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Changed tab key press to behave the same as enter key and select the highlighted option by joepetrakovich · Pull Request #5759 · select2/select2 · GitHub

Changed tab key press to behave the same as enter key and select the highlighted option - #5759

Merged
kevin-brown merged 1 commit into
select2:developfrom
joepetrakovich:select-on-tab
Jan 22, 2021
Merged

Changed tab key press to behave the same as enter key and select the highlighted option#5759
kevin-brown merged 1 commit into
select2:developfrom
joepetrakovich:select-on-tab

Conversation

Copy link
Copy Markdown
Contributor

Changed tab key press to behave the same as enter key and select the highlighted option. This is consistent with modern browser behavior for <select> elements.

#4820

…highlighted option to be consistent with regular html selects in modern browsers.

Copy link
Copy Markdown
Contributor Author

I just realized this may be a breaking change for a lot of people. If they've gone this long using select2 with the assumption that TAB should not select, changing it may mess their surrounding navigation code up.

One scenario I found is when the user tabs to the dropdown, I have the dropdown automatically open up so they can start typing, but when you call open, the first option is already highlighted, so if you hit TAB again (with the desire to skip the field and leave it blank), you can't do it because it will now select that first highlighted option. You'd be forced to use the mouse to then clear it.

This reminds me of the other issues that mention the desire for a blank first option.

kevin-brown added this to the 4.1.0 milestone Feb 4, 2020

Copy link
Copy Markdown
Member

If they've gone this long using select2 with the assumption that TAB should not select, changing it may mess their surrounding navigation code up.

We have a minor release coming up soon which will feature some of these small-but-important somewhat-breaking changes so I'm comfortable knowing that.

I have the dropdown automatically open up so they can start typing

Custom UX behaviours aren't our concern.

You'd be forced to use the mouse to then clear it.

Good news! This is one of the places where Select2 is accessible through a keyboard.

if (evt.which == KEYS.DELETE || evt.which == KEYS.BACKSPACE) {
this._handleClear(evt);
}

you can't do it because it will now select that first highlighted option

A fun feature request which could help here is to provide the keyboard event data to the select event, so you could detect that case and prevent the selection.

stale Bot commented Apr 5, 2020

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale Bot added the status: stale label Apr 5, 2020
stale Bot closed this Apr 12, 2020

Copy link
Copy Markdown

Changed tab key press to behave the same as enter key and select the highlighted option. This is consistent with modern browser behavior for <select> elements.

#4820

@joepetrakovich thx i appreciate the PR. question: is there a way of adding the minor code changes in your PR so that it overrides the existing functionality in src/js/select2/core.js? any pointers would be much appreciated.

Copy link
Copy Markdown
Contributor Author

@BKSpurgeon if you use the non-minified version of the library you can just do a text search for some of the lines I changed (like key === KEYS.ESC) and make the same change yourself. Is that what you are asking?

Copy link
Copy Markdown

Hi @joepetrakovich appreciate the response. Was wanting to know if there was a way to quickly override the original core functionality provided by select2: (i'm getting it from a yarn / npm package so presumably that package is not minified): if that is true, then is there a way to retain the original package and specifically override those 1 or 2 lines of code?

kevin-brown reopened this Apr 25, 2020
stale Bot removed the status: stale label Apr 25, 2020

Copy link
Copy Markdown

@BKSpurgeon In the intermediate, I've been using using the events system:

mySelect2Widget.on('select2:select', function (e) {
  $(this).focus();
});

Copy link
Copy Markdown

@BKSpurgeon In the intermediate, I've been using using the events system:

mySelect2Widget.on('select2:select', function (e) {
  $(this).focus();
});

@devkinetic thx - do you have the context / larger code snippet of where to place the code? Not sure if i'm doing the right thing, but i couldn't get the above to work.

stale Bot commented Aug 15, 2020

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale Bot added the status: stale label Aug 15, 2020
stale Bot closed this Aug 22, 2020

devkinetic commented Oct 30, 2020
edited
Loading

Copy link
Copy Markdown

@BKSpurgeon Sorry, i don't check github as often as I should. To follow up from my example mySelect2Widget is selector for an element with select2() applied to it.

var mySelect2Widget  = $('.css-class-to-target');
mySelect2Widget.on('select2:select', function (e) {
        $(this).focus();
      });

Copy link
Copy Markdown
Member

Reopening this for another stale cycle before the next release. Need to double check on ARIA for this before reviewing it.

kevin-brown reopened this Jan 8, 2021
stale Bot removed the status: stale label Jan 8, 2021
kevin-brown mentioned this pull request Jan 22, 2021
2 tasks

Copy link
Copy Markdown
Member

ARIA has zero guidance on this front so I'm going to default back to selectWoo and how the browser implements it. So this PR looks good and will land for the 4.1.0 release candidate.

Copy link
Copy Markdown

I noticed that if you navigate through web form with TAB keys (ARIA behaviour) and you are landing on select2 (multiple items) you get stacked in select2. TAB doesn't allow you to get to the next form field. This shouldn't happen. I'm missing something?

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL