Skip to content

Conversation

@gweesin
Copy link
Contributor

@gweesin gweesin commented Mar 4, 2025

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: #3004

What is the new behavior?

validate size property

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor
    • Improved size validation for breadcrumb and breadcrumb-item components to enforce consistent and allowed values.
    • Restricted sizing options to ensure uniform appearance across the components.

@coderabbitai
Copy link

coderabbitai bot commented Mar 4, 2025

Walkthrough

This pull request restricts the allowed values for the size prop in breadcrumb components. In one instance (in breadcrumb.js), the prop type is changed from a generic string to a literal 'medium'. In other instances (in both breadcrumb-item/src/index.ts and breadcrumb/src/index.ts), the size prop is redefined as an object with properties for type, default value, and a validator that only accepts 'medium' or an empty string. Comments indicate that other values (e.g., 'large', 'small', 'mini') were previously considered but are now disabled.

Changes

File(s) Change Summary
examples/sites/demos/apis/breadcrumb.js Updated size prop in both breadcrumb and breadcrumb-item components: changed type from 'string' to literal type 'medium'; default remains 'medium'.
packages/vue/src/breadcrumb-item/src/index.ts, packages/vue/src/breadcrumb/src/index.ts Refactored the size prop definition to an object with type, default, and a validator that allows only 'medium' or an empty string; previously valid values are commented out.

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • zzcr

Poem

In the code garden I hop along,
Adjusting props with a gentle song.
Now "medium" rules, clear and true,
Validators ensure the logic anew.
With every line, I munch a carrot—hooray!
A rabbit's cheer for our refined array!

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.

examples/sites/demos/apis/breadcrumb.js

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/breadcrumb-item/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.

packages/vue/src/breadcrumb/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.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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 Mar 4, 2025
@gweesin gweesin changed the title fix(breadcrumb): update size prop type and add validator fix(breadcrumb): [breadcrumb] update size prop type and add validator Mar 4, 2025
@petercat-assistant
Copy link

Walkthrough

This pull request addresses a bugfix for the breadcrumb component by updating the size prop type from a simple string to a more structured object with a validator function. This ensures that only valid size values are accepted, enhancing the robustness of the component.

Changes

File Summary
examples/sites/demos/apis/breadcrumb.js Updated size prop type to 'medium' for consistency.
packages/vue/src/breadcrumb-item/src/index.ts
packages/vue/src/breadcrumb/src/index.ts
Changed size prop to an object with a validator to ensure valid size values.

{
name: 'size',
type: 'string',
type: "'medium'",

Choose a reason for hiding this comment

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

The change from type: 'string' to type: 'medium' seems incorrect. The type should likely remain string to allow for different size values, unless 'medium' is intended as a default or constant value.

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 (2)
packages/vue/src/breadcrumb/src/index.ts (1)

38-42: Validator implementation ensures consistent size property values.

The updated validator restricts the size property to only accept 'medium' or an empty string, which aligns with the API documentation changes. The commented-out values ('large', 'small', 'mini') indicate these were previously valid options but are now disabled.

To improve clarity for future maintainers, consider adding a comment explaining why only 'medium' and empty string are valid now. Also, for better readability, you could extract the allowed sizes into a constant:

+// Only 'medium' size is currently supported as per issue #3004
+const ALLOWED_SIZES = ['medium', ''];
 size: {
   type: String,
   default: '',
-  validator: (val: string) => [/* 'large', */ 'medium', /* 'small', 'mini',  */ ''].includes(val)
+  validator: (val: string) => ALLOWED_SIZES.includes(val)
 },
examples/sites/demos/apis/breadcrumb.js (1)

43-45: Type restriction for 'size' prop is consistent with validator changes.

The type has been correctly updated from a generic string to specifically "'medium'" to restrict the allowed values.

To complement this change, consider updating the description to explicitly mention that only 'medium' size is supported:

 desc: {
-  'zh-CN': '设置面包屑尺寸大小',
-  'en-US': 'Set breadcrumb size'
+  'zh-CN': '设置面包屑尺寸大小,当前仅支持 medium',
+  'en-US': 'Set breadcrumb size, currently only supports medium'
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 04edfe7 and 1ea9f8c.

📒 Files selected for processing (3)
  • examples/sites/demos/apis/breadcrumb.js (2 hunks)
  • packages/vue/src/breadcrumb-item/src/index.ts (1 hunks)
  • packages/vue/src/breadcrumb/src/index.ts (1 hunks)
🔇 Additional comments (2)
examples/sites/demos/apis/breadcrumb.js (1)

109-111: Consistent type restriction for BreadcrumbItem's 'size' prop.

The type change from a generic string to "'medium'" mirrors the same change made for the Breadcrumb component, ensuring consistency across related components.

packages/vue/src/breadcrumb-item/src/index.ts (1)

22-26:

✅ Verification successful

Validator implementation consistently restricts size values across components.

The validator implementation matches the one in the Breadcrumb component, ensuring that both components handle the size property in the same way.

Let's check if there are any usages of sizes other than 'medium' or empty string in the codebase that might need updating:


🏁 Script executed:

#!/bin/bash
# Find any usage of 'large', 'small', or 'mini' sizes for breadcrumb components that might need to be updated

# Search for breadcrumb size usages in the codebase
echo "Searching for breadcrumb size usages in Vue templates or JavaScript/TypeScript files..."
rg -i "size\s*=\s*['\"](?:large|small|mini)['\"]" --type vue --type js --type ts
rg -i ":size\s*=\s*['\"](?:large|small|mini)['\"]" --type vue
rg -i "size:\s*['\"](?:large|small|mini)['\"]" --type js --type ts

echo "Searching for breadcrumb examples or demos with size props..."
rg -i "breadcrumb.*size.*(?:large|small|mini)" --type vue --type js --type ts

Length of output: 3136


Below is a refined shell script that avoids the “unrecognized file type: vue” error by using explicit globs. This script targets breadcrumb-related directories to verify that no instances using the disallowed size values (‘large’, ‘small’, or ‘mini’) remain—and thus that the validator in packages/vue/src/breadcrumb-item/src/index.ts is indeed consistent with the Breadcrumb component.

Please run the following script and share its output so we can confirm that only the allowed values (i.e. 'medium' or '') are used in the breadcrumb components:

Once we’ve confirmed that no breadcrumb files use disallowed size values, we can confidently state that the validator implementation is consistent across components.

Action: Please run the above script and verify the output.


🏁 Script executed:

#!/bin/bash
echo "Searching for invalid size values in Breadcrumb components (Vue and TS files)..."

echo ">> Checking in packages/vue/src/breadcrumb:"
rg -i --glob "*.vue" "size\s*=\s*['\"](?:large|small|mini)['\"]" packages/vue/src/breadcrumb
rg -i --glob "*.vue" "size:\s*['\"](?:large|small|mini)['\"]" packages/vue/src/breadcrumb
rg -i --glob "*.ts" "size\s*=\s*['\"](?:large|small|mini)['\"]" packages/vue/src/breadcrumb
rg -i --glob "*.ts" "size:\s*['\"](?:large|small|mini)['\"]" packages/vue/src/breadcrumb

echo ""
echo ">> Checking in packages/vue/src/breadcrumb-item:"
rg -i --glob "*.vue" "size\s*=\s*['\"](?:large|small|mini)['\"]" packages/vue/src/breadcrumb-item
rg -i --glob "*.vue" "size:\s*['\"](?:large|small|mini)['\"]" packages/vue/src/breadcrumb-item
rg -i --glob "*.ts" "size\s*=\s*['\"](?:large|small|mini)['\"]" packages/vue/src/breadcrumb-item
rg -i --glob "*.ts" "size:\s*['\"](?:large|small|mini)['\"]" packages/vue/src/breadcrumb-item

echo "Search completed."

Length of output: 1348


Validation Complete: The breadcrumb size validator is consistent.

  • The search in the packages/vue/src/breadcrumb and packages/vue/src/breadcrumb-item directories confirmed that no disallowed size values ('large', 'small', or 'mini') are in use.
  • The validator in packages/vue/src/breadcrumb-item/src/index.ts correctly mirrors the implementation in the Breadcrumb component by allowing only 'medium' and an empty string.

@zzcr zzcr merged commit a210f5a into opentiny:dev Mar 7, 2025
15 of 16 checks passed
@gweesin gweesin deleted the fix/breadcrumb-docs branch March 7, 2025 10:38
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.

🐛 [Bug]: 文档中 Breadcrumb 及 BreadcrumbItem size 属性应当为枚举,目前为 string

2 participants