Skip to content

Conversation

KumJungMin
Copy link
Contributor

Defect Fixes



How To Resolve

Issue

  • Pressing the Delete key in an OTP input cell does not clear the value or move focus backwards, unlike Backspace.

Cause

  • The existing Delete‑handling logic lived in the onInput handler under the deleteContentForward branch
  • but onInput does not fire when Delete is pressed on an empty input,
  • so the deletion logic never ran for the last (or already‑empty) cell.

Solution

  • Move Delete key handling into onKeyDown (which always fires), preventing default browser behavior.
  • Reuse existing updateTokens logic to clear the current cell’s value and invoke onChange.
const onKeyDown = (event) => {
  case 'Delete': {
      event.preventDefault();
      const idx = Number(event.target.id);
      if (!Number.isNaN(idx)) {
          updateTokens({ ...event, target: { ...event.target, value: '' } }, idx);
          moveToPrevInput(event);
      }
      break;
  }
}

  • The Delete key does not fire an onInput event when deleting the last (or an already empty) cell, yet it does fire for non‑final cells—resulting in inconsistent behavior.
  • To simplify and unify the input flow, the deleteContentForward branch was removed.
const onInput = (event, index) => {
    ...
    if (event.nativeEvent.inputType === 'deleteContentBackward') {
        moveToPrevInput(event);
    } else if (event.nativeEvent.inputType === 'insertText') { // Remove: deleteContentForward condition
        moveToNextInput(event);
    }
};

Test

before: Pressing the Delete key on an OTP input field (especially the last or empty one) had no effect

2025-03-22.9.25.22.mov

after:

  • Delete key behavior

    • Non‑empty cell → clears value + moves focus to previous cell
    • Empty cell → moves focus to previous cell
    • First cell → no action
  • onChange

    • After Delete, the callback’s value should be the updated OTP string with the deleted character removed
2025-03-22.9.24.47.mov

Copy link

vercel bot commented Mar 22, 2025

Deployment failed with the following error:

Creating the Deployment Timed Out.

@melloware melloware merged commit b894b49 into primefaces:master Mar 22, 2025
2 of 3 checks passed
@KumJungMin KumJungMin deleted the fix/issue-7807 branch March 22, 2025 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

InputOtp: integerOnly option disables delete key
2 participants