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(a11y): blur when tabbing out of input #1927

Merged
merged 1 commit into from
Dec 2, 2022

Conversation

meldafert
Copy link
Contributor

Fixes #1926.
To be accessible, it should be possible to easily navigate elements using the keyboard.
Previously, when using TAB to navigate through form elements, the input would enter its focused state when focused with TAB (and the dropdown would open when using openOnFocus).
However, when TAB is used to jump to the next focusable element, it would not lose its focused state, and the dropdown would stay open. This commit restores the behavior before #1813 and ensures that the input leaves its focused state and closes the dropdown when blurred using TAB.

@meldafert meldafert changed the title fix(a11y): blur when tabbing out of input Draft: fix(a11y): blur when tabbing out of input Dec 1, 2022
@meldafert
Copy link
Contributor Author

This breaks a test apparently. I will make sure to fix this, and to add a test case using TAB.

@meldafert meldafert force-pushed the keyboard-blur-a11y branch 2 times, most recently from 5450ca1 to ea50ace Compare December 1, 2022 19:29
@meldafert meldafert changed the title Draft: fix(a11y): blur when tabbing out of input fix(a11y): blur when tabbing out of input Dec 1, 2022
Fixes selectize#1926.
To be accessible, it should be possible to easily navigate elements
using the keyboard.
Previously, when using TAB to navigate through form elements, the
input would enter its focused state when focused with TAB (and the
dropdown would open when using `openOnFocus`).
However, when TAB is used to jump to the next focusable element, it
would not lose its focused state, and the dropdown would stay open.
This commit restores the behavior before selectize#1813 and ensures that the
input leaves its focused state and closes the dropdown when blurred
using TAB.
This commit also fixes some tests to ensure they are self-contained.
@meldafert
Copy link
Contributor Author

meldafert commented Dec 1, 2022

I have fixed the tests.
I also tried adding some tests for keyboard tabbing.
However, I was not able to get syn.key() to behave the way I want.
I emulated it using native .focus() for now, however that does not behave exactly the same way as actual keyboard tabbing, eg. for selectOnTab.
To get the best outcome, it would be necessary to use something like puppeteer - this should be fairly easy as CI already has headless chrome set up.

@@ -218,8 +218,8 @@ $.extend(Selectize.prototype, {
keypress : function() { return self.onKeyPress.apply(self, arguments); },
input : function() { return self.onInput.apply(self, arguments); },
resize : function() { self.positionDropdown.apply(self, []); },
// blur : function() { return self.onBlur.apply(self, arguments); },
focus : function() { self.ignoreBlur = false; return self.onFocus.apply(self, arguments); },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ignoreBlur was not read anywhere anymore. I removed the previous references and re-used it for detecting when an item in the dropdown was clicked, to avoid closing the dropdown in that case.

Comment on lines -636 to 639
it('should normalize a string', function () {
expect('should normalize a string', function () {
var test;

beforeEach(function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This broke my new tests. Calling beforeEach() inside of it() (instead of inside expect) apparently applies it to all subsequent tests.

Comment on lines -645 to 651
it('should return query satinized', function() {
it('should return query satinized', function(done) {
var query = test.selectize.search('héllo').query;

window.setTimeout(function () {
expect(query).to.be.equal('hello');
done();
}, 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drive-by fix to ensure the test terminates properly.

Comment on lines +477 to +481
xit('should select the first value on blur', async function() {
await tabTo(test.selectize.$control_input[0]);
await tabTo(input2[0]);
expect(test.selectize.getValue()).to.be.equal('a');
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the test that would require a better emulation/control over the headless browser (eg. puppeteer).

@risadams
Copy link
Contributor

risadams commented Dec 2, 2022

Kudos to you. this is one of the best documented pull requests I've seen in a long time :)
Thanks!

@risadams risadams merged commit bdcf08a into selectize:master Dec 2, 2022
@meldafert meldafert deleted the keyboard-blur-a11y branch January 18, 2023 18:22
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.

Selectize element isFocused is true after $control_input gets blurred
2 participants