Skip to content

Conversation

@gausszhou
Copy link
Contributor

@gausszhou gausszhou commented Dec 18, 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?

modal 组件在 alert, confirm 的弹窗场景下 top 属性不生效

Issue Number: N/A

What is the new behavior?

modal 组件在 alert, confirm 的弹窗场景下 top 属性生效

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

此改动会影响初始值从 15vh 变为 80px

Summary by CodeRabbit

  • New Features

    • top positioning now applies to alert and confirm modal types and is supported with unit-aware values.
  • Bug Fixes

    • Default top value formatted to include units (e.g., "80px") to ensure consistent positioning.
  • Documentation

    • Updated modal docs and demo labels/descriptions to clarify modal top-position behavior and examples.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions bot added the bug Something isn't working label Dec 18, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 18, 2025

Walkthrough

Generalizes the modal top positioning from message-only to modal-wide: updates API docs, demo entries and demo component to show multiple modal types with different top values, and adds top computation to the renderless modal style logic.

Changes

Cohort / File(s) Change Summary
API Documentation Updates
examples/sites/demos/apis/modal.js
Changed top prop defaultValue from '80' to '80px'; updated zh-CN and en-US descriptions from message-specific to a general modal-top description.
Demo Metadata
examples/sites/demos/pc/app/modal/webdoc/modal.js
Updated demo entry text: Chinese name and descriptions now refer to modal-top positioning instead of message-only wording.
Demo Component
examples/sites/demos/pc/app/modal/message-top.vue
Replaced one button/handler with three buttons and handlers (btnClick1, btnClick2, btnClick3) demonstrating top usage for alert (300), confirm ('50vh'), and message (500) cases; removed original btnClick.
Core Renderless Logic
packages/renderless/src/modal/index.ts
computedBoxStyle now computes a top value (formatted with px when numeric) for alert and confirm types and includes top in the returned style object.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review packages/renderless/src/modal/index.ts for correct conditional application of top (types, units, and side effects on existing style merging).
  • Verify examples/sites/demos/pc/app/modal/message-top.vue handlers pass top values correctly and the template wiring matches.
  • Confirm documentation updates (examples/sites/demos/apis/modal.js, webdoc/modal.js) reflect actual runtime behavior and default formats.

Poem

🐰
Three tiny hops where one button stood,
I nudged the top to look quite good.
Alerts at three-hundred, confirms at half-view,
Messages bounce at five-hundred too.
A rabbit cheers: position, woo-hoo! 🎉

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main bug fix: enabling the top property for alert and confirm modal scenarios, which aligns with the core changes in the renderless modal logic and demo implementations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/renderless/src/modal/index.ts (1)

57-81: Fix the return type signature to include top.

The function return type on line 59 is missing the top property, but line 80 returns an object containing top. This creates a TypeScript type mismatch.

🔎 Apply this diff to fix the return type:
 export const computedBoxStyle =
   ({ props, isMobileFirstMode }: Pick<IModalRenderlessParams, 'props' | 'isMobileFirstMode'>) =>
-  (): { width?: string | number; height?: string | number } => {
+  (): { top?: string; width?: string | number; height?: string | number } => {
     if (isMobileFirstMode) {
       return {}
     }
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 851cab3 and 1e246e8.

📒 Files selected for processing (4)
  • examples/sites/demos/apis/modal.js (1 hunks)
  • examples/sites/demos/pc/app/modal/message-top.vue (2 hunks)
  • examples/sites/demos/pc/app/modal/webdoc/modal.js (1 hunks)
  • packages/renderless/src/modal/index.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: PR Unit Test
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (4)
packages/renderless/src/modal/index.ts (1)

64-70: LGTM! The top positioning logic is correctly implemented.

The logic properly computes the top style for 'alert' and 'confirm' modal types, handling both numeric and string values, which successfully extends the feature beyond 'message' type modals.

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

382-382: Good improvement adding explicit unit to default value.

Changing the default from '80' to '80px' improves clarity and consistency.

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

304-308: LGTM! Documentation correctly reflects the broader applicability.

The Chinese label and description have been properly updated from message-specific ("消息距离顶部位置") to general modal positioning ("模态框距离顶部位置"), aligning with the expanded feature scope.

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

19-39: Excellent demo coverage across modal types and value formats.

The three handlers effectively demonstrate the top property working across all modal types (alert, confirm, message) with both numeric pixel values and CSS units (vh), providing comprehensive validation of the fix.

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 (1)
packages/renderless/src/modal/index.ts (1)

57-81: LGTM! Core logic correctly implements top positioning for alert/confirm modals.

The implementation properly:

  • Checks for 'alert' or 'confirm' types
  • Formats numeric values with 'px' suffix
  • Preserves string values like '50vh' as-is
  • Updates the return type signature appropriately

The logic aligns well with the existing width and height handling patterns.

Optional: Consider only including `top` in the return object when it's actually set

Currently, an empty string is returned for top when the type is not 'alert' or 'confirm'. While this matches the existing pattern for width and height, you could make the return more explicit:

-    return { top, width, height }
+    const style: { top?: string; width?: string | number; height?: string | number } = {}
+    if (top) style.top = top
+    if (width) style.width = width  
+    if (height) style.height = height
+    return style

This ensures only defined values are included in the returned style object.

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e246e8 and 9954caa.

📒 Files selected for processing (4)
  • examples/sites/demos/apis/modal.js (1 hunks)
  • examples/sites/demos/pc/app/modal/message-top.vue (2 hunks)
  • examples/sites/demos/pc/app/modal/webdoc/modal.js (1 hunks)
  • packages/renderless/src/modal/index.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (3)
examples/sites/demos/pc/app/modal/webdoc/modal.js (1)

302-312: Documentation update correctly reflects the expanded scope of the top property.

The Chinese name and description changes appropriately generalize from message-specific ("消息距离顶部位置") to modal-wide ("模态框距离顶部位置") positioning, aligning with the code changes that extend top support to alert and confirm modal types.

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

384-385: Description updates correctly reflect modal-wide positioning.

The updated descriptions appropriately generalize the top property from message-specific to modal-wide positioning, consistent with the code changes.

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

1-42: Excellent demo implementation showcasing the expanded top property functionality.

The three handlers effectively demonstrate:

  1. Alert modal with top: 300 (numeric, new functionality)
  2. Confirm modal with top: '50vh' (string with viewport units, new functionality)
  3. Message modal with top: 500 (existing functionality preserved)

This comprehensively covers both the new alert/confirm support and various value formats (number, string with units), making it clear to developers how the top property now works across all modal types.

name: 'top',
type: 'number | string',
defaultValue: '80',
defaultValue: '80px',
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find the modal.js file and examine the top property default value
find . -name "modal.js" -type f 2>/dev/null | head -20

Repository: opentiny/tiny-vue

Length of output: 211


🏁 Script executed:

#!/bin/bash
# Read the modal.js file around line 382
sed -n '375,390p' ./examples/sites/demos/apis/modal.js

# Also search for where the top property is defined in Modal component
grep -n "top.*default" ./examples/sites/demos/apis/modal.js | head -20

Repository: opentiny/tiny-vue

Length of output: 499


🏁 Script executed:

#!/bin/bash
# Search for the Modal component's top prop definition in the source code
find . -path ./node_modules -prune -o -name "index.ts" -type f -print | xargs grep -l "computedBoxStyle" 2>/dev/null | head -5

# Also search for Modal component files
find . -path ./node_modules -prune -o -name "*modal*" -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.vue" \) -print | grep -E "src|packages" | head -20

Repository: opentiny/tiny-vue

Length of output: 193


🏁 Script executed:

#!/bin/bash
# Read the computedBoxStyle function in modal index.ts
sed -n '60,90p' ./packages/renderless/src/modal/index.ts

# Also search for the complete computedBoxStyle function
grep -n "computedBoxStyle" ./packages/renderless/src/modal/index.ts

# Get more context around that area
sed -n '1,120p' ./packages/renderless/src/modal/index.ts | tail -80

Repository: opentiny/tiny-vue

Length of output: 2936


🏁 Script executed:

#!/bin/bash
# Search for the Modal component props definition to find the actual default value for 'top'
find . -path ./node_modules -prune -o -path ./packages/renderless -prune -o -name "*modal*" -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.vue" \) -print | xargs grep -l "top.*default" 2>/dev/null | head -10

# Also check the Modal type definitions
grep -n "top" ./packages/renderless/types/modal.type.ts | head -20

Repository: opentiny/tiny-vue

Length of output: 325


🏁 Script executed:

#!/bin/bash
# Find the actual Modal component implementation with prop defaults
find ./packages -name "*modal*" \( -name "*.ts" -o -name "*.tsx" -o -name "*.vue" \) -type f | xargs grep -l "props.*top" 2>/dev/null | head -10

# Also check Vue component definition files
find ./packages/vue/src/modal -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.vue" \) | xargs cat 2>/dev/null | head -200

Repository: opentiny/tiny-vue

Length of output: 5062


🏁 Script executed:

#!/bin/bash
# Look for the Modal component's props definition more specifically
find ./packages/vue/src/modal -name "*.vue" -o -name "*.ts" -o -name "*.tsx" | xargs grep -l "top" 2>/dev/null

# Check the main Modal component file
ls -la ./packages/vue/src/modal/

# Read the main Modal component
cat ./packages/vue/src/modal/src/modal.tsx 2>/dev/null | head -150

Repository: opentiny/tiny-vue

Length of output: 586


🏁 Script executed:

#!/bin/bash
# Read the Modal component index.ts to find props definition
cat ./packages/vue/src/modal/src/index.ts

# Also check the pc.vue component
head -100 ./packages/vue/src/modal/src/pc.vue

Repository: opentiny/tiny-vue

Length of output: 5472


🏁 Script executed:

#!/bin/bash
# Verify the exact prop default for top and check how it's rendered
grep -A 1 "top:" ./packages/vue/src/modal/src/index.ts

# Also check if there are any comments about this in the computedBoxStyle
sed -n '55,90p' ./packages/renderless/src/modal/index.ts

Repository: opentiny/tiny-vue

Length of output: 1112


Correct the documentation for the top property default value.

The top property default is a number 80 (not the string '80px'). The computedBoxStyle function in packages/renderless/src/modal/index.ts automatically converts numeric values to strings with the 'px' suffix for alert and confirm modal types. Update the defaultValue in the documentation from '80px' to 80 and add a note explaining that the suffix is automatically appended.

🤖 Prompt for AI Agents
In examples/sites/demos/apis/modal.js around line 382, update the documented
default for the `top` property from the string '80px' to the number 80 and add a
brief note that the renderless computedBoxStyle function will automatically
append the 'px' suffix for alert/confirm modal types; change the defaultValue to
80 and include a one-line comment or note indicating the px suffix is appended
automatically.

@zzcr
Copy link
Member

zzcr commented Dec 19, 2025

你好,E2E测试没过,看下哈

@Issues-translate-bot
Copy link

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


Hello, I haven’t passed the E2E test. Let’s take a look.

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