software-factory
MAmattpocock/skills336k近 7 天新增 4,217 个 star
Build forms, inputs, buttons, and controls that feel right — label association, 16px inputs to stop iOS zoom, focus states, validation timing, loading/disabled button states, Enter and Cmd+Enter submission, and autofocus rules. Use when building or reviewing any form, text input, textarea, search field, login/signup flow, settings page, checkout, button, checkbox, or submit handler. Triggers on: form, input, textarea, select, button, checkbox, radio, toggle, submit, onSubmit, validation, error message, placeholder, label, autofocus, autocomplete, spellcheck, iOS zoom, font-size 16px, focus ring, focus-visible, loading state, disabled, double submit, duplicate request, Enter to submit, Cmd+Enter, keyboard shortcut, destructive action, confirmation, delete, clear button, input icon, prefix, suffix, search field, login form, signup form, 1Password, password manager.
Forms are where users do real work, and they notice every rough edge: the label that doesn't focus the input, the page that zooms on iOS, the button that fires twice, the Enter key that does nothing. None of these are hard to fix — they're just easy to forget. Wire up the semantics the platform gives you (<form>, <label>, <button>), then layer on the details below. Where CSS is involved, implement it in the project's existing styling system (Tailwind, CSS Modules, styled-components — whatever is already there); the values matter, the syntax doesn't.
Clicking the label must focus the input:
<label for="email">Email</label>
<input id="email" type="email" />
<!-- Or wrap the input -->
<label>
Email
<input type="email" />
</label>
<input type="email" /> <input type="password" />
<input type="tel" /> <input type="url" />
<input type="number" /> <input type="search" />
This gets you the right mobile keyboard, browser validation, and autofill behavior for free.
Inputs smaller than 16px cause iOS Safari to zoom in on focus. Set it globally:
input, textarea, select {
font-size: 16px;
}
If the design calls for smaller text, keep the computed font-size at 16px on touch devices and scale visually some other way — never below 16px.
Every input and control needs a clear focus state. Style :focus-visible (not bare :focus) so keyboard users get a ring without mouse users seeing one on every click, and never outline: none without a replacement:
input:focus-visible { outline: 2px solid var(--focus-color); outline-offset: 2px; }
Disable spellcheck and autocomplete most of the time for cleaner UX (usernames, search fields, codes, slugs — anything that isn't a real address/identity field). Keep autocomplete ON for email, name, address, and payment fields — there it genuinely helps. Disable 1Password's overlay on fields where it doesn't belong:
<input type="text" spellcheck="false" autocomplete="off" />
<input data-lpignore="true" data-1p-ignore />
Prefix/suffix icons and labels should be absolutely positioned on top of the input (with padding making room), not rendered as sibling elements — otherwise clicking them does nothing and the "input" border lies about the hit area:
.input-wrapper {
position: relative;
}
.input-icon {
position: absolute;
left: 12px;
top: 50%;
transform: translateY(-50%);
pointer-events: none;
}
.input-field { padding-left: 40px; }
Clickable decorations (like a clear button) should refocus the input:
<button
className="input-icon-button"
onClick={() => inputRef.current?.focus()}
>
<SearchIcon />
</button>
Autofocus the first input when a modal opens (if the modal contains one). Do NOT autofocus on touch devices — it pops the keyboard open unexpectedly:
const isTouchDevice = 'ontouchstart' in window;
<input autoFocus={!isTouchDevice} />
<form> — Enter must submit<form onSubmit={handleSubmit}>
<input type="text" />
<button type="submit">Submit</button>
</form>
For textareas (where Enter inserts a newline), support Cmd+Enter (Mac) / Ctrl+Enter (Windows) to submit:
function handleKeyDown(e) {
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
handleSubmit();
}
}
<button> elements — with a loading stateNever put click handlers on elements that aren't buttons:
<!-- Good -->
<button onClick={handleClick}>Click me</button>
<!-- Bad -->
<div onClick={handleClick}>Click me</div>
<span onClick={handleClick}>Click me</span>
Disable the button while submitting to prevent duplicate network requests, and say what's happening:
const [isSubmitting, setIsSubmitting] = useState(false);
<button
disabled={isSubmitting}
onClick={async () => {
setIsSubmitting(true);
await submitForm();
setIsSubmitting(false);
}}
>
{isSubmitting ? 'Submitting...' : 'Submit'}
</button>
Make buttons feel pressable with a subtle scale on :active:
.button:active { transform: scale(0.97); }
If a button's action has a keyboard shortcut, surface it as a tooltip:
<Tooltip content="Save (Cmd+S)">
<button onClick={save}>Save</button>
</Tooltip>
Don't flag a field as invalid while the user is still typing their first attempt — validate on blur or on submit. Once a field HAS shown an error, switch to validating on change so the error clears the moment they fix it ("reward early, punish late").
Colocate error messages with the field that caused them — not in a summary at the top:
<div className="field">
<input type="email" aria-invalid={!!error} />
{error && <span className="error">{error}</span>}
</div>
The label, the control, AND the gap between them must all be clickable:
.checkbox-wrapper {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
/* Make the entire row clickable, not just the checkbox */
.checkbox-wrapper label { cursor: pointer; flex: 1; }
Or wrap everything in one label:
<label class="checkbox-row">
<input type="checkbox" />
<span>Remember me</span>
</label>
function handleDelete() {
if (confirm('Are you sure you want to delete this?')) deleteItem();
}
confirm() is the floor — use a proper confirmation modal for real products.
Use the logged-in user's data to prefill forms whenever possible. When linking to a form, prefill it from the request context — e.g. a "Change username" link should land on a form prefilled with: "I'd like to change my username to:"
Use Base UI for accessible component primitives. If it doesn't fit the codebase, use whatever does — but the accessibility bar (focus management, ARIA, keyboard support) is non-negotiable.
type attribute on every inputfont-size: 16px minimum on inputs, textareas, selects:focus-visible state on all controlsspellcheck="false" / autocomplete="off" where autofill is noise<form>; Enter submits; Cmd/Ctrl+Enter submits textareas<button> elements; disabled + loading text during submission:active { transform: scale(0.97) } for press feedback<form>, so Enter silently does nothing<div onClick> "buttons" invisible to keyboards and screen readersMAmattpocock/skills336k近 7 天新增 4,217 个 star
MAmattpocock/skills336k近 7 天新增 4,217 个 star
AFaffaan-m/ECC314k近 7 天新增 3,503 个 star
AFaffaan-m/ECC314k近 7 天新增 3,503 个 star
AFaffaan-m/ECC314k近 7 天新增 3,503 个 star
DIDietrichGebert/ponytail202k近 7 天新增 4,226 个 star