Skip to content

Fix repeatable text field focus#7499

Merged
sc0ttkclark merged 1 commit intopods-framework:release/3.3.8from
pdclark:repeatable-text-field-focus
Mar 11, 2026
Merged

Fix repeatable text field focus#7499
sc0ttkclark merged 1 commit intopods-framework:release/3.3.8from
pdclark:repeatable-text-field-focus

Conversation

@pdclark
Copy link
Collaborator

@pdclark pdclark commented Mar 2, 2026

Including value of text field in the field ID caused repeating text fields to lose focus as user typed.

Commit removes JSON.stringify( valueItem ) from input key.

Description

Typing in repeatable text fields caused field to lose focus on each keystroke.

The react component was changing input field key with value, causing the field identifier to change as user typed.

Related issue(s)

https://wordpress.org/support/topic/plain-text-repeatable-fields-lose-focus-when-typing/

Testing instructions

Create a repeating text field
Add new
Type in field
Save

Should be able to type more than one character in field and save the value.

The last working version was 3.3.4:

key={ `${ fieldConfig.name }-${ index }` }

This change brings it back to how it was in that version, but it is notable that as I switched between versions, the values displayed in the field appeared to be lost, so unknown if there's any backend change needed or reason the key was changed.

Changelog text for these changes

Fix: Repeatable text field input

PR checklist

@what-the-diff
Copy link

what-the-diff bot commented Mar 2, 2026

PR Summary

  • Updated Version Numbers
    The version numbers in two key files have been updated. This ensures our code remains compatible with the latest advancements, thereby reducing potential crashes or bugs.

  • Improved ID Tracking
    Enhancements have been made to how we track IDs during 'drag-and-drop' operations. The use of a 'stable ID' ensures the items being dragged and dropped are consistently rendered. The changes also allow us to more efficiently manage these unique IDs whenever items are added, removed, or reordered.

  • Removed Unnecessary Effects
    Redundant elements that synced local states with external value changes post 'drag-and-drop' operations have been removed. This simplifies the code whilst leaving its functionality unchanged.

  • Better Component Rendering
    The component rendering process has been improved by updating keys to use stable IDs instead of values. This optimizes the reconciliation process when using React, ensuring more efficient rendering of the visual elements in our application.

@pdclark
Copy link
Collaborator Author

pdclark commented Mar 2, 2026

The build files were included in the PR... maybe that's why build failed? The only real change was repeatable-field-list.js

@sc0ttkclark
Copy link
Member

The original fix was to resolve problems reordering items. This will take a bit more work to cover both the original fix and resolving the issue with the value focus. Probably need to figure out a better way for the keys.

@pdclark
Copy link
Collaborator Author

pdclark commented Mar 3, 2026

#7486

@pdclark pdclark force-pushed the repeatable-text-field-focus branch 2 times, most recently from 48180ac to fd75603 Compare March 3, 2026 00:48
useEffect value-sync approach in repeatable DateTime, Currency, Text, and
Number fields have been replaced with useRef.

A previous fix for drag-and-drop reorder (including value in the React key)
caused repeatable text fields to lose focus on every keystroke. Removing the
value from the key fixed focus but regressed drag-and-drop for date/currency/number
fields that maintain internal state.

This replaces both approaches with useRef for persistent field IDs which associate
with items during reorder. React tracks component instances without
remounting, so text fields keep focus and fields keep their order.
@pdclark pdclark force-pushed the repeatable-text-field-focus branch from fd75603 to 713efa7 Compare March 3, 2026 00:58
@pdclark
Copy link
Collaborator Author

pdclark commented Mar 3, 2026

Both drag & focus should be resolved now

useEffect -> useRef

Video:
https://github.com/user-attachments/assets/ca362b96-b5ca-4723-a30c-25fd9396e73f

@Koda-Pig
Copy link

Koda-Pig commented Mar 3, 2026

I'm experiencing the same issue with fields losing focus. Commenting to keep track of when this PR gets merged.

@sc0ttkclark sc0ttkclark added Status: PR > Pending Code Review PR is pending code review by core developers Status: PR > QA pending QA needs to be done Type: Bug labels Mar 8, 2026
@YippeKaye
Copy link

I am also still having the issue with fields losing focus.

@sc0ttkclark sc0ttkclark changed the base branch from main to release/3.3.8 March 11, 2026 21:58
@sc0ttkclark sc0ttkclark removed the Status: PR > QA pending QA needs to be done label Mar 11, 2026
@sc0ttkclark sc0ttkclark merged commit e8f0839 into pods-framework:release/3.3.8 Mar 11, 2026
3 of 4 checks passed
@sc0ttkclark sc0ttkclark added this to the Pods 3.3.8 milestone Mar 11, 2026
@sc0ttkclark sc0ttkclark removed the Status: PR > Pending Code Review PR is pending code review by core developers label Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants