I am developing an React app in which i have to implement t9 typing in which we have to simulate the typing of keypad phones
(ie . say if i click the button containing 'p q r s' on: long press : shows 7 single click: shows p double click shows q triple click shows r quadruple click : should show 's' but my code shows 'rp'
What i have done i have set an onclick listener to td of html table (which i am using to render as key of key pad phone) and find no. Of times it has been clicked by event.detail . in some case i need to capture a quadruple click (eg. if i have to type 's') but when i click an element more than 3 it resets event.detail to 1 and start again.
Code of onclick listener:
<tbody>
{array.map((i) => {
return (
<tr key={i}>
{values.slice(3 * i, 3 * i + 3).map((val) => {
return (
<td
key={val.str1}
onClick={fxn}
className={val.str2}
id={val.str1}
onMouseDown={startTimer}
onMouseUp={clear}
onMouseLeave={clear}
>
<h2>{val.str1}</h2>
{val.str1 !== val.str2 && <h5>{val.str2}</h5>}
</td>
);
})}
</tr>
);
})}
</tbody>
Code of fxn:
const fxn = (event) => {
var string = event.currentTarget.className;
var s2 = event.currentTarget.id;
var times = event.detail;
if (count === display.length) {
if (s2 === string || s2 === "0") {
setDisplay(display + string);
} else {
if (times < 2) {
setDisplay(display + string[(times - 1) * 2]);
} else {
setDisplay(display.slice(0, -1) + string[(times - 1) * 2]);
}
}
}
};
Here is the full code in case you need to see:
https://codesandbox.io/s/winter-leaf-4k62s
Is there any method to capture the quadruple click?