Skip to content

fix: row height / column width value not applied when pressing Enter in context menu - #765

Open
bynkook wants to merge 1 commit into
ruilisi:masterfrom
bynkook:fix/context-menu-enter-key-for-row-height-column-width
Open

fix: row height / column width value not applied when pressing Enter in context menu#765
bynkook wants to merge 1 commit into
ruilisi:masterfrom
bynkook:fix/context-menu-enter-key-for-row-height-column-width

Conversation

@bynkook

@bynkook bynkook commented Apr 15, 2026

Copy link
Copy Markdown

PR: Fix row height / column width input not applying value on Enter key

Summary

In the context menu, the "Set row height" and "Set column width" inputs stop
propagation of all keydown events. This means pressing Enter after typing
a value (or adjusting with the spinner) never triggers the parent Menu's
onClick handler, so the value is never applied.

The only way the value was ever applied was by clicking the plain-text label
next to the input (e.g. the "row", "height", "column", "width", or "px"
text nodes) — a hidden and completely unintuitive interaction that most
users will never discover.


Reproduction

  1. Select one or more rows by clicking the row header.
  2. Right-click → "Set row height" (set-row-height).
  3. Type a new value in the number input (e.g. 50) and press Enter.
  4. Expected: row height updates to 50 px.
  5. Actual: nothing happens. The value is ignored.

Same steps apply to "Set column width" (set-column-width).


Root Cause

packages/react/src/components/ContextMenu/index.tsx

<input
  onClick={(e) => e.stopPropagation()}
  onKeyDown={(e) => e.stopPropagation()}   // ← blocks ALL keydown, including Enter
  type="number"
  ...
/>

The Menu wrapper component relies on its own onClick to read the input
value and call api.setRowHeight / api.setColumnWidth:

<Menu
  onClick={(e, container) => {
    const targetRowHeight = container.querySelector("input")?.value;
    // applies value …
  }}
><input onKeyDown={(e) => e.stopPropagation()}  /></Menu>

Because stopPropagation() is called unconditionally, the Enter key never
bubbles up to trigger Menu's onClick. The input's native spinner (↑↓
buttons) also fires only on the input element, so clicking the spinner
likewise never applies the value.

The same pattern exists in insert-row and insert-column inputs.


Fix

Allow Enter in the onKeyDown handler to programmatically invoke the
parent menu item's click, which triggers the existing apply logic:

packages/react/src/components/ContextMenu/index.tsx

 // set-row-height input
-onKeyDown={(e) => e.stopPropagation()}
+onKeyDown={(e) => {
+  e.stopPropagation();
+  if (e.key === "Enter") {
+    (e.currentTarget.closest(".luckysheet-cols-menuitem") as HTMLElement)?.click();
+  }
+}}
 // set-column-width input  (identical change)
-onKeyDown={(e) => e.stopPropagation()}
+onKeyDown={(e) => {
+  e.stopPropagation();
+  if (e.key === "Enter") {
+    (e.currentTarget.closest(".luckysheet-cols-menuitem") as HTMLElement)?.click();
+  }
+}}

Note: The same fix should be considered for insert-row and
insert-column inputs, which share the same pattern.


Test Steps

  1. Select rows/columns via header click.
  2. Right-click → "Set row height" or "Set column width".
  3. Type a value and press Enter → value should be applied immediately.
  4. Use the spinner (↑↓) to change the value, then press Enter → applied.
  5. Existing behavior (clicking the text label) should still work unchanged.

Affected Files

  • packages/react/src/components/ContextMenu/index.tsx

Affected Versions

Confirmed on @fortune-sheet/react@1.0.4 (latest at time of writing).


Notes

The spinner click issue (value not applied when clicking ↑↓ without pressing
Enter) has the same root cause: the spinner fires a change event on the
input but this never reaches the Menu's onClick. A more complete fix
would add an onChange handler to the input that immediately invokes the
parent click — but that is a separate, larger change left as a follow-up.

The set-row-height and set-column-width inputs called
e.stopPropagation() unconditionally on keydown, which prevented the
Enter key from bubbling up to the parent Menu's onClick handler. As a
result, the value typed in the input was never applied unless the user
clicked one of the adjacent text labels — a completely unintuitive
interaction.

Fix: allow Enter to programmatically trigger a click on the nearest
.luckysheet-cols-menuitem element, which invokes the existing Menu
onClick logic that reads the input value and calls api.setRowHeight /
api.setColumnWidth.
bynkook added a commit to bynkook/ht_tools that referenced this pull request Apr 16, 2026
컨텍스트 메뉴의 행 높이(set-row-height) 및 열 너비(set-column-width)
입력 필드에서 onKeyDown이 e.stopPropagation()만 호출하여 Enter 키가
부모 Menu의 onClick에 도달하지 않는 버그 수정.

수정 방법: Enter 키 입력 시 가장 가까운 .luckysheet-cols-menuitem
요소를 programmatic click하여 기존 값 적용 로직이 실행되도록 처리.

- patch-package로 관리 (npm install 시 자동 적용)
- FortuneSheet 원소스에도 동일 수정으로 PR 등록 완료
  ruilisi/fortune-sheet#765

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant