-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(a11y): blur when tabbing out of input #1927
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -633,7 +633,7 @@ | |
test.selectize.search('hello'); | ||
}).to.not.throw(Error); | ||
}); | ||
it('should normalize a string', function () { | ||
expect('should normalize a string', function () { | ||
var test; | ||
|
||
beforeEach(function() { | ||
Comment on lines
-636
to
639
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This broke my new tests. Calling |
||
|
@@ -642,11 +642,12 @@ | |
'</select>', { normalize: true }); | ||
}); | ||
|
||
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); | ||
Comment on lines
-645
to
651
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drive-by fix to ensure the test terminates properly. |
||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
(function() { | ||
|
||
var click = function(el, cb) { | ||
syn.click(el).delay(350, cb); | ||
syn.click(el).delay(1, cb); | ||
}; | ||
|
||
var tabTo = function(elem) { | ||
// emulating keyboard tabbing using focus | ||
// TODO: it would be better to use something like puppeteer instead, then we could simulate real keyboard interactions | ||
// syn.key() is not reliable enough for tabbing | ||
elem.focus(); | ||
return new Promise((resolve) => window.setTimeout(resolve)); | ||
}; | ||
|
||
// These tests are functional simulations of | ||
|
@@ -41,7 +49,7 @@ | |
}); | ||
}); | ||
}); | ||
|
||
it('should reopen dropdown if clicked after being closed by closeAfterSelect: true', function(done) { | ||
var test = setup_test('<select multiple>' + | ||
'<option value="a">A</option>' + | ||
|
@@ -413,6 +421,103 @@ | |
}); | ||
}); | ||
|
||
describe('simulate tabbing using native focus()', function() { | ||
|
||
describe('defaults', function() { | ||
var test, input1, input2; | ||
|
||
before(function(done) { | ||
test = setup_test('<select>' + | ||
'<option value="">No selection</option>' + | ||
'<option value="a">A</option>' + | ||
'<option value="b">B</option>' + | ||
'</select>', {}); | ||
input1 = $('<input type="text" class="first">'); | ||
input2 = $('<input type="text" class="last">'); | ||
test.$select.parent().prepend(input1); | ||
test.$select.parent().append(input2); | ||
done(); | ||
}); | ||
|
||
after(function() { | ||
input1.remove(); | ||
input2.remove(); | ||
}); | ||
|
||
it('should give the control focus', async function() { | ||
await tabTo(input1[0]); | ||
expect(test.selectize.isFocused).to.be.equal(false); | ||
await tabTo(test.selectize.$control_input[0]); | ||
expect(test.selectize.isFocused).to.be.equal(true); | ||
}); | ||
|
||
it('should remove the control focus', async function() { | ||
await tabTo(test.selectize.$control_input[0]); | ||
expect(test.selectize.isFocused).to.be.equal(true); | ||
await tabTo(input2[0]); | ||
expect(test.selectize.isFocused).to.be.equal(false); | ||
}); | ||
|
||
it('should open the control', async function() { | ||
await tabTo(input1[0]); | ||
expect(test.selectize.isOpen).to.be.equal(false); | ||
await tabTo(test.selectize.$control_input[0]); | ||
expect(test.selectize.isOpen).to.be.equal(true); | ||
}); | ||
|
||
it('should close the control', async function() { | ||
await tabTo(test.selectize.$control_input[0]); | ||
expect(test.selectize.isOpen).to.be.equal(true); | ||
await tabTo(input2[0]); | ||
expect(test.selectize.isOpen).to.be.equal(false); | ||
}); | ||
|
||
// TODO: this would work if tabTo was using actual keyboard interactions, | ||
// and not just focus() | ||
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'); | ||
}); | ||
Comment on lines
+477
to
+481
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
}); | ||
|
||
describe('openOnFocus is false', function() { | ||
var test, input1, input2; | ||
|
||
before(function(done) { | ||
test = setup_test('<select>' + | ||
'<option value="">No selection</option>' + | ||
'<option value="a">A</option>' + | ||
'<option value="b">B</option>' + | ||
'</select>', { openOnFocus: false }); | ||
input1 = $('<input type="text" class="first">'); | ||
input2 = $('<input type="text" class="last">'); | ||
test.$select.parent().prepend(input1); | ||
test.$select.parent().append(input2); | ||
done(); | ||
}); | ||
|
||
after(function() { | ||
input1.remove(); | ||
input2.remove(); | ||
}); | ||
|
||
it('should give the control focus', async function() { | ||
await tabTo(input1[0]); | ||
expect(test.selectize.isFocused).to.be.equal(false); | ||
await tabTo(test.selectize.$control_input[0]); | ||
expect(test.selectize.isFocused).to.be.equal(true); | ||
}); | ||
|
||
it('should not open the control', async function() { | ||
await tabTo(input1[0]); | ||
expect(test.selectize.isOpen).to.be.equal(false); | ||
await tabTo(test.selectize.$control_input[0]); | ||
expect(test.selectize.isOpen).to.be.equal(false); | ||
}); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
})(); |
There was a problem hiding this comment.
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.