Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion Scroller/EditableWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -133,7 +134,10 @@ const EditableWrapper = (props) => {
lastInputDirection: null,

// initialSelected
initialSelected: editable?.initialSelected
initialSelected: editable?.initialSelected,

// onLeaveContainer handler
handleLeaveContainer: null
});
const announceRef = useRef({});

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 (
<TouchableDiv
holdConfig={holdConfig}
Expand All @@ -808,6 +832,8 @@ const EditableWrapper = (props) => {
onMouseDown={handleMouseDown}
onMouseMove={handleMouseMove}
ref={wrapperRef}
{...spotlightContainerProps}
{...spotlightContainerAttributes}
>
{children}
<Announce key="editable-wrapper-announce" ref={announceRef} />
Expand Down