Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Windows Tipps & SecurityGetting Repeated No Caller ID Calls? Here’s What’s Really Going On(22.09.2026 um 22:31 Uhr)
Windows Tipps & SecurityHöllenmaschine: Gaming-Peripherie für gut 1.800 Euro für die HMX 6(23.09.2026 um 10:20 Uhr)
Windows Tipps & SecurityDas nächste große Ding: KI-Agenten(23.09.2026 um 10:30 Uhr)
Sichere ProgrammierungHow AI Is Making Restaurant Menus Easier to Navigate(23.09.2026 um 10:55 Uhr)
Windows Tipps & SecurityGetting Repeated No Caller ID Calls? Here’s What’s Really Going On(22.09.2026 um 22:31 Uhr)
Windows Tipps & SecurityHöllenmaschine: Gaming-Peripherie für gut 1.800 Euro für die HMX 6(23.09.2026 um 10:20 Uhr)
Windows Tipps & SecurityDas nächste große Ding: KI-Agenten(23.09.2026 um 10:30 Uhr)
Sichere ProgrammierungHow AI Is Making Restaurant Menus Easier to Navigate(23.09.2026 um 10:55 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Opt input react component

This OTP input component is a bit different from the typical ones you see. Normally, OTP input fields consist of 6 separate input boxes for each digit, and handling each one can be a real hassle, especially when you need to manage the…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

This OTP input component is a bit different from the typical ones you see. Normally, OTP input fields consist of 6 separate input boxes for each digit, and handling each one can be a real hassle, especially when you need to manage the focus, cursor position, and backspacing between fields. But with this component, I’ve simplified it by using a single input field. This is more efficient and less cluttered, as you only need to manage one field, which reduces the complexity of the code.



Another cool feature of this component is that it automatically handles the OTP entry, and it also supports autocomplete for mobile out of the box. This means when users try to input OTP on their phone, it can automatically recognize and fill in the digits without much hassle. So no more worrying about manually typing in each digit or dealing with the inconvenience of focus shifting between inputs.



The OTP blocks themselves are visually clean with a nice blue background, and when the field is focused, it shows a ring effect, making it obvious where the user is typing. The component is fully responsive and works seamlessly across different screen sizes. It also handles keypresses like Backspace and Delete gracefully.



Tech Requirements:- React, Tailwind,Typescript




import React, { useState } from 'react';

interface OtpInputProps {
otpLength: number
onChange: Function
}

const OtpInput: React.FC<OtpInputProps> = ({ otpLength = 6, onChange }) => {
const [otp, setOtp] = useState('');
const [focused, setFocused] = useState<boolean>(false);

const handleChange = (event: any) => {
const value = event.target.value;
if (/^\d*$/.test(value) && value.length <= otpLength) {
setOtp(value);
onChange(value);
}
};

const handleKeyDown = (event: any) => {
if (event.key === 'Backspace' || event.key === 'Delete') {
event.preventDefault();
setOtp((prevOtp) => prevOtp.slice(0, -1));
}
else if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
event.preventDefault();
}
};

return (
<div className="relative flex gap-2 w-fit">
{Array.from({ length: otpLength }).map((_, index) => (
<div
key={index}
className={`w-[45px] h-[50px] bg-blue-500 rounded-md flex items-center border-2 border-white justify-center text-white text-2xl
${otp[index] ? '' : 'opacity-80'}
${otp[index] === undefined ? '' : ''}
${focused && (index === otp.length || (otpLength === otp.length && index === otpLength - 1)) ? 'ring-2 ring-primary' : 'ring-2 ring-transparent'} // Active block ring
`}
>
{otp[index] || '-'}
</div>
))}
{/* Transparent input field */}
<input
type="text"
inputMode="numeric"
maxLength={otpLength}
pattern="\d{6}"
autoComplete="one-time-code"
autoFocus={true}
className="absolute top-0 left-0 w-full h-full bg-transparent caret-transparent text-transparent focus:outline-none ltr:text-left rtl:text-right
selection:bg-transparent selection:text-transparent"
value={otp}
onChange={handleChange}
onKeyDown={handleKeyDown}
onFocus={() => setFocused(true)}
onBlur={() => setFocused(false)}
/>
</div>
);
};

export default OtpInput;



Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Opt input react component

Thematisch verwandte Begriffe: input, react, component · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-96258 | A vulnerability has been found in onSite internet GmbH Auktion NG Auktio…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick