mirror of
https://github.com/google/blockly.git
synced 2025-12-15 22:00:07 +01:00
fix: Fix bug that prevented using keyboard shortcuts when the DropDownDiv is open. (#9085)
* fix: Fix bug that prevented using keyboard shortcuts when the DropDownDiv is open. * chore: Remove obsolete comment. * Refactor: Remove unreachable null check. * chore: Add tests for handling Escape to dismiss the Widget/DropDownDivs. * chore: Satisfy the linter. * fix: Fix post-merge test failure.
This commit is contained in:
@@ -136,6 +136,39 @@ suite('DropDownDiv', function () {
|
||||
});
|
||||
});
|
||||
|
||||
suite('Keyboard Shortcuts', function () {
|
||||
setup(function () {
|
||||
this.boundsStub = sinon
|
||||
.stub(Blockly.DropDownDiv.TEST_ONLY, 'getBoundsInfo')
|
||||
.returns({
|
||||
left: 0,
|
||||
right: 100,
|
||||
top: 0,
|
||||
bottom: 100,
|
||||
width: 100,
|
||||
height: 100,
|
||||
});
|
||||
this.workspace = Blockly.inject('blocklyDiv', {});
|
||||
});
|
||||
teardown(function () {
|
||||
this.boundsStub.restore();
|
||||
});
|
||||
test('Escape dismisses DropDownDiv', function () {
|
||||
let hidden = false;
|
||||
Blockly.DropDownDiv.show(this, false, 0, 0, 0, 0, false, () => {
|
||||
hidden = true;
|
||||
});
|
||||
assert.isFalse(hidden);
|
||||
Blockly.DropDownDiv.getContentDiv().dispatchEvent(
|
||||
new KeyboardEvent('keydown', {
|
||||
key: 'Escape',
|
||||
keyCode: 27, // example values.
|
||||
}),
|
||||
);
|
||||
assert.isTrue(hidden);
|
||||
});
|
||||
});
|
||||
|
||||
suite('show()', function () {
|
||||
test('without bounds set throws error', function () {
|
||||
const block = this.setUpBlockWithField();
|
||||
|
||||
@@ -287,6 +287,29 @@ suite('WidgetDiv', function () {
|
||||
});
|
||||
});
|
||||
|
||||
suite('Keyboard Shortcuts', function () {
|
||||
test('Escape dismisses WidgetDiv', function () {
|
||||
let hidden = false;
|
||||
Blockly.WidgetDiv.show(
|
||||
this,
|
||||
false,
|
||||
() => {
|
||||
hidden = true;
|
||||
},
|
||||
this.workspace,
|
||||
false,
|
||||
);
|
||||
assert.isFalse(hidden);
|
||||
Blockly.WidgetDiv.getDiv().dispatchEvent(
|
||||
new KeyboardEvent('keydown', {
|
||||
key: 'Escape',
|
||||
keyCode: 27, // example values.
|
||||
}),
|
||||
);
|
||||
assert.isTrue(hidden);
|
||||
});
|
||||
});
|
||||
|
||||
suite('show()', function () {
|
||||
test('shows nowhere', function () {
|
||||
const block = this.setUpBlockWithField();
|
||||
|
||||
Reference in New Issue
Block a user