Skip to content

Save InPlaceEditor changes when focus moves outside#11304

Open
ClarenceChoo wants to merge 1 commit into
marmelab:masterfrom
ClarenceChoo:fix/in-place-editor-external-blur
Open

Save InPlaceEditor changes when focus moves outside#11304
ClarenceChoo wants to merge 1 commit into
marmelab:masterfrom
ClarenceChoo:fix/in-place-editor-external-blur

Conversation

@ClarenceChoo

Copy link
Copy Markdown

Problem

InPlaceEditor returned early for every blur event with a non-null relatedTarget. As a result, moving focus to another button, link, or input left the editor open and neither saved nor canceled the change.

Fixes #11303.

Solution

  • Track a pending blur when focus is moving to another element.
  • Resolve it from the destination document's bubbling focusin event, before the destination's click handler runs.
  • Cancel the pending blur when React reports focus still inside the editor's logical subtree. This includes controls rendered through a React portal, such as the documented SelectInput editor.
  • Keep the existing synchronous behavior when the blur has no relatedTarget.

Impact

Tabbing or clicking from an InPlaceEditor to an outside focusable control now saves by default, or cancels when cancelOnBlur is enabled. Focus moves to built-in action buttons and portalled editor controls continue to stay in edit mode.

Verification

  • corepack yarn test-unit --runTestsByPath packages/ra-ui-materialui/src/input/InPlaceEditor/InPlaceEditor.spec.tsx --runInBand
  • corepack yarn eslint packages/ra-ui-materialui/src/input/InPlaceEditor/InPlaceEditor.tsx packages/ra-ui-materialui/src/input/InPlaceEditor/InPlaceEditor.spec.tsx
  • corepack yarn workspace ra-core build
  • corepack yarn workspace ra-ui-materialui build

@ClarenceChoo
ClarenceChoo marked this pull request as ready for review July 20, 2026 02:20
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.

InPlaceEditor ignores blur when focus moves outside the editor

1 participant