inputMode And enterKeyHint For Mobile Keyboards

inputMode picks the virtual keyboard layout and enterKeyHint labels the action key, taming mobile form fields without changing the input type.

TypescriptForm Validation

Code

typescriptsnippet
18 lines
const amountInput = document.querySelector('#amount') as HTMLInputElement;
const nextField = document.querySelector('#note') as HTMLInputElement;

// Numeric virtual keyboard with a decimal point, without number-input quirks.
amountInput.inputMode = 'decimal';
// Mobile keyboards label the action key "Next"; desktop browsers ignore it.
amountInput.enterKeyHint = 'next';
// Exact codes: no capitalization or correction help wanted.
amountInput.autocapitalize = 'off';
amountInput.spellcheck = false;

amountInput.addEventListener('keydown', (event) => {
  if (event.key === 'Enter') {
    event.preventDefault();
    nextField.focus();
    console.log('moved on; enterKeyHint is', amountInput.enterKeyHint);
  }
});

How the pieces connect — inputMode And enterKeyHint For Mobile Keyboards

Demo state sits in top-level bindings: amountInput, nextField.

Points of care

  • The project needs no new pieces before this file can run.
  • The snippet leans on document — browser-only surfaces a bare Node process cannot provide.

Using it

The file’s steps show up in the output as moved on; enterKeyHint is.

Key statements

amountInput.addEventListener('keydown', (event) => {
  if (event.key === 'Enter') {
    event.preventDefault();
    nextField.focus();
    console.log('moved on; enterKeyHint is', amountInput.enterKeyHint);
  }
});

Interactive Tools for This Topic

FAQ

Does inputMode And enterKeyHint For Mobile Keyboards run in plain Node.js?
No — it touches `document`, which exist only in the browser. Run it in a page (or the DevTools console) instead of a bare Node process.