Skip to content

Commit f61f8f2

Browse files
authored
Merge pull request #22 from josueJURE/keyboard
Web accessibility
2 parents 3bd72d5 + 4a657ff commit f61f8f2

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

index.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ body {
3333
position: absolute;
3434
height: 530px;
3535
width: 400px;
36-
border: black 1px solid;
37-
border-radius: 15px;
36+
3837
overflow: hidden;
3938
display: grid;
4039
grid-template-columns: repeat(4, 1fr);

index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,37 @@ const clearHistoryBtn = document.querySelector(".clear-history-btn");
1010
clearHistoryBtn.addEventListener("click", () => {historyElement.innerHTML = "";
1111
});
1212

13+
document.addEventListener('keydown', handleKeyPress);
14+
15+
function handleKeyPress(event) {
16+
17+
const key = event.key;
18+
const button = document.querySelector(`[data-value="${key}"]`);
19+
20+
console.log(key)
21+
22+
23+
24+
if (button) {
25+
button.click(); // Trigger the click event for the corresponding button
26+
}
27+
28+
if (event.code === "Backspace") {
29+
let newArray = data.slice(ZERO, -1);
30+
screen.innerText = newArray.join("");
31+
data = newArray;
32+
if (screen.innerText === "") {
33+
screen.innerText = ZERO;
34+
}
35+
}
36+
37+
if(event.code === "Enter") {
38+
userClicksOnEqualButton("=");
39+
}
40+
41+
}
42+
43+
1344
const operatorRegex = /[\/*\-+]/;
1445
const ZERO = 0;
1546
const ZERO_DOT = "0.";

0 commit comments

Comments
 (0)