primereact icon indicating copy to clipboard operation
primereact copied to clipboard

Dropdown: filter IME Enter bug

Open CRC32EX opened this issue 10 months ago • 9 comments

Describe the bug

Pressing the Enter key to confirm a converted word in the Japanese IME causes the filter dialog to close unexpectedly.

This problem happen on Remix. Vite is no problem.

Reproducer

https://stackblitz.com/edit/remix-run-remix-9ccvms25

System Information

System:
  OS: Windows 11 10.0.22621
  CPU: (16) x64 AMD Ryzen 7 9800X3D 8-Core Processor
  Memory: 44.36 GB / 61.59 GB
Binaries:
  Node: 20.15.0 - C:\Program Files\nodejs\node.EXE
  npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD
  pnpm: 9.14.2 - C:\Program Files\nodejs\pnpm.CMD
Browsers:
  Edge: Chromium (131.0.2903.51)
  Internet Explorer: 11.0.22621.3527

Steps to reproduce the behavior

  1. Click Dropdown
  2. type おんせん
  3. press space key (convert word)
  4. press enter key (confirm convert word)
  5. Dropdown closed unexpectedly.

Image

Expected behavior

  • Do not close Dropdown

Image

Possible solution

https://gist.github.com/CRC32EX/b05988bb96bf7910a25cad74f5a9c589/revisions

primereact/components/lib/dropdown/Dropdown.js

+ if (event.is_composing === false) {
+  onEnterKey(event);
+ }

Reference

  • https://webfrontend.ninja/js-input-ime-enter/

CRC32EX avatar Jan 18 '25 16:01 CRC32EX

We are facing the same bug. Does anyone have a good workaround?

bizwms avatar Feb 05 '25 06:02 bizwms

@bizwms

It's my workaround. It's working successfully for me.

But we need root solution.

Step to workaround

  1. open dropdown.js
(project_root_directory)/node_modules/primereact/dropdown/dropdown.esm.js
  1. edit
  case 'Enter':
  case 'NumpadEnter':
+  if (event.is_composing === false) {
+    onEnterKey(event);
+  }
    event.preventDefault();
    break;

3.(optional) delete .vite directory for clear cache I'm using Vite. so i have to delete .vite directory.

(project_root_directory)/node_modules/.vite
  1. run or build
npm run dev
npm run build

CRC32EX avatar Feb 05 '25 06:02 CRC32EX

@CRC32EX Thank you for sharing your workaround. I tried implementing it, but I'm still facing the issue where the search textbox disappears when I press Enter. Additionally, as this is for a production environment, modifying the node_modules directly isn't feasible. Do you have any other suggestions or workarounds that might help resolve this issue without altering the node_modules?

Image

bizwms avatar Feb 05 '25 09:02 bizwms

@bizwms

Do you have any other suggestions or workarounds that might help resolve this issue without altering the node_modules?

No. It's Impossible.

But, i have an idea. Try, function hooking. (not React hooks. try JavaScript function hooking)

Notice. I don't know it's possible or not. Just want share ideas.

CRC32EX avatar Feb 05 '25 10:02 CRC32EX

@CRC32EX

Thank you for your reply. The previous version (“primereact”:“^9.6.3”) was fine. I hope the PrimeReact team can fix it.

bizwms avatar Feb 05 '25 10:02 bizwms

primereact“:”^9.6.3” code in the corresponding section.

    var onFilterInputKeyDown = function onFilterInputKeyDown(event) {
      switch (event.which) {
        //down
        case 40:
          onDownKey(event);
          break;

        //up
        case 38:
          onUpKey(event);
          break;

        //enter and escape
        case 13:
        case 27:
          hide();
          event.preventDefault();
          break;
      }
    };

bizwms avatar Feb 05 '25 10:02 bizwms

I found an event that is not listed on the PrimeReact site, and I believe it can resolve the composition issue.

Here’s my implementation:

onKeyDownCapture={(e: React.KeyboardEvent) => {
    if (e.nativeEvent.isComposing && (e.key === 'Enter' || e.key === 'NumpadEnter')) {
        e.preventDefault();
        e.stopPropagation();
    }
}}

ryrocks avatar Feb 05 '25 10:02 ryrocks

@ryrocks can you submit a PR?

melloware avatar Feb 05 '25 13:02 melloware

@CRC32EX @ryrocks

The KeyboardEvent for the Japanese IME when pressing Enter to confirm a converted word is “Proccess”, but Chrome and Safari on the Mac do not seem to support this specification.

                    onKeyDownCapture={(e: React.KeyboardEvent) => {
                        if (
                            e.nativeEvent.isComposing &&
                            (e.key === 'Enter' || e.key === 'NumpadEnter' || e.key === 'Process')
                        ) {
                            e.preventDefault();
                            e.stopPropagation();
                        }
                    }}

Reference https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values#ime_and_composition_keys https://qiita.com/alt_yamamoto/items/8663d047a3794dd5605e

Image

bizwms avatar Feb 06 '25 09:02 bizwms