Skip to content

fix(modal): input carry over with IMEs in modal forms#2709

Merged
jrgarciadev merged 3 commits into
heroui-inc:mainfrom
ryo-manba:fix/modal-input-ime
Apr 14, 2024
Merged

fix(modal): input carry over with IMEs in modal forms#2709
jrgarciadev merged 3 commits into
heroui-inc:mainfrom
ryo-manba:fix/modal-input-ime

Conversation

@ryo-manba
Copy link
Copy Markdown
Contributor

@ryo-manba ryo-manba commented Apr 14, 2024

Closes #2445

📝 Description

Fixed an issue where typing with an IME (like Korean or Japanese) and pressing tab would carry the input to the next field. This was resolved using the isComposing property.

modal-form-input-with-korean-language.mov

⛳️ Current behavior (updates)

When entering text in a modal form using Korean, pressing the tab key causes the last character to be entered into the next input field.

🚀 New behavior

Pressing the tab key after entering text in Korean no longer transfers the last character to the next input field.

💣 Is this a breaking change (Yes/No):

No.

📝 Additional Information

This bug does not occur in Storybook, so the behavior was verified using the docs.
This was tested using both Japanese and 2-set Korean IMEs on browsers including Chrome, Safari, and Firefox.

Summary by CodeRabbit

  • Bug Fixes
    • Implemented a fix in modal components to prevent carryover of IME (Input Method Editor) input when switching fields using the Tab key.
    • Enhanced accessibility by handling Tab key press event in the ModalContent component.

@ryo-manba ryo-manba requested a review from jrgarciadev as a code owner April 14, 2024 10:34
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 14, 2024

🦋 Changeset detected

Latest commit: fd30f0b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@nextui-org/modal Patch
@nextui-org/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 14, 2024 11:02am

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2024

@ryo-manba is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 14, 2024

Walkthrough

The update introduces a patch for the @nextui-org/modal package to handle the Tab key press event in the ModalContent component. This prevents the carryover of IME input in form fields and addresses issues related to tab navigation within modals.

Changes

File Path Change Summary
.changeset/old-cameras-sip.md Introduced a patch to handle IME input carryover using Tab in @nextui-org/modal.
packages/components/modal/src/modal-content.tsx Added KeyboardEvent import and onKeyDown callback to manage Tab key events and prevent defaults.

Assessment against linked issues

Objective Addressed Explanation
Bug when using Korean language in modal form (#2445) The changes address the issue by preventing IME input carryover when tabbing through form fields.
Bug Description: Tabbing through form fields in a Modal triggers data loss upon reaching the Close button (#2558) The new onKeyDown callback ensures that tabbing to the Close button does not result in data loss.

Possibly related issues

  • None

Recent Review Details

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 334c044 and fd30f0b.
Files selected for processing (2)
  • .changeset/old-cameras-sip.md (1 hunks)
  • packages/components/modal/src/modal-content.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • .changeset/old-cameras-sip.md
  • packages/components/modal/src/modal-content.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ryo-manba ryo-manba changed the title Fix/modal input ime fix(modal): input carry over with IMEs in modal forms Apr 14, 2024
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Comment thread .changeset/old-cameras-sip.md Outdated
"@nextui-org/modal": patch
---

prevent IME input carryover in form fields when tabbing
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider starting the description with an uppercase letter for proper grammar.

- prevent IME input carryover in form fields when tabbing
+ Prevent IME input carryover in form fields when tabbing

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
prevent IME input carryover in form fields when tabbing
Prevent IME input carryover in form fields when tabbing

Comment on lines +63 to +68
const onKeyDown = useCallback((e: KeyboardEvent) => {
if (e.key === "Tab" && e.nativeEvent.isComposing) {
e.stopPropagation();
e.preventDefault();
}
}, []);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The onKeyDown callback correctly handles the Tab key during IME composition to prevent unwanted character carryover. Consider adding comments to explain the logic for future maintainability.

+ // Handle Tab key during IME composition to prevent input carryover
  const onKeyDown = useCallback((e: KeyboardEvent) => {
+   // Check if the Tab key is pressed and the event is part of a composition session
    if (e.key === "Tab" && e.nativeEvent.isComposing) {
+     // Stop event propagation and prevent the default action
      e.stopPropagation();
      e.preventDefault();
    }
  }, []);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const onKeyDown = useCallback((e: KeyboardEvent) => {
if (e.key === "Tab" && e.nativeEvent.isComposing) {
e.stopPropagation();
e.preventDefault();
}
}, []);
// Handle Tab key during IME composition to prevent input carryover
const onKeyDown = useCallback((e: KeyboardEvent) => {
// Check if the Tab key is pressed and the event is part of a composition session
if (e.key === "Tab" && e.nativeEvent.isComposing) {
// Stop event propagation and prevent the default action
e.stopPropagation();
e.preventDefault();
}
}, []);

@ryo-manba ryo-manba marked this pull request as draft April 14, 2024 10:49
Copy link
Copy Markdown
Member

@jrgarciadev jrgarciadev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! @ryo-manba

@jrgarciadev jrgarciadev merged commit eb11a77 into heroui-inc:main Apr 14, 2024
@ryo-manba ryo-manba deleted the fix/modal-input-ime branch April 14, 2024 13:44
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.

[BUG] - Bug when using Korean language in modal form

2 participants