Skip to content

fix(cascader): [cascader,select] add the changeCompat attribute to the component #2934

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

Merged
merged 2 commits into from
Feb 20, 2025

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Feb 20, 2025

PR

为cascader组件添加changeCompat属性
为option 组件添加默认的title属性

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

Summary by CodeRabbit

  • New Features
    • Enhanced responsiveness as the Cascader now distinguishes user-triggered actions from automated updates.
    • A new compatibility mode option has been added, enabling tailored event handling across mobile and desktop experiences.
    • Improved accessibility with dynamic tooltips providing additional context on selectable options.

Copy link

coderabbitai bot commented Feb 20, 2025

Walkthrough

This pull request updates the cascader component in both renderless and Vue implementations. It introduces a new exported function watchValue to monitor value changes and sets a userChangeValue flag in state. The watchCheckedValue function is modified to include props and to decide event emissions based on whether the change is user-initiated. Additionally, a new changeCompat property is added to the cascader props and integrated into the mobile-first and PC variants, along with an accessibility improvement in the option component.

Changes

File(s) Change Summary
packages/renderless/.../cascader/index.ts, packages/renderless/.../cascader/vue.ts Added new watchValue function; updated watchCheckedValue signature to include props and handle a new userChangeValue state flag for differentiating user-initiated changes.
packages/vue/.../cascader/src/index.ts Added new changeCompat property to cascaderProps with a Boolean type and default value of false.
packages/vue/.../cascader/src/mobile-first.vue, packages/vue/.../cascader/src/pc.vue Integrated changeCompat by adding it to the emitted events and props for enhanced configuration.
packages/vue/.../option/src/pc.vue Added a dynamic title attribute to the <li> element to improve accessibility.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Component
    participant watchValue
    participant watchCheckedValue
    participant Emitter

    User->>Component: Initiates value change
    Component->>watchValue: Call with new value
    watchValue-->>Component: Update state (checkedValue, userChangeValue)
    Component->>watchCheckedValue: Invoke with new value and props
    alt User-initiated change (state.userChangeValue true)
       watchCheckedValue->>Emitter: Emit update:modelValue & change events
       watchCheckedValue->>Component: Reset userChangeValue flag
    else Programmatic change
       watchCheckedValue->>Emitter: Emit update:modelValue & change events
    end
Loading

Possibly related PRs

Suggested labels

enhancement, feature

Suggested reviewers

  • zzcr

Poem

I'm a rabbit hopping through lines of code,
In a field where new methods gladly explode.
With watchValue and changes in the air,
User-driven flags now handled with care.
A sprinkle of change makes my heart skip a node!
🐰✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/renderless/src/cascader/index.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/renderless/src/cascader/vue.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/vue/src/cascader/src/index.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

  • 3 others
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@github-actions github-actions bot added the bug Something isn't working label Feb 20, 2025
Copy link

Walkthrough

此PR为cascader组件添加了一个新的changeCompat属性,并为option组件添加了默认的title属性。这些更改旨在增强组件的功能和兼容性。

Changes

文件 概要
packages/renderless/src/cascader/index.ts, packages/renderless/src/cascader/vue.ts 添加了changeCompat属性的逻辑处理,确保在用户修改值时根据属性决定是否触发事件。
packages/vue/src/cascader/src/index.ts, packages/vue/src/cascader/src/mobile-first.vue, packages/vue/src/cascader/src/pc.vue 在组件中添加了changeCompat属性的定义和使用。
packages/vue/src/option/src/pc.vue 为option组件添加了默认的title属性。

@shenjunjian shenjunjian changed the title fix(cascader): add the changeCompat attribute to the component fix(cascader): [cascader,select] add the changeCompat attribute to the component Feb 20, 2025
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Walkthrough

This PR adds a new changeCompat property to the cascader component and a default title property to the option component. These changes are designed to enhance the functionality and compatibility of components.

Changes

Documents Summary
packages/renderless/src/cascader/index.ts, packages/renderless/src/cascader/vue.ts Added logical processing of the changeCompat attribute to ensure that the user decides whether to trigger the event based on the attribute when modifying the value.
packages/vue/src/cascader/src/index.ts, packages/vue/src/cascader/src/mobile-first.vue, packages/vue/src/cascader/src/pc.vue Added in the component Definition and use of changeCompat property.
packages/vue/src/option/src/pc.vue Added the default title attribute to the option component.

Copy link

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

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

🧹 Nitpick comments (2)
packages/vue/src/cascader/src/index.ts (1)

104-107: Add JSDoc documentation for the changeCompat prop.

While the prop is properly typed, adding documentation would help other developers understand its purpose and usage.

Add documentation above the prop:

+  /**
+   * When true, maintains compatibility with older behavior for change events.
+   * @default false
+   */
   changeCompat: {
     type: Boolean,
     default: false
   }
packages/renderless/src/cascader/index.ts (1)

85-93: Consider using nextTick instead of setTimeout.

The function correctly handles user-initiated value changes. However, using setTimeout for computing present content might cause a flash of content. Consider using Vue's nextTick for a more reliable update timing.

-      setTimeout(api.computePresentContent)
+      nextTick(api.computePresentContent)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1080ec and a368900.

📒 Files selected for processing (6)
  • packages/renderless/src/cascader/index.ts (3 hunks)
  • packages/renderless/src/cascader/vue.ts (3 hunks)
  • packages/vue/src/cascader/src/index.ts (1 hunks)
  • packages/vue/src/cascader/src/mobile-first.vue (2 hunks)
  • packages/vue/src/cascader/src/pc.vue (1 hunks)
  • packages/vue/src/option/src/pc.vue (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: PR Unit Test
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (6)
packages/vue/src/option/src/pc.vue (1)

20-20: Great accessibility improvement!

Adding the title attribute enhances the user experience by providing tooltips on hover, especially useful for truncated or long labels.

packages/vue/src/cascader/src/mobile-first.vue (1)

95-96:

❓ Verification inconclusive

Verify changeCompat event emission.

The changeCompat event is added to emits but there's no visible implementation emitting this event. Ensure the event is properly emitted where needed.


🏁 Script executed:

#!/bin/bash
# Search for changeCompat event emissions
rg -l "emit.*changeCompat" .

Length of output: 30


ACTION REQUIRED: Verify changeCompat Event Emission

Our repository search (using rg -l "emit.*changeCompat") did not reveal any instances where the changeCompat event is actually emitted. Please verify that this event is correctly triggered in the component's logic where applicable. If the omission is intentional, consider adding a brief comment to clarify why the event remains un-emitted.

packages/renderless/src/cascader/vue.ts (2)

136-137: LGTM!

The addition of userChangeValue state property is well-designed to track user-initiated value changes, which is essential for the new changeCompat functionality.


192-192: LGTM!

The function signature update correctly includes the props parameter, which is necessary for accessing the changeCompat property.

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

84-84: LGTM!

The comment clearly explains the function's purpose and behavior regarding user-initiated value changes.


128-139: LGTM!

The event emission logic is well-implemented:

  • User-initiated changes respect the changeCompat flag.
  • Non-user-initiated changes (clicks, deletes) maintain backward compatibility.
  • The state is properly reset after handling user-initiated changes.

Comment on lines +237 to +238
'blank',
'changeCompat'
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Maintain consistency with mobile-first component.

The mobile-first component includes 'changeCompat' in its emits array, but it's missing here. Consider adding it to maintain consistency across components.

Add the event to emits:

   emits: [
     'update:modelValue',
     'change',
     'visible-change',
     'focus',
     'blur',
     'expand-change',
     'active-item-change',
     'remove-tag',
-    'created'
+    'created',
+    'changeCompat'
   ],
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'blank',
'changeCompat'
emits: [
'update:modelValue',
'change',
'visible-change',
'focus',
'blur',
'expand-change',
'active-item-change',
'remove-tag',
'created',
'changeCompat'
],

@zzcr zzcr merged commit 1b406ea into opentiny:dev Feb 20, 2025
13 of 16 checks passed
@opentiny opentiny deleted a comment from petercat-assistant bot Feb 21, 2025
@shenjunjian shenjunjian deleted the fix-cascader-select branch March 10, 2025 11:35
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.

3 participants