Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions bricks/visual-builder/src/page-arch-node/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ describe("visual-builder.page-arch-node", () => {
});
expect(onLabelChange).toBeCalledTimes(0);

// Composition blocks enter behavior
act(() => {
fireEvent.compositionStart(
element.shadowRoot?.querySelector(".label-input")
);
});
act(() => {
fireEvent.keyDown(element.shadowRoot?.querySelector(".label-input"), {
key: "Enter",
});
});
expect(onLabelChange).toBeCalledTimes(0);
act(() => {
fireEvent.compositionEnd(
element.shadowRoot?.querySelector(".label-input")
);
});

act(() => {
fireEvent.keyDown(element.shadowRoot?.querySelector(".label-input"), {
key: "Enter",
Expand Down
9 changes: 8 additions & 1 deletion bricks/visual-builder/src/page-arch-node/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export function PageArchNodeComponent({
const editingLabelInitialized = useRef(false);
const [shouldEmitLabelChange, setShouldEmitLabelChange] = useState(false);
const labelInputRef = useRef<HTMLInputElement>(null);
const compositionRef = useRef(false);

useEffect(() => {
setCurrentLabel(label);
Expand Down Expand Up @@ -247,7 +248,7 @@ export function PageArchNodeComponent({
event.key ||
/* istanbul ignore next: compatibility */ event.keyCode ||
/* istanbul ignore next: compatibility */ event.which;
if (key === "Enter" || key === 13) {
if (!compositionRef.current && (key === "Enter" || key === 13)) {
labelInputRef.current?.blur();
}
}, []);
Expand Down Expand Up @@ -309,6 +310,12 @@ export function PageArchNodeComponent({
ref={labelInputRef}
onChange={handleInputChange}
onKeyDown={handleInputKeydown}
onCompositionStart={() => {
compositionRef.current = true;
}}
onCompositionEnd={() => {
compositionRef.current = false;
}}
onBlur={handleInputBlur}
onDoubleClick={stopPropagation}
onContextMenu={stopPropagation}
Expand Down