what-input is a client-side JavaScript utility designed to accurately track the user's current input method, distinguishing between mouse, keyboard, and touch interactions. It operates by listening for specific DOM events (mousedown, keydown, touchstart) and dynamically applies `data-whatinput` and `data-whatintent` attributes to the `window` object, making the current input state accessible via CSS or a simple JavaScript API. Currently at version 5.2.12, the package maintains an active release cadence, primarily focusing on bug fixes, TypeScript definition enhancements, and minor feature additions. A key feature is its default use of session storage to persist input/intent across page navigations, improving user experience by maintaining context. It also smartly manages form interactions, preserving the `data-whatintent` as `mouse` even when a user types into form fields, preventing unnecessary input state changes.
npm install what-inputVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import `what-input`, query the current input method and intent using its API, and observe how it updates data attributes on the `window` and body. It also highlights how to set up basic logging and interaction, alongside a note on persistence.
Consult the `what-input` v5 changelog and documentation. Update CSS selectors and JavaScript API calls if prior versions' behaviors or attributes were relied upon.
Always provide clear, visible `:focus` styles for keyboard users. Refer to WCAG 2.0 Guideline 2.4.7 ('Focus Visible') for best practices. Only remove default outlines if an accessible alternative is in place.To disable persistence, add the `data-whatpersist="false"` attribute to your `<html>` or `<body>` tag. Alternatively, call `whatInput.clearStorage()` programmatically when you need to reset the stored state.
Upgrade to `what-input` v5.2.12 or later to ensure that persistence logic correctly respects DOM readiness and avoids premature `sessionStorage` interactions.
Ensure `what-input` is correctly imported and that the `whatInput` default export is assigned: `import whatInput from 'what-input';`. If using a script tag, ensure it is loaded before your consuming script.
Provide alternative `:focus` styles that clearly indicate the active element for keyboard users. Refer to WCAG 2.0 2.4.7 for guidelines on visible focus. Only remove default outlines if an accessible alternative is in place.
If this persistence behavior is undesired, disable it by adding the `data-whatpersist="false"` attribute to your `<html>` or `<body>` tag. Alternatively, call `whatInput.clearStorage()` programmatically when you need to explicitly reset the stored state.
No dependency data recorded yet.