Skip to content
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

fix(autocomplete): [autocomplete] fix form validate error when select… #2296

Merged
merged 1 commit into from
Oct 21, 2024

Conversation

gimmyhehe
Copy link
Member

@gimmyhehe gimmyhehe commented Oct 18, 2024

… suggestion option

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

由于@blur是当鼠标点击时就触发,而选项面板中,是点击事件触发选中,点击事件是需要松开鼠标才会触发。
所以导致失焦先校验 -> 弹出校验框。 选中对应选项,弹窗消失。

修改方案:
将失焦事件触发改为click-outside,使得松开鼠标后才触发校验事件。

@gimmyhehe gimmyhehe added the bug Something isn't working label Oct 18, 2024
Copy link

coderabbitai bot commented Oct 18, 2024

Walkthrough

This pull request includes updates to multiple package files, primarily focusing on version increments and enhancements to the autocomplete component's functionality. The version of @opentiny/vue-renderless was updated from 3.18.4 to 3.18.5, while @opentiny/vue-autocomplete was updated from 3.18.0 to 3.18.1. Significant modifications were made to the autocomplete component's methods, including changes to parameters and event handling mechanisms.

Changes

File Change Summary
packages/renderless/package.json Version updated from 3.18.4 to 3.18.5.
packages/renderless/src/autocomplete/index.ts - Removed event parameter from handleBlur.
- Added dispatch parameter to select.
- Modified handleChange logic.
- Updated handleKeyEnter to check suggestions.
- Set aria-activedescendant in mounted.
packages/renderless/src/autocomplete/vue.ts Removed duplicate 'select' entry from api array.
- Updated select method to include dispatch.
packages/vue/src/autocomplete/package.json Version updated from 3.18.0 to 3.18.1.
- Added type and license fields.
- Adjusted dependencies and added devDependencies.
packages/vue/src/autocomplete/src/pc.vue Bound v-clickoutside directive to handleBlur method instead of @blur event.

Possibly related PRs

  • fix(form): [form] fix form tooltip class name #2154: This PR updates the version number in the package.json file for the @opentiny/vue-form-item package, similar to the version update in the main PR for @opentiny/vue-renderless.
  • Sync 3.18.0 to dev #2294: This PR also updates the version number in the package.json file for the @opentiny/vue-theme package, which is related to the versioning changes in the main PR.

Suggested reviewers

  • zzcr

🐇 In the code we hop and play,
New versions come to save the day!
Autocomplete now dances bright,
With changes made to bring delight.
So let us cheer, both near and far,
For updates shine like a guiding star! 🌟


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>, please review it.
    • 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 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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 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: 1

🧹 Outside diff range and nitpick comments (1)
packages/renderless/src/autocomplete/vue.ts (1)

127-127: LGTM! Consider adding a comment for clarity.

The addition of the dispatch parameter to the select function is a good improvement. It aligns with the PR objective to fix form validation errors and is consistent with other methods in the file.

Consider adding a brief comment explaining the purpose of the dispatch parameter for better code maintainability. For example:

-    select: select({ emit, nextTick, props, state, dispatch }),
+    // dispatch is used for form validation after selection
+    select: select({ emit, nextTick, props, state, dispatch }),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b19efbc and 90c97c1.

📒 Files selected for processing (5)
  • packages/renderless/package.json (1 hunks)
  • packages/renderless/src/autocomplete/index.ts (2 hunks)
  • packages/renderless/src/autocomplete/vue.ts (1 hunks)
  • packages/vue/src/autocomplete/package.json (1 hunks)
  • packages/vue/src/autocomplete/src/pc.vue (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/renderless/package.json
🧰 Additional context used
🔇 Additional comments (8)
packages/vue/src/autocomplete/package.json (4)

3-3: LGTM: Addition of "type": "module"

The addition of "type": "module" is a positive change. It explicitly declares that this package uses ECMAScript modules, which is consistent with modern JavaScript practices and can lead to better tree-shaking and module resolution.


4-4: LGTM: Version update to 3.18.1

The version update from 3.18.0 to 3.18.1 is appropriate for this PR. It follows semantic versioning principles, indicating a patch release for bug fixes, which aligns with the PR's objective to address a validation error in the autocomplete component.


6-6: LGTM: Addition of "license": "MIT"

The addition of the license field with the MIT license is a positive change. It clearly communicates the terms under which the package is distributed, which is crucial for open-source projects. The MIT license is a widely accepted and permissive license, suitable for many projects.


22-25: LGTM: Addition of devDependencies for testing

The addition of devDependencies, specifically @opentiny-internal/vue-test-utils and vitest, is a positive change. This suggests that testing capabilities have been added or restored to the package, which promotes better code quality and maintainability.

To ensure that test files exist for this package, you can run the following command:

#!/bin/bash
# Search for test files in the package directory
fd -e spec.ts -e spec.js -e test.ts -e test.js . packages/vue/src/autocomplete

If no test files are found, consider adding appropriate test cases for the autocomplete component.

packages/renderless/src/autocomplete/vue.ts (1)

Line range hint 1-180: Great work on addressing the form validation issue. A few suggestions to complete the PR:

  1. Please mark the completed items in the PR checklist.
  2. Consider adding unit tests to verify the fix for the form validation error when selecting suggestion options.
  3. Update the component documentation to reflect this change in behavior, if applicable.

To help verify the changes and ensure comprehensive test coverage, you can run the following script:

Would you like assistance in writing unit tests or updating the documentation for this change?

packages/vue/src/autocomplete/src/pc.vue (1)

27-27: Clarify the rationale for changing blur handling and ensure comprehensive testing.

The change from @blur to v-clickoutside for handling the blur event is interesting and potentially improves the component's behavior, especially in complex UI scenarios. This might indeed address the form validation errors mentioned in the PR objectives.

However, I have a few points to consider:

  1. Could you please clarify the specific issues this change addresses? Understanding the reasoning will help validate if this is the best approach.

  2. This non-standard way of handling blur events might not be immediately obvious to other developers. Consider adding a comment explaining why v-clickoutside is used instead of the standard @blur.

  3. Ensure thorough testing of various interaction scenarios, including:

    • Clicking on suggestion items
    • Clicking on other form elements
    • Tabbing through the form
    • Interacting with overlays or modals
  4. Verify that this change doesn't introduce any unexpected side effects in the component's behavior.

To help verify the impact of this change, you can run the following script to check for other usages of @blur in autocomplete-related components:

This will help ensure consistency across related components and identify any potential areas that might need similar updates.

✅ Verification successful

Blur handling update verified successfully.

No other instances of @blur found in autocomplete-related components, ensuring the change is isolated and does not impact other parts of the feature.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for @blur usage in autocomplete-related files
rg --type vue '@blur' packages/vue/src/autocomplete

Length of output: 79


Script:

#!/bin/bash
# Search for @blur usage in .vue files within autocomplete-related directories
rg '@blur' --type-add 'vue:*.vue' --type vue packages/vue/src/autocomplete

Length of output: 74

packages/renderless/src/autocomplete/index.ts (2)

168-169: Ensuring Consistent Form Validation on Selection

The addition of dispatch in the select function and the subsequent dispatch of FORM_EVENT.change when state.validateEvent is true ensures that form validation is triggered upon selecting an item. This change aligns with the validation logic present in other event handlers like handleChange, promoting consistency across the component.

Also applies to: 177-183


112-114: ⚠️ Potential issue

Potential Breaking Change: Removal of event parameter in handleBlur

The handleBlur function no longer accepts the event parameter, and the emitted 'blur' event no longer includes the event object. This change might impact consumers who rely on the event object in their 'blur' event handlers. Please verify that removing the event parameter does not introduce unintended side effects or break existing functionality.

To identify any 'blur' event handlers that depend on the event object, you can run the following script:

This script searches for 'blur' event bindings in Vue components that include arguments, indicating usage of the event object.

✅ Verification successful

No Breaking Change Detected: handleBlur Removal is Safe

After reviewing the usage of 'blur' event handlers, no consumers rely on the event parameter in handleBlur. The handler passing $event to saveEdit is unaffected, as saveEdit does not accept or utilize any parameters.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for 'blur' event handlers that use the event parameter in .vue files.

rg --type vue '@blur="[^"]+"' -o --no-filename | grep -E '@blur="[^"]*\([^)]*\)"'

Length of output: 111


Script:

#!/bin/bash
# Description: Search for 'blur' event handlers that use the event parameter in .vue files.

rg -g "*.vue" '@blur="[^"]+"' -o --no-filename | grep -E '@blur="[^"]*\([^)]*\)"'

Length of output: 263


Script:

#!/bin/bash
# Description: Find implementations of the `saveEdit` function to determine if it relies on the `event` parameter.

rg -g "*.vue" "function\s+saveEdit\s*\(" -A 5

Length of output: 1084

Comment on lines +15 to +18
"@opentiny/vue-common": "workspace:~",
"@opentiny/vue-icon": "workspace:~",
"@opentiny/vue-input": "workspace:~",
"@opentiny/vue-renderless": "workspace:~",
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

@opentiny/vue-icon is still in use across multiple files

The @opentiny/vue-icon dependency has been removed from the package.json, but it is still being imported in numerous files within the packages/vue/src/autocomplete directory and other related packages. This inconsistency can lead to potential runtime errors or build issues.

Please either add @opentiny/vue-icon back to the dependencies or refactor the code to eliminate its usage if it's no longer needed.

🔗 Analysis chain

Please clarify the removal of @opentiny/vue-icon from dependencies

The dependencies have been reordered, which is fine. However, @opentiny/vue-icon has been removed from the dependencies list. Could you please clarify why this dependency was removed? Is it no longer used in the package, or is it being imported differently now?

To check if @opentiny/vue-icon is still used in the package, you can run the following command:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for imports of @opentiny/vue-icon in the package
rg --type typescript --type vue "from ['\"]\@opentiny/vue-icon" packages/vue/src/autocomplete

Length of output: 205


Script:

#!/bin/bash
# Corrected script to search for imports of @opentiny/vue-icon in the autocomplete package
rg --type typescript --type vue "from ['\"]@opentiny/vue-icon['\"]" packages/vue/src/autocomplete

Length of output: 138


Script:

#!/bin/bash
# Corrected script to search for imports of @opentiny/vue-icon in the autocomplete package
rg --type ts --type vue "from ['\"]@opentiny/vue-icon['\"]" packages/vue/src/autocomplete

Length of output: 123


Script:

#!/bin/bash
# Search for imports of @opentiny/vue-icon in the autocomplete package
fd -e ts -e vue -t f packages/vue/src/autocomplete | xargs rg "from ['\"]@opentiny/vue-icon['\"]"

Length of output: 73589

@zzcr zzcr merged commit 80bcc5d into release-3.18.0 Oct 21, 2024
5 of 11 checks passed
kagol pushed a commit that referenced this pull request Oct 23, 2024
zzcr pushed a commit that referenced this pull request Oct 23, 2024
* fix(autocomplete): [autocomplete] fix form validate error when select suggestion option (#2296)

* fix: update @opentiny/fluent-editor version and export defaultToolbar

* chore(renderless): release v3.18.6

---------

Co-authored-by: gimmyhehe <[email protected]>
@kagol kagol deleted the cgm/fix-autocomplete-validate branch November 4, 2024 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants