diff --git a/Scroller/EditableWrapper.js b/Scroller/EditableWrapper.js index 43cfc66247..6c7eb1b311 100644 --- a/Scroller/EditableWrapper.js +++ b/Scroller/EditableWrapper.js @@ -6,6 +6,7 @@ import Spotlight, {getDirection} from '@enact/spotlight'; import {getContainersForNode} from '@enact/spotlight/src/container'; import {getTargetByDirectionFromElement} from '@enact/spotlight/src/target'; import Accelerator from '@enact/spotlight/Accelerator'; +import {useSpotlightContainer} from '@enact/spotlight/SpotlightContainerDecorator'; import {getLastPointerPosition, setPointerMode} from '@enact/spotlight/src/pointer'; import {Announce} from '@enact/ui/AnnounceDecorator'; import Touchable from '@enact/ui/Touchable'; @@ -133,7 +134,10 @@ const EditableWrapper = (props) => { lastInputDirection: null, // initialSelected - initialSelected: editable?.initialSelected + initialSelected: editable?.initialSelected, + + // onLeaveContainer handler + handleLeaveContainer: null }); const announceRef = useRef({}); @@ -619,6 +623,7 @@ const EditableWrapper = (props) => { // Check if focus leaves scroll container. if (nextTarget && !getContainersForNode(nextTarget).includes(mutableRef.current.spotlightId)) { + setPointerMode(false); Spotlight.move(getDirection(keyCode)); const orders = finalizeOrders(); @@ -797,6 +802,25 @@ const EditableWrapper = (props) => { }); }, []); // eslint-disable-line react-hooks/exhaustive-deps + useEffect(() => { + mutableRef.current.handleLeaveContainer = () => { + const orders = finalizeOrders(); + finalizeEditing(orders); + }; + }, [finalizeOrders, finalizeEditing]); + + const {attributes: spotlightContainerAttributes, ...spotlightContainerProps} = useSpotlightContainer({ + id: mutableRef.current.spotlightId + '_editable', + restrict: 'none', + containerConfig: { + onLeaveContainer: () => { + if (mutableRef.current.handleLeaveContainer) { + mutableRef.current.handleLeaveContainer(); + } + } + } + }); + return ( { onMouseDown={handleMouseDown} onMouseMove={handleMouseMove} ref={wrapperRef} + {...spotlightContainerProps} + {...spotlightContainerAttributes} > {children}