Skip to content

Conversation

@gweesin
Copy link
Contributor

@gweesin gweesin commented Mar 3, 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?

https://opentiny.design/vue-playground?mode=pc&theme=os#3.21|eyJzcmMvQXBwLnZ1ZSI6IjxzY3JpcHQgbGFuZz1cInRzeFwiPlxuLy8g5byV5YWlIEBvcGVudGlueS92dWUg57uE5Lu2XG5pbXBvcnQgeyBCdXR0b24sIExpbmsgfSBmcm9tICdAb3BlbnRpbnkvdnVlJ1xuXG5leHBvcnQgZGVmYXVsdCB7XG4gIGNvbXBvbmVudHM6IHtcbiAgICBUaW55QnV0dG9uOiBCdXR0b24sXG4gICAgVGlueUxpbms6IExpbmtcbiAgfSxcbiAgZGF0YSgpIHtcbiAgICByZXR1cm4ge1xuICAgICAgbXNnOiAnaGVsbG8gd29ybGQhJ1xuICAgIH1cbiAgfVxufVxuPC9zY3JpcHQ+XG5cbjx0ZW1wbGF0ZT5cbiAgPFRpbnlCdXR0b24+56Gu5a6aPC9UaW55QnV0dG9uPlxuICA8aDE+e3sgbXNnIH19PC9oMT5cbiAgPGRpdiBjbGFzcz1cInRpbnl2dWVcIj5cbiAgICA8ZGl2IGNsYXNzPVwidGlueXZ1ZS1wYWdlXCI+XG4gICAgICB0aW55dnVlXG4gICAgICA8dGlueS1saW5rIHR5cGU9XCJzdWNjZXNzXCIgaHJlZj0naHR0cHM6Ly9naXRodWIuY29tL29wZW50aW55L3RpbnktdnVlJz5cbiAgICAgICAgdGlueXZ1ZVxuICAgICAgPC90aW55LWxpbms+XG4gICAgPC9kaXY+XG4gIDwvZGl2PlxuPC90ZW1wbGF0ZT5cblxuP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XCI6IFwiRVNOZXh0XCIsXHJcbiAgICBcIm1vZHVsZVwiOiBcIkVTTmV4dFwiLFxyXG4gICAgXCJtb2R1bGVSZXNvbHV0aW9uXCI6IFwiQnVuZGxlclwiLFxyXG4gICAgXCJhbGxvd0ltcG9ydGluZ1RzRXh0ZW5zaW9uc1wiOiB0cnVlXHJcbiAgfSxcclxuICBcInZ1ZUNvbXBpbGVyT3B0aW9uc1wiOiB7XHJcbiAgICBcInRhcmdldFwiOiAzLjNcclxuICB9XHJcbn1cclxuIiwiYmFzaWMtdXNhZ2UudnVlIjoiPHRlbXBsYXRlPlxuICA8dGlueS1iYWRnZSA6dmFsdWU9XCIyXCIgZGF0YT1cIuaIkeeahOW+heWKnlwiIGlzLWRvdD48L3RpbnktYmFkZ2U+XG48L3RlbXBsYXRlPlxuXG48c2NyaXB0IHNldHVwPlxuaW1wb3J0IHsgVGlueUJhZGdlIH0gZnJvbSAnQG9wZW50aW55L3Z1ZSdcbjwvc2NyaXB0PlxuIiwiX28iOnt9fQ==

Issue Number: #3005

What is the new behavior?

expected successfully

  test('is-dot with value', () => {
    const wrapper = mount(() => <Badge value={2} is-dot />)
    expect(wrapper.find('.tiny-badge').exists()).toBe(true)
    expect(wrapper.find('.tiny-badge__content-text').text()).toBe('')
  })

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Improved the badge’s display behavior so that when the dot indicator is enabled, any accompanying text is intentionally hidden. This change streamlines the user interface, providing a cleaner and more consistent appearance.

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2025

Walkthrough

This pull request updates both the Badge component tests and its rendering logic. In the test file, JSX syntax is refactored by replacing closing tags with self-closing tags in the content and default slot tests; the assignment of the hidden prop is also made more explicit, and a new test case (is-dot with value) has been added. In the component file, the <slot name="content"> logic now uses an additional nested <template> to conditionally render state.content based on the isDot property. There are no changes to exported/public entities.

Changes

File(s) Change Summary
packages/vue/src/badge/tests/badge.test.tsx Refactored JSX: replaced closing tags with self-closing tags in content and default slots; updated hidden prop assignments; added new test "is-dot with value".
packages/vue/src/badge/src/pc.vue Modified slot rendering logic: introduced a nested <template> inside <slot name="content"> to conditionally render state.content based on the isDot property.

Sequence Diagram(s)

sequenceDiagram
    participant C as Badge Component
    participant T as Content Slot
    C->>C: Evaluate state.href
    alt state.href is false
        C->>C: Check isDot flag
        alt isDot is false
            C->>T: Render state.content within <span>
        else isDot is true
            C->>T: Render dot indicator (omit state.content)
        end
    else
        C->>C: Render as hyperlink (using state.href)
    end
Loading

Suggested labels

bug

Suggested reviewers

  • zzcr

Poem

I'm a little rabbit, hopping through code delight,
Badge tests and renders shining in the night.
Self-closing tags and conditions so neat,
Every change a garden where logic and design meet.
I nibble on bugs with a cheerful beat,
Hopping over improvements—oh, what a treat!
🥕🐇

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/vue/src/badge/__tests__/badge.test.tsx

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/badge/src/pc.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.

✨ 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 3, 2025
@petercat-assistant
Copy link

Walkthrough

This pull request addresses a bug in the Badge component where the dot badge style was incorrectly displayed when a value was present. The changes ensure that the dot badge does not display any content text when a value is provided, aligning with the expected behavior.

Changes

File Summary
packages/vue/src/badge/__tests__/badge.test.tsx Updated tests to verify the correct behavior of the dot badge with a value, ensuring no content text is displayed.
packages/vue/src/badge/src/pc.vue Modified the template to conditionally render content text only when isDot is false.

<slot name="content">
<a v-if="state.href" :href="state.href" :target="target" rel="noopener noreferrer">{{ state.content }}</a>
<span class="tiny-badge__content-text" v-if="!state.href">{{ state.content }}</span>
<span class="tiny-badge__content-text" v-if="!state.href">

Choose a reason for hiding this comment

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

Ensure that the isDot condition is correctly applied to prevent content text from displaying when isDot is true. This change addresses the issue with the dot badge style.

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/vue/src/badge/src/pc.vue (1)

29-33: Fixed the badge display logic for dot badges with values.

This change correctly implements the requirement that dot badges should not display value content. By conditionally rendering the content only when !isDot is true, the component now properly hides values when the badge is in dot mode, which aligns with the UX design pattern for dot badges.

For better readability, consider using a v-else-if pattern instead of a nested template:

-<span class="tiny-badge__content-text" v-if="!state.href">
-  <template v-if="!isDot">
-    {{ state.content }}
-  </template>
-</span>
+<span class="tiny-badge__content-text" v-if="!state.href && !isDot">
+  {{ state.content }}
+</span>

This simplifies the template structure while maintaining the same conditional rendering logic.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6cbb529 and 9aa2e51.

📒 Files selected for processing (2)
  • packages/vue/src/badge/__tests__/badge.test.tsx (4 hunks)
  • packages/vue/src/badge/src/pc.vue (1 hunks)
🔇 Additional comments (6)
packages/vue/src/badge/__tests__/badge.test.tsx (6)

47-48: Improved JSX syntax with self-closing tags.

The change from a full closing tag to a self-closing tag makes the JSX syntax more concise and is a standard approach for elements without children.


58-62: Enhanced code formatting with proper indentation.

The updated formatting improves readability by properly nesting JSX elements with consistent indentation.


75-75: Consistent usage of self-closing tags.

Similar to the earlier change, this improves JSX syntax consistency by using a self-closing tag for elements with no children.


98-98: Explicit prop assignment improves clarity.

Setting hidden: false explicitly rather than using a conditional expression improves code readability and makes the test intent clearer.


104-104: Direct boolean assignment is more readable.

Changed from a potentially confusing conditional expression to a direct hidden: true assignment, which is clearer and more maintainable.


108-112: Added critical test case for the bugfix.

This test directly addresses the bug being fixed - ensuring that a dot badge with a value doesn't display the value content. The test verifies two key aspects:

  1. The badge element exists when both is-dot and a value are provided
  2. The content text is empty as expected for dot badges

This test is essential for preventing regression and documenting the expected behavior.

@zzcr zzcr merged commit 6587d10 into opentiny:dev Mar 4, 2025
14 of 16 checks passed
@gweesin gweesin deleted the fix/badge-dot-value branch March 4, 2025 03:56
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