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(tag): tag add maxWidth prop, and select add maxTagWidth prop #3158

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Mar 19, 2025

PR

为tag添加 maxWidth 属性, 为select 添加 maxTagWidth属性
添加相应的文档

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
    • Introduced configurable maximum width settings for tag displays in multi-select and standalone tag components.
    • Added demonstration components showcasing the new maximum width behavior across different device modes.
  • Style
    • Enhanced tag styling with improved overflow handling and text truncation for a cleaner UI.
  • Tests
    • Implemented automated tests to ensure the maximum width settings render correctly.

Copy link

coderabbitai bot commented Mar 19, 2025

Walkthrough

This PR introduces new properties to control the maximum width of tags in both the select and tag components. The updates span demo files, core component files, test scripts, and style sheets for PC and mobile-first environments. New Vue demo components and a Playwright test have been added to showcase and validate the max-width functionality, while CSS utility classes and rules have been updated to handle text overflow and truncation.

Changes

File(s) Change Summary
examples/sites/demos/apis/select.js
packages/vue/src/select/src/index.ts
packages/vue/src/select/src/mobile-first.vue
packages/vue/src/select/src/pc.vue
Added new properties (max-tag-width in demos and maxTagWidth in implementation) to configure the maximum width of tags in the select component.
examples/sites/demos/apis/tag.js
packages/vue/src/tag/src/index.ts
packages/vue/src/tag/src/mobile-first.vue
packages/vue/src/tag/src/pc.vue
Introduced/reintroduced the property (max-width/maxWidth) for tag components to control their maximum width and adjust inline styling.
examples/sites/demos/pc/app/tag/max-width-composition-api.vue
examples/sites/demos/pc/app/tag/max-width.vue
examples/sites/demos/pc/app/tag/webdoc/tag.js
examples/sites/demos/pc/app/tag/max-width.spec.ts
Added new demo components and a test file to demonstrate and verify the max-width feature on tags.
packages/theme-saas/src/tag/index.less
packages/theme/src/tag/index.less
Updated CSS by adding utility classes and properties for overflow handling and text truncation in tag components.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant S as Select Component
    participant T as Tag Component
    participant CSS as Styling Engine

    U->>S: Makes a selection
    S->>T: Passes maxTagWidth/max-width property
    T->>CSS: Applies inline styles for max width and text overflow
    CSS-->>T: Renders tag with controlled width
    T-->>S: Displays tag within limits
Loading

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • zzcr

Poem

I’m a rabbit hopping through the code,
With max-width tags in a neat new mode.
Each property set makes the layout neat,
Overflow trimmed—a visual treat.
I bounce with joy at each new line,
Happy to see the changes align!

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/select.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.

examples/sites/demos/apis/tag.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.

examples/sites/demos/pc/app/tag/max-width-composition-api.vue

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.

  • 9 others

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ 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.
    • 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 19, 2025
Copy link

Walkthrough

此PR为tag组件添加了maxWidth属性,并为select组件添加了maxTagWidth属性。这些更改包括更新相关文档和样式文件,以支持新属性的功能。还添加了相应的测试用例来验证这些功能。

Changes

文件 摘要
examples/sites/demos/apis/select.js, examples/sites/demos/apis/tag.js selecttag组件添加了maxTagWidthmaxWidth属性的API描述。
examples/sites/demos/pc/app/tag/max-width-composition-api.vue, examples/sites/demos/pc/app/tag/max-width.vue 添加了演示maxWidth属性的示例文件。
examples/sites/demos/pc/app/tag/max-width.spec.ts 添加了测试用例以验证maxWidth属性的功能。
examples/sites/demos/pc/app/tag/webdoc/tag.js 更新了文档以包括maxWidth属性的描述。
packages/theme-saas/src/tag/index.less, packages/theme/src/tag/index.less 更新了样式文件以支持maxWidth属性。
packages/vue/src/select/src/index.ts, packages/vue/src/tag/src/index.ts selecttag组件中添加了maxTagWidthmaxWidth属性的实现。
packages/vue/src/select/src/mobile-first.vue, packages/vue/src/select/src/pc.vue, packages/vue/src/tag/src/mobile-first.vue, packages/vue/src/tag/src/pc.vue 更新了组件文件以支持新属性。

import { test, expect } from '@playwright/test'

test('各型号尺寸是否正常', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).not.toBeNull())

Choose a reason for hiding this comment

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

Ensure that the page error handler is correctly capturing and logging errors. Consider adding more specific error handling if necessary.

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

@Issues-translate-bot
Copy link

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


Walkthrough

This PR adds the maxWidth property to the tag component and the maxTagWidth property to the select component. These changes include the ability to update related documents and style files to support new properties. Corresponding test cases have also been added to verify these features.

Changes

File Summary
examples/sites/demos/apis/select.js, examples/sites/demos/apis/tag.js Added API descriptions for the maxTagWidth and maxWidth properties for the select and tag components.
examples/sites/demos/pc/app/tag/max-width-composition-api.vue, examples/sites/demos/pc/app/tag/max-width.vue Added an example file that demonstrates the maxWidth property.
examples/sites/demos/pc/app/tag/max-width.spec.ts Added test cases to verify the functionality of the maxWidth property.
examples/sites/demos/pc/app/tag/webdoc/tag.js Updated documentation to include a description of the maxWidth property.
packages/theme-saas/src/tag/index.less, packages/theme/src/tag/index.less Updated style files to support the maxWidth property.
packages/vue/src/select/src/index.ts, packages/vue/src/tag/src/index.ts Added the implementation of the maxTagWidth and maxWidth properties in the select and tag components.
packages/vue/src/select/src/mobile-first.vue, packages/vue/src/select/src/pc.vue, packages/vue/src/tag/src/mobile-first.vue, packages/vue/src/tag/src/pc.vue Updated component files to support new properties.

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)
examples/sites/demos/pc/app/tag/max-width.spec.ts (1)

1-10: Test name could be more specific to the maxWidth feature

While the test correctly verifies that the tag respects the specified maxWidth of 80px, the test name "各型号尺寸是否正常" (roughly "whether different model sizes are normal") doesn't specifically indicate that it's testing the maxWidth feature. Consider renaming it to something more specific like "标签的maxWidth属性是否生效" (whether the tag's maxWidth property takes effect).

Otherwise, the test implementation looks good.

-test('各型号尺寸是否正常', async ({ page }) => {
+test('标签的maxWidth属性是否生效', async ({ page }) => {
packages/vue/src/tag/src/mobile-first.vue (1)

54-59: Consider adding unit validation for maxWidth.

The implementation for maxWidth looks good, but there's no validation to ensure the value includes a valid CSS unit (px, %, em, etc.). If a number without a unit is provided, it might not work as expected in some browsers.

if (maxWidth) {
-  styles.maxWidth = maxWidth
+  styles.maxWidth = typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth
  styles.display = 'inline-block'
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 34b7233 and 564c2d1.

📒 Files selected for processing (14)
  • examples/sites/demos/apis/select.js (1 hunks)
  • examples/sites/demos/apis/tag.js (1 hunks)
  • examples/sites/demos/pc/app/tag/max-width-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/tag/max-width.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/tag/max-width.vue (1 hunks)
  • examples/sites/demos/pc/app/tag/webdoc/tag.js (1 hunks)
  • packages/theme-saas/src/tag/index.less (1 hunks)
  • packages/theme/src/tag/index.less (1 hunks)
  • packages/vue/src/select/src/index.ts (1 hunks)
  • packages/vue/src/select/src/mobile-first.vue (6 hunks)
  • packages/vue/src/select/src/pc.vue (6 hunks)
  • packages/vue/src/tag/src/index.ts (1 hunks)
  • packages/vue/src/tag/src/mobile-first.vue (2 hunks)
  • packages/vue/src/tag/src/pc.vue (3 hunks)
🔇 Additional comments (26)
packages/vue/src/tag/src/pc.vue (3)

35-36: LGTM: maxWidth prop added to tag component

The new maxWidth prop has been properly added to the component's props array.


55-56: LGTM: Proper destructuring of the maxWidth prop

The maxWidth prop is correctly destructured from the component instance along with other properties.


81-84: LGTM: Style implementation for maxWidth

The implementation sets both maxWidth and display properties when maxWidth is provided. Setting display to 'inline-block' is necessary for text truncation to work properly with the CSS classes added in the theme file.

examples/sites/demos/pc/app/tag/max-width.vue (3)

1-5: LGTM: Well-structured demo template

The demo clearly showcases the new maxWidth feature with a practical example using a long text string that would trigger truncation.


7-15: LGTM: Clean component implementation

The component imports and registers TinyTag properly, following the project's conventions.


17-22: LGTM: Appropriate styling for the demo

The margins provide good spacing for the demo display.

packages/theme-saas/src/tag/index.less (1)

18-20: LGTM: Essential CSS utilities added for text truncation

These two CSS utilities work together to ensure text is properly truncated with an ellipsis when the maxWidth property is applied:

  1. overflow-hidden prevents text from spilling outside the container
  2. text-ellipsis adds the ellipsis when text is truncated

This is essential for the maxWidth property to function correctly.

packages/vue/src/select/src/index.ts (1)

366-370: Well-structured addition of the maxTagWidth property.

This new property for configuring tag width in multi-select scenarios is well-documented and follows the component's existing prop pattern. The type definition correctly allows both String and Number values with an appropriate default.

packages/vue/src/tag/src/index.ts (1)

42-45: Appropriate implementation of the maxWidth property.

The maxWidth property is correctly defined to allow both String and Number types with a null default, consistent with the component's existing property definitions.

packages/vue/src/select/src/pc.vue (6)

89-89: Consistent application of maxTagWidth prop to the first tag.

The first occurrence of the maxTagWidth prop is correctly added to the tag that displays the first selected item.


123-123: Proper implementation of maxTagWidth for the counter tag.

The maxTagWidth prop is correctly added to the tag that displays the count of additional selected items.


140-140: Appropriate application of maxTagWidth to the "all" text tag.

The maxTagWidth prop is correctly added to the tag that displays the "all" text when showAllTextTag is true.


156-156: Consistent implementation of maxTagWidth for the collapse tag.

The maxTagWidth prop is correctly added to the collapse tag that appears when using hover expand functionality.


175-175: Thorough implementation of maxTagWidth for individual selected item tags.

The maxTagWidth prop is correctly added to the tags that display each selected item in the loop.


770-771: Complete implementation with prop registration.

The maxTagWidth property is correctly added to the component's props array, maintaining the component structure.

examples/sites/demos/pc/app/tag/max-width-composition-api.vue (1)

1-16: Well-structured demo for the new maxWidth feature.

The demo clearly illustrates the use of the maxWidth property with a realistic example of text that would overflow without this constraint. The component is correctly imported and the styling is consistent with other demos.

examples/sites/demos/pc/app/tag/webdoc/tag.js (1)

79-90: LGTM! Properly documented new feature.

The addition of the 'max-width' demo is well-structured with appropriate names and descriptions in both Chinese and English, properly showcasing the new feature.

examples/sites/demos/apis/tag.js (1)

57-70: LGTM! API documentation is clear and complete.

The new 'max-width' property is well-documented with appropriate type, default value, descriptions, and version information. Support for both PC and mobile-first environments is properly indicated.

packages/vue/src/tag/src/mobile-first.vue (2)

27-28: LGTM! New prop added correctly.

The 'maxWidth' property has been properly added to the props array.


62-62: LGTM! Style application is correct.

The style binding has been properly updated to use the styles object that includes the maxWidth property when specified.

examples/sites/demos/apis/select.js (1)

547-560: LGTM - New property added to support maximum tag width control

The implementation of the max-tag-width property is well-documented with clear descriptions in both Chinese and English. The property is correctly configured to work in both 'pc' and 'mobile-first' modes with appropriate versioning metadata.

I like that this addition will allow developers to control tag widths in multi-select scenarios, improving UI consistency and preventing layout issues from overly wide tags.

packages/vue/src/select/src/mobile-first.vue (5)

90-90: LGTM - Properly implemented maxWidth for the first tag instance

The maxTagWidth property is correctly bound to the maxWidth attribute on the first tag instance, allowing for width control when the tag is rendered.


124-124: LGTM - Properly implemented maxWidth for count tag

The maxTagWidth property is correctly applied to the tag that shows the "+N" count when there are multiple selections, ensuring consistent styling across all tag elements.


144-144: LGTM - Properly implemented maxWidth for collapse tag

The maxTagWidth property is properly applied to the tag that displays when tags are collapsed, ensuring consistent width constraints.


157-157: LGTM - Properly implemented maxWidth for individual selection tags

The maxTagWidth property is correctly applied to each individual tag in the selection list, ensuring that all tags have consistent width constraints regardless of their content.


718-719: LGTM - Property added to component props array

The maxTagWidth property is correctly added to the component's props array, making it accessible throughout the component.

Comment on lines +21 to +23
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

CSS properties are duplicated.

The CSS properties for text truncation (text-overflow: ellipsis;, overflow: hidden;, and white-space: nowrap;) are added at lines 21-23, but these same properties already exist at lines 32-34. This duplication is unnecessary and could lead to maintenance issues.

- text-overflow: ellipsis;
- overflow: hidden;
- white-space: nowrap;
📝 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
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;

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