Preserve first responder position when children are replaced#52
Open
arcticleo wants to merge 1 commit intorensbreur:mainfrom
Open
Preserve first responder position when children are replaced#52arcticleo wants to merge 1 commit intorensbreur:mainfrom
arcticleo wants to merge 1 commit intorensbreur:mainfrom
Conversation
If a Control's children need to be rebuilt (for example, during ForEach updates when the underlying data changes), the first responder would always reset to the first selectable element. This caused jarring UX in dynamic lists where the selection would jump to the top after any update. With this proposed change, Control tracks which child index contained the first responder before removal. When adding new children with firstResponder == nil, it attempts to restore the first responder at that same index. If the index is out of bounds (e.g., the list got shorter after a deletion), it decrements until finding a valid selectable element. This provides intuitive behavior for: - Lists where items are deleted (selection stays near same position) - Dynamic content that refreshes (selection doesn't jump to top) - Any view rebuild that replaces children This change should be backwards compatible because it only changes behavior in cases where firstResponder is nil, which is when the selection would have been reset anyway.
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.
If a Control's children need to be rebuilt (for example, during ForEach updates when the underlying data changes), the first responder would always reset to the first selectable element. This caused jarring UX in lists where the selection would jump to the top after any update.
With this proposed change, Control tracks which child index contained the first responder before removal. When adding new children with firstResponder == nil, it attempts to restore the first responder at that same index. If the index is out of bounds (e.g., the list got shorter after a deletion), it decrements until finding a valid selectable element.
This provides intuitive behavior for:
This change should be backwards compatible because it only changes behavior in cases where firstResponder is nil, which is when the selection would have been reset anyway.