-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add shiftKey modifier to keyboard events (#514)
* add shiftKey option to some events * add test cases * revert unrelated formatting changes * add shiftKey option for mouseUp event * one more formatting revert --------- Co-authored-by: Dmitriy <dmtr.kovalenko@outlook.com>
- Loading branch information
1 parent
f90bdb2
commit 769273d
Showing
9 changed files
with
120 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
describe("Events behavior with shiftKey modifier applied", () => { | ||
beforeEach(() => { | ||
cy.visit("./cypress/fixtures/modifiers-test.html"); | ||
}); | ||
|
||
it("detects shift key modifier on click", () => { | ||
cy.get("#action-button").realClick({ shiftKey: true }); | ||
cy.contains("Shift key was pressed"); | ||
}); | ||
|
||
it("detects shift key modifier on hover", () => { | ||
cy.get("#mouse-move-div").realHover({ shiftKey: true }); | ||
cy.contains("Shift key was pressed"); | ||
}); | ||
|
||
it("detects shift key modifier on mousedown", () => { | ||
cy.get("#mouse-down-div").realMouseDown({ shiftKey: true }); | ||
cy.contains("Shift key was pressed"); | ||
}); | ||
|
||
it("detects shift key modifier on mpuseup", () => { | ||
cy.get("#mouse-up-div").realMouseUp({ shiftKey: true }); | ||
cy.contains("Shift key was pressed"); | ||
}); | ||
|
||
it("detects shift key modifier on mousemove", () => { | ||
cy.get("#mouse-move-div").realMouseMove(100, 50, { shiftKey: true }); | ||
cy.contains("Shift key was pressed"); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<body> | ||
<button id="action-button">Click on me with shift pressed</button> | ||
<hr /> | ||
<div id="mouse-move-div">Hover/mousemove over me with shift pressed</div> | ||
<hr /> | ||
<div id="mouse-down-div">Initiate mouse down with shift pressed</div> | ||
<hr /> | ||
<div id="mouse-up-div">Initiate mouse up with shift pressed</div> | ||
<hr /> | ||
|
||
<p id="result"></p> | ||
</body> | ||
<script> | ||
const resultBox = document.getElementById("result"); | ||
|
||
function commonHandler(e) { | ||
resultBox.innerHTML = ""; | ||
if (e.shiftKey) resultBox.innerHTML = "Shift key was pressed"; | ||
} | ||
|
||
document | ||
.getElementById("action-button") | ||
.addEventListener("click", commonHandler); | ||
|
||
document | ||
.getElementById("mouse-move-div") | ||
.addEventListener("mousemove", commonHandler); | ||
|
||
document | ||
.getElementById("mouse-down-div") | ||
.addEventListener("mousedown", commonHandler); | ||
|
||
document | ||
.getElementById("mouse-up-div") | ||
.addEventListener("mouseup", commonHandler); | ||
</script> | ||
<style> | ||
div { | ||
width: 100%; | ||
height: 100px; | ||
background-color: aqua; | ||
} | ||
</style> | ||
</html> |
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
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const keyToModifierBitMap: Record<string, number> = { | ||
Alt: 1, | ||
Control: 2, | ||
Meta: 4, | ||
Shift: 8, | ||
}; |