Skip to content

fix: suppress semantic hint and focused state when disabled (#427)#428

Open
MohamedSamir298 wants to merge 1 commit into
adar2378:mainfrom
MohamedSamir298:fix/427-a11y-disabled-material-pin-field-semantics
Open

fix: suppress semantic hint and focused state when disabled (#427)#428
MohamedSamir298 wants to merge 1 commit into
adar2378:mainfrom
MohamedSamir298:fix/427-a11y-disabled-material-pin-field-semantics

Conversation

@MohamedSamir298
Copy link
Copy Markdown

@MohamedSamir298 MohamedSamir298 commented May 12, 2026

Problem

When PinInput (and MaterialPinField) is rendered with enabled: false, screen readers were still announcing interactive hints like "Enter 6 more digits" or "PIN complete", and the field could report itself as focused. This told visually impaired users the field was editable when it wasn't.

The expected behavior — "Text field, dimmed" announced automatically in the user's OS language — was being overridden by our explicit hint value on the Semantics node.

Root cause

In _PinInputState.build(), two properties on the Semantics widget conflicted with the enabled: false state. The hint was always computed and set, even when disabled — the string "Enter N more digits" explicitly told screen readers the field accepts input. The focused property was also set directly from
_focusNode.hasFocus without guarding against the disabled state, meaning a field could be reported as focused while disabled.

Fix

Two targeted changes in packages/pin_code_fields/lib/src/core/pin_input.dart. semanticHint is now gated behind widget.enabled and returns null when disabled, letting the platform produce its native "dimmed" suffix without contradiction. focused is changed from _focusNode.hasFocus to widget.enabled &&
_focusNode.hasFocus so a disabled field can never be semantically focused. No new public API. No behavior change when enabled: true.

Tests

Four new cases added to the Semantics group in pin_input_test.dart: an empty disabled field has no hint, the "PIN complete" hint is also suppressed when disabled, the semanticHintBuilder callback is gated behind enabled too, and the focused guard holds when the field is disabled mid-session.

Closes #427

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.

A11Y issue - Wrong semanticLabel and semanticHint for disabled MaterialPinField

1 participant