Fix InPlaceEditor not saving when focus moves outside the editor - #2
Open
olitreadwell wants to merge 1 commit into
Open
Fix InPlaceEditor not saving when focus moves outside the editor#2olitreadwell wants to merge 1 commit into
olitreadwell wants to merge 1 commit into
Conversation
The blur handler returned for any non-null relatedTarget. Browsers set relatedTarget to the element receiving focus, so tabbing or clicking to a neighboring focusable control (button, link, input) skipped the save/cancel logic and left the editor open. Only skip save/cancel when focus stays inside the editor (for example, on the Save and Cancel buttons). When focus leaves the editor, save the value, or cancel it when cancelOnBlur is set. Closes marmelab#11303
olitreadwell
force-pushed
the
fix/inplaceeditor-blur-outside-focus
branch
from
August 12, 2026 04:19
6e24df6 to
6cca925
Compare
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
<InPlaceEditor>stays open and never saves (or cancels) when focus moves to a focusable element outside it, a neighboring button, link, or input reached by Tab or a click.The blur handler bailed out for any non-null
relatedTarget:Browsers set
relatedTargetto the element receiving focus, so normal Tab navigation and clicks on focusable controls skip the save/cancel logic.This contradicts the documented behavior: the field should save automatically when the user clicks outside it, and
cancelOnBlurshould cancel instead.Reported in marmelab#11303 (reproduced on current
master).Solution
Only skip save/cancel when focus stays inside the editor (for example, on the Save and Cancel buttons, the case the original guard was meant to protect).
When focus leaves the editor, run the normal blur logic: save the value, or cancel it when
cancelOnBluris set.event.currentTargetis the editorBoxthat owns theonBlurhandler, socontains()distinguishes focus moving within the editor from focus leaving it.Focus lost to a non-focusable target (
relatedTarget === null) still saves, as before.How To Test
Manually (Storybook story
WithSiblingControl, added here):cancelOnBlur), and the editor closes.Additional Checks
masterfor a bugfix or a documentation fix, ornextfor a featurecancelOnBlur, and stay-open when focus moves to an inner button)WithSiblingControl)Fork-staging note (not part of the change). This PR is opened against my own fork (
olitreadwell/react-admin, basemaster) as a staging copy before any upstream submission.Verified locally (MUI 5.16, the repo's dev/CI version):
InPlaceEditor.spec.tsx9/9 (was 6/6; +3). The two new save/cancel tests fail onmasterbefore the fix and pass after; verified failing-first.lerna run build --scope ra-ui-materialui --include-dependenciesexits 0, no TS errors.Diff: 3 files, +56 / -2.
One logical change; no unrelated churn (incidental build edits to
package.jsonexports were reverted).No CLA bot and no DCO sign-off requirement found in this repo.
To promote upstream (unchanged branch maps 1:1):
Confidence: HIGH.
Fixes a clear, documented behavior gap with a standard focus-containment check; existing tests unaffected.
AI assistance
Drafted with AI assistance. The change was verified before opening, and the diff was reviewed line by line.
PROMOTION NOTE (remove this section before/when opening against upstream):
Prerequisites: none outstanding (re-verify CLA/DCO/signing before promoting).