-
Notifications
You must be signed in to change notification settings - Fork 28
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
Inverts arrow key focus movement when in an RTL context. #41
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f72ff76
Check for RTL when changing selection on directional key press.
bicknellr 7dccc86
Use `getComputedStyle` to determine direction.
bicknellr 8fb7c1a
Test directional key behavior in RTL.
bicknellr befda3c
Bump Polymer dep to ^1.2.4 for activeElement use in tests; test that …
bicknellr f67e49d
Remove `setTimeout` calls from synchronous tests.
bicknellr 525d515
Remove call to `done` now that the tests are sync.
bicknellr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
|
||
<script src="../../webcomponentsjs/webcomponents-lite.js"></script> | ||
<script src="../../web-component-tester/browser.js"></script> | ||
<script src="../../iron-test-helpers/mock-interactions.js"></script> | ||
<link rel="import" href="../../iron-test-helpers/iron-test-helpers.html"> | ||
<link rel="import" href="test-menubar.html"> | ||
|
||
</head> | ||
|
@@ -45,6 +45,18 @@ | |
</template> | ||
</test-fixture> | ||
|
||
<test-fixture id="rtl"> | ||
<template> | ||
<div dir="rtl"> | ||
<test-menubar> | ||
<div>item 1</div> | ||
<div>item 2</div> | ||
<div>item 3</div> | ||
</test-menubar> | ||
</div> | ||
</template> | ||
</test-fixture> | ||
|
||
<script> | ||
|
||
suite('menubar a11y tests', function() { | ||
|
@@ -58,7 +70,7 @@ | |
var menubar = fixture('basic'); | ||
MockInteractions.focus(menubar); | ||
setTimeout(function() { | ||
assert.equal(document.activeElement, menubar.firstElementChild, 'document.activeElement is first item') | ||
assert.equal(Polymer.dom(document).activeElement, menubar.firstElementChild, 'document.activeElement is first item') | ||
done(); | ||
// wait for async in _onFocus | ||
}, 200); | ||
|
@@ -69,7 +81,7 @@ | |
menubar.selected = 1; | ||
MockInteractions.focus(menubar); | ||
setTimeout(function() { | ||
assert.equal(document.activeElement, menubar.selectedItem, 'document.activeElement is selected item'); | ||
assert.equal(Polymer.dom(document).activeElement, menubar.selectedItem, 'document.activeElement is selected item'); | ||
done(); | ||
// wait for async in _onFocus | ||
}, 200); | ||
|
@@ -80,7 +92,7 @@ | |
menubar.selected = 0; | ||
menubar.items[1].click(); | ||
setTimeout(function() { | ||
assert.equal(document.activeElement, menubar.items[1], 'document.activeElement is last activated item'); | ||
assert.equal(Polymer.dom(document).activeElement, menubar.items[1], 'document.activeElement is last activated item'); | ||
done(); | ||
// wait for async in _onFocus | ||
}, 200); | ||
|
@@ -91,12 +103,55 @@ | |
menubar.selected = 0; | ||
menubar.items[0].click(); | ||
setTimeout(function() { | ||
assert.equal(document.activeElement, menubar.items[0], 'document.activeElement is last activated item'); | ||
assert.equal(Polymer.dom(document).activeElement, menubar.items[0], 'document.activeElement is last activated item'); | ||
done(); | ||
// wait for async in _onFocus | ||
}, 200); | ||
}); | ||
|
||
suite('left / right keys are reversed when the menubar has RTL directionality', function() { | ||
var LEFT = 37; | ||
var RIGHT = 39; | ||
|
||
test('left key moves to the next item', function(done) { | ||
var rtlContainer = fixture('rtl'); | ||
var menubar = rtlContainer.querySelector('test-menubar'); | ||
menubar.selected = 0; | ||
menubar.items[1].click(); | ||
setTimeout(function() { | ||
MockInteractions.pressAndReleaseKeyOn(menubar, LEFT); | ||
setTimeout(function() { | ||
assert.equal(Polymer.dom(document).activeElement, menubar.items[2], | ||
'`document.activeElement` should be the next item.'); | ||
assert.equal(menubar.selected, 1, | ||
'`menubar.selected` should not change.'); | ||
done(); | ||
// wait for async in _onFocus | ||
}, 200); | ||
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 comment is still applicable.) |
||
// wait for async in _onFocus | ||
}, 200); | ||
}); | ||
|
||
test('right key moves to the previous item', function(done) { | ||
var rtlContainer = fixture('rtl'); | ||
var menubar = rtlContainer.querySelector('test-menubar'); | ||
menubar.selected = 0; | ||
menubar.items[1].click(); | ||
setTimeout(function() { | ||
MockInteractions.pressAndReleaseKeyOn(menubar, RIGHT); | ||
setTimeout(function() { | ||
assert.equal(Polymer.dom(document).activeElement, menubar.items[0], | ||
'`document.activeElement` should be the previous item'); | ||
assert.equal(menubar.selected, 1, | ||
'`menubar.selected` should not change.'); | ||
done(); | ||
// wait for async in _onFocus | ||
}, 200); | ||
// wait for async in _onFocus | ||
}, 200); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
</script> | ||
|
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.
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.
why 200 and not 100, or 1? it is waiting for an animation to finish, or just a microtask?
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.
I think I copied this from the other examples with the assumption that both actions would need to wait for the same thing because they both affect focus, so I wouldn't be surprised if the timing is too loose. I'll look more into this.