Skip to content

fix(types): Type 'enter' and 'tab' is not assignable to type 'VOnModifiers' #13337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

selicens
Copy link

@selicens selicens commented May 16, 2025

close #13336

before after
966521e38159034cb123e4a3bddc812e 3ee2dcbe02e389659e9677c65f1dc4ac

Summary by CodeRabbit

  • New Features

    • Added support for "enter" and "tab" key modifiers in event handling.
  • Tests

    • Added test cases to verify correct handling of combined "enter" and "tab" key modifiers.

Copy link

coderabbitai bot commented May 16, 2025

Walkthrough

The changes add support for the "enter" and "tab" key modifiers in the runtime-dom directive logic. The internal keyNames mapping is updated to include these keys, and a new test verifies that event handlers with these modifiers work as expected when combined.

Changes

File(s) Change Summary
packages/runtime-dom/src/directives/vOn.ts Extended the keyNames type and object to include 'enter' and 'tab' as valid key modifiers.
packages/runtime-dom/tests/directives/vOn.spec.ts Added a test to verify that handlers with 'enter' and 'tab' modifiers trigger correctly on keyup events.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite
    participant InputElement
    participant Handler

    TestSuite->>InputElement: Patch onKeyup with withModifiers(handler, ['enter', 'tab'])
    TestSuite->>InputElement: Dispatch keyup event with key='Enter'
    InputElement->>Handler: Call handler (if key is 'Enter' or 'Tab')
    TestSuite->>InputElement: Dispatch keyup event with key='Tab'
    InputElement->>Handler: Call handler (if key is 'Enter' or 'Tab')
Loading

Assessment against linked issues

Objective Addressed Explanation
Support 'enter' and 'tab' as valid values for VOnModifiers (#13336)
Ensure event handlers with 'enter' and 'tab' modifiers work correctly (#13336)

Poem

A hop and a jump, two keys join the show—
"Enter" and "Tab" now ready to go!
With modifiers strong, our tests leap ahead,
No more type errors to fill us with dread.
🐇✨
The code is complete, so let's all cheer,
For every new key, the bunny draws near!

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

Copy link

@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: 0

🧹 Nitpick comments (1)
packages/runtime-dom/__tests__/directives/vOn.spec.ts (1)

167-177: Test case properly verifies new key modifiers.

The test effectively validates that the 'enter' and 'tab' modifiers work as expected. It's a good approach to test both modifiers together, confirming they can be combined correctly in a real-world scenario.

A minor suggestion: consider adding assertions that the function is NOT called when other keys are pressed, similar to how other tests in this file verify that handlers aren't invoked with incorrect inputs.

 it('it should support "enter" and "tab" key modifiers', () => {
   const el = document.createElement('input')
   const fn = vi.fn()

   const enterHandler = withModifiers(fn, ['enter', 'tab'])
   patchEvent(el, 'onKeyup', null, enterHandler, null)
+  // Verify that other keys don't trigger the handler
+  triggerEvent(el, 'keyup', e => (e.key = 'a'))
+  expect(fn).not.toBeCalled()
   triggerEvent(el, 'keyup', e => (e.key = 'Enter'))
   expect(fn).toBeCalledTimes(1)
   triggerEvent(el, 'keyup', e => (e.key = 'Tab'))
   expect(fn).toBeCalledTimes(2)
 })
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 163b365 and 0d8b6c2.

📒 Files selected for processing (2)
  • packages/runtime-dom/__tests__/directives/vOn.spec.ts (1 hunks)
  • packages/runtime-dom/src/directives/vOn.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules
  • GitHub Check: Header rules
  • GitHub Check: Pages changed
🔇 Additional comments (2)
packages/runtime-dom/src/directives/vOn.ts (2)

74-84: Type definition correctly extended for 'enter' and 'tab' keys.

The type definition for keyNames is properly updated to include 'enter' and 'tab' keys, which addresses the issue mentioned in the PR title where these types were not assignable to VOnModifiers.


93-94: Key mappings correctly implemented for 'enter' and 'tab'.

The implementation correctly maps 'enter' and 'tab' to their respective string values. Unlike some other keys that require transformation (e.g., 'esc' → 'escape'), these keys map directly to themselves since hyphenate(event.key) will convert 'Enter' and 'Tab' to lowercase.

@edison1105
Copy link
Member

edison1105 commented May 16, 2025

I don't think #13336 should be fixed.

@selicens
Copy link
Author

我认为 #13336 不应该被修复。

In the jsx and tsx scenarios, although events can be processed on their own, as described in the documentation, it would be better if the methods could focus more on data logic rather than dealing with the details of DOM events

@selicens
Copy link
Author

https://vuejs.org/guide/extras/render-function.html#event-modifiers
The document also recommends this usage, but it doesn't seem to be an absolute private API

@edison1105
Copy link
Member

@selicens
Oh, I made a mistake.

@edison1105 edison1105 added ready to merge The PR is ready to be merged. scope: types labels May 17, 2025
Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB (+24 B) 38.3 kB (+16 B) 34.5 kB (+17 B)
vue.global.prod.js 159 kB (+24 B) 58.5 kB (+17 B) 52 kB (+37 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.6 kB 18.2 kB 16.7 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.8 kB 23 kB 20.9 kB
defineCustomElement 59.5 kB 22.8 kB 20.8 kB
overall 68.6 kB 26.4 kB 24.1 kB

Copy link

pkg-pr-new bot commented May 17, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@13337

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@13337

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@13337

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@13337

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@13337

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@13337

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@13337

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@13337

@vue/shared

npm i https://pkg.pr.new/@vue/shared@13337

vue

npm i https://pkg.pr.new/vue@13337

@vue/compat

npm i https://pkg.pr.new/@vue/compat@13337

commit: 0d8b6c2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge The PR is ready to be merged. scope: types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type '"enter"' and '"tab"' is not assignable to type 'VOnModifiers'
2 participants