Skip to content

Commit

Permalink
prevent tabbing after focus leaves the container, e.g. after mouse cl…
Browse files Browse the repository at this point in the history
…ick and then tabbing back to the control should still let you easily get past the select
  • Loading branch information
hchiam committed Apr 13, 2022
1 parent 64e9776 commit bb5a4fb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CodePen.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ function createStylableSelect(simulatedSelect, optionsData = []) {
options.attr("tabindex", "0");
}
})
.on("focusout", function (e) {
const target = $(e.target);
const isOption = target.is('[role="option"]');
const isOptionsEnd = target.is(".simulated-select-options-end");
if (!isOption && !isOptionsEnd) {
options.attr("tabindex", "-1"); // disable tabbing to all options
}
})
.on("keyup", function (e) {
const target = $(e.target);
const isWrapper = target.is(".simulated-select-options-wrapper");
Expand Down

0 comments on commit bb5a4fb

Please sign in to comment.