fix: suppress semantic hint and focused state when disabled (#427)#428
Open
MohamedSamir298 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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