diff --git a/src/components/Buttons.js b/src/components/Buttons.js index 6fa5db4..81f46ec 100644 --- a/src/components/Buttons.js +++ b/src/components/Buttons.js @@ -2,13 +2,14 @@ import React from "react"; import "./styles/Buttons.css"; // import CALCULATOR_BUTTONS from "./CalculatorButtons"; -const Buttons = ({ - inputHandler, - clearInput, - backspace, - changePlusMinus, - calculateAns, -}) => { +const Buttons = ({ inputHandler, clearInput, backspace, changePlusMinus, calculateAns }) => { + document.addEventListener("keydown", function (event) { + if (event.key === "Enter") { + event.preventDefault(); + document.getElementById("equalbtn").click(); + } + }); + return (
-
diff --git a/src/components/Display.js b/src/components/Display.js index f10b822..8df7acf 100644 --- a/src/components/Display.js +++ b/src/components/Display.js @@ -2,13 +2,13 @@ import React from "react"; import "./styles/Display.css"; const Display = ({ input, setInput, answer }) => { - // const onChangeTagInput = (e) => { - // // setInputVal(e.target.value.replace(/^[0-9 ()+-]+$/, "a")); - // // if(e.target.value === "1") - // setInput(e.target.value); - // // console.log(e.target.value.test(/^[0-9 ()+-]+$/)); - // // console.log(e.target.value); - // }; + const onChangeTagInput = (e) => { + const re = /^[!%(-+\x2D-9^glox\xF7\u221A]+$/; + + if (e.target.value === "" || re.test(e.target.value)) { + setInput(e.target.value); + } + }; return ( <> @@ -22,9 +22,10 @@ const Display = ({ input, setInput, answer }) => { style={{ padding: "29px" }} value={input} placeholder="0" - // onChange={onChangeTagInput} maxLength={12} - disabled + // disabled + onChange={onChangeTagInput} + autoComplete="off" /> ) : ( @@ -43,7 +44,6 @@ const Display = ({ input, setInput, answer }) => { name="value" className="input" value={answer} - // onChange={onChangeTagInput} disabled />