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

feat(modal): [modal] add show-close feature #2840

Merged
merged 3 commits into from
Jan 24, 2025
Merged

feat(modal): [modal] add show-close feature #2840

merged 3 commits into from
Jan 24, 2025

Conversation

James-9696
Copy link
Collaborator

@James-9696 James-9696 commented Jan 23, 2025

PR

新增modal组件是否显示关闭按钮新特性

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

    • Added show-close property to the modal component, allowing customization of the close button visibility.
    • Enhanced control over the modal close button for both modal and confirmation dialogs.
    • Expanded modal configuration options for PC and mobile-first environments.
  • Documentation

    • Updated modal component documentation with details on the new show-close property.
    • Specified stable version 3.22.0 for the feature.

Copy link

coderabbitai bot commented Jan 23, 2025

Walkthrough

The pull request introduces a new show-close property for the modal component, expanding its configurability across PC and mobile-first environments. The changes modify the modal's API to allow developers to control the visibility of the close button. This enhancement is implemented across multiple files, including API documentation, demo components, and the core modal component implementation. The modifications provide more flexibility in modal interaction and user interface design.

Changes

File Change Summary
examples/sites/demos/apis/modal.js Updated show-close property default value to 'true', mode to ['pc', 'mobile-first'], and added meta object with stable version 3.22.0
examples/sites/demos/pc/app/modal/*.vue Added show-close property to <tiny-modal> components, configured showClose in Modal.confirm method to false
examples/sites/demos/pc/app/modal/webdoc/modal.js Added documentation for new show-close property with default value true
packages/vue/src/modal/src/pc.vue Added showClose prop to control close button rendering in the modal

Possibly related PRs

Suggested reviewers

  • zzcr

Poem

🐰 A modal's dance, a button's grace,
Close or stay, at just the right pace.
With show-close now in sight,
Developers' control takes flight.
A rabbit's code, both smart and neat! 🎉


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fe2d3eb and 65f3eb6.

📒 Files selected for processing (1)
  • examples/sites/demos/apis/modal.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/sites/demos/apis/modal.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)

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 enhancement New feature or request (功能增强) label Jan 23, 2025
Copy link

Walkthrough

This pull request introduces a new feature to the modal component, allowing users to toggle the visibility of the close button. The default behavior is set to show the close button. The changes include updates to the demo examples and the core modal component to support this feature.

Changes

Files Summary
examples/sites/demos/apis/modal.js Updated to include metadata and demo configurations for the new feature.
examples/sites/demos/pc/app/modal/modal-other-composition-api.vue Added show-close attribute and showClose property to demonstrate the new feature.
examples/sites/demos/pc/app/modal/modal-other.vue Added show-close attribute and showClose property to demonstrate the new feature.
examples/sites/demos/pc/app/modal/webdoc/modal.js Documentation updated to describe the new show-close attribute.
packages/vue/src/modal/src/pc.vue Core modal component updated to conditionally render the close button based on the showClose property.

@@ -335,7 +335,11 @@ export default {
'zh-CN': '是否显示关闭按钮,默认值为 true',
'en-US': ''

Choose a reason for hiding this comment

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

The English description for the show-close feature is missing. Please ensure to provide a complete description for consistency across languages.

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

Test coverage needed for modal close button functionality

The codebase lacks proper test coverage for the close button feature. Please add tests for:

  • Default visibility of the close button (should be visible by default)
  • Hiding close button when showClose is set to false
  • Message type modal's default behavior (close button should be hidden)
  • Interaction between showClose and messageClosable props

Suggested test location: examples/sites/demos/pc/app/modal/modal-header.spec.ts

🔗 Analysis chain

Line range hint 92-222: Verify test coverage for the show-close feature.

The PR objectives mention that tests haven't been added. Please ensure test coverage for:

  1. Default behavior of the close button
  2. Hiding the close button when showClose is false
  3. Interaction between showClose and messageClosable props
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for existing tests and potential test locations
echo "Searching for modal test files..."
fd -e spec.js -e spec.ts -e test.js -e test.ts modal

echo "Checking test coverage in existing modal tests..."
rg -l "showClose|show-close" $(fd -e spec.js -e spec.ts -e test.js -e test.ts modal)

Length of output: 1781


Script:

#!/bin/bash
# Check content of relevant test files and implementation
echo "=== Modal Header Tests ==="
cat examples/sites/demos/pc/app/modal/modal-header.spec.ts

echo -e "\n=== Modal Other Tests ==="
cat examples/sites/demos/pc/app/modal/modal-other.spec.ts

echo -e "\n=== Modal Implementation ==="
rg -A 5 "showClose.*:" packages/vue/src/modal/

Length of output: 2324

🧹 Nitpick comments (2)
examples/sites/demos/pc/app/modal/modal-other-composition-api.vue (1)

19-19: LGTM! Consider documenting the show-close behavior.

The show-close prop is correctly implemented in the template-based modal.

Consider adding a comment to explain why the close button behavior differs between template-based and function-based modals in this demo.

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

215-222: Add ARIA attributes for better accessibility.

While the close button implementation is correct, consider adding ARIA attributes to improve accessibility.

     showClose
       ? h(iconClose(), {
           class: ['tiny-modal__close-btn', 'trigger__btn'],
+          attrs: {
+            'aria-label': t('ui.modal.close'),
+            role: 'button',
+            tabindex: '0'
+          },
           on: {
             click: this.closeEvent
           }
         })
       : null
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 05b7e6e and 98a251a.

📒 Files selected for processing (5)
  • examples/sites/demos/apis/modal.js (1 hunks)
  • examples/sites/demos/pc/app/modal/modal-other-composition-api.vue (2 hunks)
  • examples/sites/demos/pc/app/modal/modal-other.vue (2 hunks)
  • examples/sites/demos/pc/app/modal/webdoc/modal.js (1 hunks)
  • packages/vue/src/modal/src/pc.vue (3 hunks)
🔇 Additional comments (5)
examples/sites/demos/pc/app/modal/modal-other-composition-api.vue (1)

62-62: LGTM! Consistent with the feature implementation.

The showClose: false setting demonstrates the ability to hide the close button in function-based modals.

examples/sites/demos/pc/app/modal/modal-other.vue (1)

19-19: LGTM! Implementation matches the Composition API version.

The show-close feature is implemented consistently between the Options API and Composition API versions of the demo.

Also applies to: 66-66

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

206-207: LGTM! Documentation is clear and bilingual.

The show-close feature is well documented in both Chinese and English, with the default value correctly specified.

Also applies to: 212-213

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

338-342: LGTM! API definition is complete and properly versioned.

The show-close feature is:

  • Properly versioned with stable version 3.22.0
  • Correctly supported in both PC and mobile-first modes
  • Linked to the appropriate demo
packages/vue/src/modal/src/pc.vue (1)

92-104: LGTM! Clean destructuring of props.

The destructuring of the showClose prop alongside other modal properties is well-organized and follows the component's existing patterns.

Comment on lines +71 to +72
'slots',
'showClose'
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add type definition and default value for the showClose prop.

The new showClose prop should include type information and a default value for better maintainability and developer experience.

-    'slots',
-    'showClose'
+    'slots',
+    {
+      name: 'showClose',
+      type: Boolean,
+      default: true,
+      description: 'Controls the visibility of the modal close button'
+    }

Committable suggestion skipped: line range outside the PR's diff.

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/modal/modal-other.spec.ts (2)

5-5: Consider using more stable selectors for E2E tests.

The current CSS selector .tiny-modal__close-btn > .tiny-svg is tightly coupled to implementation details. Consider using more stable selectors like data-testid attributes or ARIA roles for better test maintainability.

-  const close = page.locator('.tiny-modal__close-btn >  .tiny-svg')
+  const close = page.locator('[data-testid="modal-close-button"]')

Line range hint 3-12: Consider internationalizing test descriptions and labels.

The test descriptions and button labels are in Chinese while the codebase appears to be in English. Consider using English for consistency or implementing proper i18n test utilities.

-test('弹窗其他特性', async ({ page }) => {
+test('modal other features', async ({ page }) => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 98a251a and fe2d3eb.

📒 Files selected for processing (1)
  • examples/sites/demos/pc/app/modal/modal-other.spec.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)

await page.goto('modal#modal-other')
await page.getByRole('button', { name: '弹窗 esc 关闭' }).first().click()
await expect(close).toBeHidden()
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance test coverage for show-close feature.

The test only verifies that the close button is hidden. Consider adding assertions to verify:

  1. The close button is initially visible when show-close is true
  2. The close button visibility toggles correctly with show-close prop changes

@James-9696 James-9696 changed the title feat(modal): [modal] the show-close feature is added feat(modal): [modal] add show-close feature Jan 24, 2025
@zzcr zzcr merged commit f80d683 into dev Jan 24, 2025
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request (功能增强)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants