Performance: Form input patterns
Form input patterns affect page interactivity and input responsiveness, impacting how quickly users can interact with forms without delays.
<input type="text" class="border p-2" oninput="debouncedValidate(event)" /> <script>const debouncedValidate = debounce((e) => { /* lightweight validation */ }, 300); function debounce(fn, delay) { let timer; return (...args) => { clearTimeout(timer); timer = setTimeout(() => fn(...args), delay); }; }</script>
<input type="text" class="border p-2" oninput="validateInput(event)" onkeyup="validateInput(event)" /> <script>function validateInput(e) { /* heavy validation logic */ }</script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy input event handlers on every keystroke | 1 per keystroke | Multiple reflows per input | High paint cost due to blocking | [X] Bad |
| Debounced input validation | 1 per debounce interval | Single reflow per validation | Low paint cost | [OK] Good |
| Fixed width input styling | 1 on resize | Reflow triggered on viewport change | Medium paint cost | [!] Bad |
| Responsive width with Tailwind classes | Minimal DOM ops | No reflows on resize | Low paint cost | [OK] Good |
| SVG icon with pointer-events and aria-hidden | Minimal DOM ops | No extra reflows | Low paint cost | [OK] Good |
border class adds a 1px solid border around an element, commonly used for inputs.bg-blue-500 changes background color, text-center centers text, and flex applies flexbox layout, none add borders.rounded-lg applies medium-large rounded corners to elements, suitable for inputs.rounded-full makes fully circular corners, rounded-none removes rounding, and rounded-0 is invalid in Tailwind.<input type="text" class="border border-gray-400 p-2 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" />
border border-gray-400 adds a gray border, p-2 adds padding inside the input, rounded-md rounds corners moderately.focus:outline-none removes default outline, focus:ring-2 focus:ring-blue-500 adds a blue ring around input on focus.<input class="border-2 rounded focus:ring-blue-400 focus:ring" />
border-2 is valid for 2px border, rounded is valid for small rounding.focus:ring requires a size like focus:ring-2 to show ring thickness; missing size means no visible ring.border border-gray-300 sets default border, focus:border-blue-600 changes border color on focus.rounded-md rounds corners, p-3 adds padding, focus:ring-2 focus:ring-blue-600 adds blue ring on focus, and focus:shadow-lg adds shadow only on focus.Pass the test and this pattern moves unknown