feat: indicator基础升级完成#3480
Conversation
Walkthrough新增 Indicator 的 placement 属性与定位样式支持;将 slide 模式位移计算暴露为 CSS 变量;补充样式变量与主题变量,新增 Demo7 演示并扩展中英/Taro 文档与单元测试覆盖。 ChangesIndicator 组件 placement 定位布局功能
Estimated code review effort 🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## feat_v4.x #3480 +/- ##
=============================================
+ Coverage 88.33% 88.42% +0.09%
=============================================
Files 295 295
Lines 19747 19727 -20
Branches 3117 3116 -1
=============================================
+ Hits 17443 17444 +1
+ Misses 2298 2277 -21
Partials 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/packages/indicator/indicator.tsx (1)
58-59: ⚡ Quick win建议提取滑块尺寸常量以提高可维护性。
硬编码的
trackWidth: 24和sliderWidth: 8与 SCSS 变量和文档一致,但如果将来这些值发生变化,需要在多个地方(包括 Taro 版本)同步更新。建议提取为命名常量或在文件顶部添加注释说明这些值与 CSS 变量的对应关系。♻️ 建议的重构
+// 与 SCSS $indicator-track-width 和 $indicator-slider-width 保持一致 +const SLIDE_TRACK_WIDTH = 24 +const SLIDE_SLIDER_WIDTH = 8 + const renderLineElement = () => { - const trackWidth: number = 24 - const sliderWidth: number = 8 + const trackWidth: number = SLIDE_TRACK_WIDTH + const sliderWidth: number = SLIDE_SLIDER_WIDTH const stride = (trackWidth - sliderWidth) / (total - 1)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/packages/indicator/indicator.tsx` around lines 58 - 59, Extract the hardcoded numeric values into named constants at the top of indicator.tsx (e.g., SLIDER_TRACK_WIDTH and SLIDER_HANDLE_WIDTH) and replace usages of trackWidth and sliderWidth with these constants; add a short comment above the constants noting the corresponding SCSS variable names and documentation reference so future changes stay in sync; ensure any other references (including Taro-specific copies) use these constants or are documented where they diverge.src/packages/indicator/indicator.taro.tsx (1)
63-64: ⚡ Quick win建议提取滑块尺寸常量以提高可维护性。
与 H5 版本相同,硬编码的
trackWidth: 24和sliderWidth: 8应提取为命名常量,以便与 H5 版本保持同步并提高可维护性。♻️ 建议的重构
+// 与 SCSS $indicator-track-width 和 $indicator-slider-width 保持一致 +const SLIDE_TRACK_WIDTH = 24 +const SLIDE_SLIDER_WIDTH = 8 + const renderLineElement = () => { - const trackWidth: number = 24 - const sliderWidth: number = 8 + const trackWidth: number = SLIDE_TRACK_WIDTH + const sliderWidth: number = SLIDE_SLIDER_WIDTH const stride = (trackWidth - sliderWidth) / (total - 1)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/packages/indicator/indicator.taro.tsx` around lines 63 - 64, Extract the hard-coded numeric values used for the slider into named constants (e.g., TRACK_WIDTH and SLIDER_WIDTH) instead of inline numbers; update the declarations that currently set trackWidth and sliderWidth in indicator.taro.tsx to reference these constants (and export them or import from a shared constants module if the H5 version uses the same names) so both versions share the same definitions and improve maintainability.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/types/spec/indicator/base.ts`:
- Line 18: The placement field is currently required but should be optional;
update the type declaration that defines placement (the property named placement
of type IndicatorPlacement) to be optional (add the ? modifier) so it reads as
an optional property, and ensure any related type/interface where placement
appears (the Indicator placement property in the indicator base type) reflects
this change to match the docs/default of "-".
---
Nitpick comments:
In `@src/packages/indicator/indicator.taro.tsx`:
- Around line 63-64: Extract the hard-coded numeric values used for the slider
into named constants (e.g., TRACK_WIDTH and SLIDER_WIDTH) instead of inline
numbers; update the declarations that currently set trackWidth and sliderWidth
in indicator.taro.tsx to reference these constants (and export them or import
from a shared constants module if the H5 version uses the same names) so both
versions share the same definitions and improve maintainability.
In `@src/packages/indicator/indicator.tsx`:
- Around line 58-59: Extract the hardcoded numeric values into named constants
at the top of indicator.tsx (e.g., SLIDER_TRACK_WIDTH and SLIDER_HANDLE_WIDTH)
and replace usages of trackWidth and sliderWidth with these constants; add a
short comment above the constants noting the corresponding SCSS variable names
and documentation reference so future changes stay in sync; ensure any other
references (including Taro-specific copies) use these constants or are
documented where they diverge.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4bc353c0-9f11-427c-9f24-6433689c0277
📒 Files selected for processing (16)
src/packages/indicator/__test__/indicator.spec.tsxsrc/packages/indicator/demo.taro.tsxsrc/packages/indicator/demo.tsxsrc/packages/indicator/demos/h5/demo7.tsxsrc/packages/indicator/demos/taro/demo7.tsxsrc/packages/indicator/doc.en-US.mdsrc/packages/indicator/doc.mdsrc/packages/indicator/doc.taro.mdsrc/packages/indicator/doc.zh-TW.mdsrc/packages/indicator/indicator.scsssrc/packages/indicator/indicator.taro.tsxsrc/packages/indicator/indicator.tsxsrc/styles/theme-dark.scsssrc/styles/theme-default.scsssrc/styles/variables.scsssrc/types/spec/indicator/base.ts
| direction: string | ||
| color: IndicatorColor | ||
| type: IndicatorType | ||
| placement: IndicatorPlacement |
There was a problem hiding this comment.
placement 字段应该是可选的。
根据文档和组件实现,placement 属性应该是可选的(文档中默认值为 -),但当前类型定义中没有 ? 修饰符,这会导致类型错误并可能破坏现有代码。
🔧 建议修复
export interface BaseIndicator extends BaseProps {
total: number
current: number
direction: string
color: IndicatorColor
type: IndicatorType
- placement: IndicatorPlacement
+ placement?: IndicatorPlacement
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/types/spec/indicator/base.ts` at line 18, The placement field is
currently required but should be optional; update the type declaration that
defines placement (the property named placement of type IndicatorPlacement) to
be optional (add the ? modifier) so it reads as an optional property, and ensure
any related type/interface where placement appears (the Indicator placement
property in the indicator base type) reflects this change to match the
docs/default of "-".
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/packages/indicator/indicator.scss`:
- Around line 200-208: The calc expression inside the &-active selector breaks
Stylelint rules by placing binary operators at the end of lines; reformat the
calc so operators start the wrapped lines (e.g., put the "/" and "-" at the
beginning of their respective continued lines) to match the horizontal-mode
formatting and satisfy Stylelint; update the expression that uses
var(--nutui-indicator-current), var(--nutui-indicator-total),
#{$indicator-track-width} and #{$indicator-slider-width} within transform:
translateY(calc(...)) accordingly.
- Around line 85-91: The SCSS calc expression inside transform: translateX
currently breaks lines immediately after the / and * operators which violates
scss/operator-no-newline-after; update the calc so the operators are not
followed by a newline (e.g., place the / and * at the end of the preceding lines
or put the whole calc on one line) for the expression that uses
var(--nutui-indicator-current, 0), var(--nutui-indicator-total, 2),
$indicator-track-width and $indicator-slider-width inside transform:
translateX(calc(...)) to satisfy the lint rule.
In `@src/packages/indicator/indicator.tsx`:
- Around line 60-65: indicator passes the raw total into the CSS variable
--nutui-indicator-total, which makes the calc in indicator.scss divide by (total
- 1) and produce NaN when total === 1; update the component (indicator.tsx /
indicator.taro.tsx) to clamp/protect BaseIndicator.total before assigning the
CSS var (e.g. compute a safeTotal = Math.max(total, 2) and set
'--nutui-indicator-total' to safeTotal) so the CSS denominator never becomes
zero; alternatively also consider a defensive CSS change (use
max(var(--nutui-indicator-total) - 1, 1)) but the primary fix is to ensure the
component sets a minimum total >= 2.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8a0eb9c6-cab6-4947-a7ef-1c31843e0060
📒 Files selected for processing (4)
src/packages/indicator/__test__/indicator.spec.tsxsrc/packages/indicator/indicator.scsssrc/packages/indicator/indicator.taro.tsxsrc/packages/indicator/indicator.tsx
| transform: translateX( | ||
| calc( | ||
| var(--nutui-indicator-current, 0) / | ||
| (var(--nutui-indicator-total, 2) - 1) * | ||
| (#{$indicator-track-width} - #{$indicator-slider-width}) | ||
| ) | ||
| ); |
There was a problem hiding this comment.
修复 SCSS 运算符换行格式问题。
Stylelint 检测到第 87 和 88 行在 / 与 * 运算符后存在换行,违反 scss/operator-no-newline-after 规则,可能导致 CI 失败。
🔧 建议的格式修复
transform: translateX(
calc(
- var(--nutui-indicator-current, 0) /
- (var(--nutui-indicator-total, 2) - 1) *
- (#{$indicator-track-width} - #{$indicator-slider-width})
+ var(--nutui-indicator-current, 0) / (var(--nutui-indicator-total, 2) - 1) * (#{$indicator-track-width} - #{$indicator-slider-width})
)
);📝 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.
| transform: translateX( | |
| calc( | |
| var(--nutui-indicator-current, 0) / | |
| (var(--nutui-indicator-total, 2) - 1) * | |
| (#{$indicator-track-width} - #{$indicator-slider-width}) | |
| ) | |
| ); | |
| transform: translateX( | |
| calc( | |
| var(--nutui-indicator-current, 0) / (var(--nutui-indicator-total, 2) - 1) * (#{$indicator-track-width} - #{$indicator-slider-width}) | |
| ) | |
| ); |
🧰 Tools
🪛 Stylelint (17.12.0)
[error] 87-87: Unexpected newline after "/" (scss/operator-no-newline-after)
(scss/operator-no-newline-after)
[error] 88-88: Unexpected newline after "*" (scss/operator-no-newline-after)
(scss/operator-no-newline-after)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/packages/indicator/indicator.scss` around lines 85 - 91, The SCSS calc
expression inside transform: translateX currently breaks lines immediately after
the / and * operators which violates scss/operator-no-newline-after; update the
calc so the operators are not followed by a newline (e.g., place the / and * at
the end of the preceding lines or put the whole calc on one line) for the
expression that uses var(--nutui-indicator-current, 0),
var(--nutui-indicator-total, 2), $indicator-track-width and
$indicator-slider-width inside transform: translateX(calc(...)) to satisfy the
lint rule.
Source: Linters/SAST tools
| &-active { | ||
| transform: translateY( | ||
| calc( | ||
| var(--nutui-indicator-current, 0) / | ||
| (var(--nutui-indicator-total, 2) - 1) * | ||
| (#{$indicator-track-width} - #{$indicator-slider-width}) | ||
| ) | ||
| ); | ||
| } |
There was a problem hiding this comment.
修复竖向模式的运算符换行格式问题。
与横向模式相同,第 203 和 204 行在运算符后存在换行,违反 Stylelint 规则。
🔧 建议的格式修复
&-active {
transform: translateY(
calc(
- var(--nutui-indicator-current, 0) /
- (var(--nutui-indicator-total, 2) - 1) *
- (#{$indicator-track-width} - #{$indicator-slider-width})
+ var(--nutui-indicator-current, 0) / (var(--nutui-indicator-total, 2) - 1) * (#{$indicator-track-width} - #{$indicator-slider-width})
)
);
}📝 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.
| &-active { | |
| transform: translateY( | |
| calc( | |
| var(--nutui-indicator-current, 0) / | |
| (var(--nutui-indicator-total, 2) - 1) * | |
| (#{$indicator-track-width} - #{$indicator-slider-width}) | |
| ) | |
| ); | |
| } | |
| &-active { | |
| transform: translateY( | |
| calc( | |
| var(--nutui-indicator-current, 0) / (var(--nutui-indicator-total, 2) - 1) * (#{$indicator-track-width} - #{$indicator-slider-width}) | |
| ) | |
| ); | |
| } |
🧰 Tools
🪛 Stylelint (17.12.0)
[error] 203-203: Unexpected newline after "/" (scss/operator-no-newline-after)
(scss/operator-no-newline-after)
[error] 204-204: Unexpected newline after "*" (scss/operator-no-newline-after)
(scss/operator-no-newline-after)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/packages/indicator/indicator.scss` around lines 200 - 208, The calc
expression inside the &-active selector breaks Stylelint rules by placing binary
operators at the end of lines; reformat the calc so operators start the wrapped
lines (e.g., put the "/" and "-" at the beginning of their respective continued
lines) to match the horizontal-mode formatting and satisfy Stylelint; update the
expression that uses var(--nutui-indicator-current),
var(--nutui-indicator-total), #{$indicator-track-width} and
#{$indicator-slider-width} within transform: translateY(calc(...)) accordingly.
Source: Linters/SAST tools
| style={ | ||
| { | ||
| '--nutui-indicator-current': current, | ||
| '--nutui-indicator-total': total, | ||
| } as React.CSSProperties | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# 检查是否有 total 最小值校验或相关文档
# 搜索 total 的验证逻辑
rg -n -C3 'total.*[>=<].*1' --type ts --type tsx
# 搜索文档中是否说明 total 最小值
rg -n 'total.*minimum|minimum.*total|total.*至少|至少.*total' --glob '*.md'Repository: jdf2e/nutui-react
Length of output: 89
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) 确认 indicator 相关文件
echo "=== indicator.tsx ==="
sed -n '1,140p' src/packages/indicator/indicator.tsx
# 2) 搜索 total 的校验/默认值/prop 类型
echo
echo "=== Search total validation/usage in indicator package ==="
rg -n --hidden --no-ignore-vcs "total" src/packages/indicator -S
# 3) 搜索 CSS 变量在样式中如何用于 calc(total - 1)
echo
echo "=== Search for nutui-indicator-total usage ==="
rg -n "nutui-indicator-total|indicator-total" -S src/packages/indicator
# 4) 在整个 repo 搜索 calc( ... - 1 ) 与 indicator 相关的写法
echo
echo "=== Search calc with total-1 near indicator ==="
rg -n "calc\\([^\\)]*\\-\\s*1\\)|\\(\\s*total\\s*\\-\\s*1\\s*\\)|total\\s*\\-\\s*1" -S src/packages/indicator src/packages -g'*.{scss,css,less,ts,tsx,js,jsx}'
# 5) 搜索文档/示例是否注明 total 最小值
echo
echo "=== Search docs for total minimum mention ==="
rg -n "total.*(最小|至少|min|minimum)|至少.*total|minimum.*total" --glob '*.md' -SRepository: jdf2e/nutui-react
Length of output: 8601
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) 确认 indicator 相关文件
echo "=== indicator.tsx ==="
sed -n '1,220p' src/packages/indicator/indicator.tsx
# 2) 搜索 total 的校验/默认值/prop 类型
echo
echo "=== Search total validation/usage in indicator package ==="
rg -n --hidden --no-ignore-vcs "total" src/packages/indicator -S
# 3) 搜索 CSS 变量在样式中如何用于 calc(total - 1)
echo
echo "=== Search for nutui-indicator-total usage ==="
rg -n "nutui-indicator-total|indicator-total" -S src/packages/indicator
# 4) 在整个 repo 搜索 calc( ... - 1 ) 与 indicator 相关的写法
echo
echo "=== Search calc with total-1 near indicator ==="
rg -n "calc\\([^\\)]*\\-\\s*1\\)|\\(\\s*total\\s*\\-\\s*1\\s*\\)|total\\s*\\-\\s*1" -S src/packages/indicator src/packages -g'*.{scss,css,less,ts,tsx,js,jsx}'
# 5) 搜索文档/示例是否注明 total 最小值
echo
echo "=== Search docs for total minimum mention ==="
rg -n "total.*(最小|至少|min|minimum)|至少.*total|minimum.*total|total\\s*>=\\s*1|total\\s*\\.?\\s*>=\\s*1" --glob '*.md' -SRepository: jdf2e/nutui-react
Length of output: 8601
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# 1) 确认 indicator 相关文件
echo "=== indicator.tsx ==="
sed -n '1,220p' src/packages/indicator/indicator.tsx
# 2) 搜索 total 的校验/默认值/prop 类型
echo
echo "=== Search total validation/usage in indicator package ==="
rg -n --hidden --no-ignore-vcs "total" src/packages/indicator -S
# 3) 搜索 CSS 变量在样式中如何用于 calc(total - 1)
echo
echo "=== Search for nutui-indicator-total usage ==="
rg -n "nutui-indicator-total|indicator-total" -S src/packages/indicator
# 4) 在整个 repo 搜索 calc( ... - 1 ) 与 indicator 相关的写法
echo
echo "=== Search calc with total-1 near indicator ==="
rg -n "calc\\([^\\)]*\\-\\s*1\\)|\\(\\s*total\\s*\\-\\s*1\\s*\\)|total\\s*\\-\\s*1" -S src/packages/indicator src/packages -g'*.{scss,css,less,ts,tsx,js,jsx}'
# 5) 搜索文档/示例是否注明 total 最小值
echo
echo "=== Search docs for total minimum mention ==="
rg -n "total.*(最小|至少|min|minimum)|至少.*total|minimum.*total|total\\s*>=\\s*1|total\\s*\\.?\\s*>=\\s*1" --glob '*.md' -SRepository: jdf2e/nutui-react
Length of output: 8601
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== indicator.tsx ==="
sed -n '1,220p' src/packages/indicator/indicator.tsx
echo
echo "=== Search total validation/usage in indicator package ==="
rg -n "total" src/packages/indicator -S
echo
echo "=== Search for nutui-indicator-total usage ==="
rg -n "nutui-indicator-total|indicator-total" src/packages/indicator -S
echo
echo "=== Search calc with total-1 near indicator ==="
rg -n "calc\\([^\\)]*\\-\\s*1\\)|\\(\\s*total\\s*\\-\\s*1\\s*\\)|total\\s*\\-\\s*1" -S src/packages/indicator src/packages -g'*.{scss,css,less,ts,tsx,js,jsx}'
echo
echo "=== Search docs for total minimum mention ==="
rg -n "total.*(最小|至少|min|minimum)|至少.*total|minimum.*total|total\\s*>=\\s*1|total\\s*\\.?\\s*>=\\s*1" --glob '*.md' -SRepository: jdf2e/nutui-react
Length of output: 8601
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== indicator.tsx ==="
sed -n '1,220p' src/packages/indicator/indicator.tsx
echo
echo "=== Search total validation/usage in indicator package ==="
rg -n "total" src/packages/indicator -S
echo
echo "=== Search for nutui-indicator-total usage ==="
rg -n "nutui-indicator-total|indicator-total" src/packages/indicator -S
echo
echo "=== Search calc with total-1 near indicator ==="
rg -n "calc\\([^\\)]*\\-\\s*1\\)|\\(\\s*total\\s*\\-\\s*1\\s*\\)|total\\s*\\-\\s*1" -S src/packages/indicator src/packages -g'*.{scss,css,less,ts,tsx,js,jsx}'
echo
echo "=== Search docs for total minimum mention ==="
rg -n "total.*(最小|至少|min|minimum)|至少.*total|minimum.*total|total\\s*>=\\s*1|total\\s*\\.?\\s*>=\\s*1" --glob '*.md' -SRepository: jdf2e/nutui-react
Length of output: 8601
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== indicator.scss (around line 70-110) ==="
sed -n '60,110p' src/packages/indicator/indicator.scss
echo
echo "=== indicator.scss (around line 180-240) ==="
sed -n '170,240p' src/packages/indicator/indicator.scss
echo
echo "=== indicator.taro.tsx (for parity) ==="
sed -n '1,120p' src/packages/indicator/indicator.taro.tsx
echo
echo "=== doc.md total prop description (around line 60-100) ==="
sed -n '60,100p' src/packages/indicator/doc.mdRepository: jdf2e/nutui-react
Length of output: 6040
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate WebIndicatorProps / TaroIndicatorProps definition
echo "=== Search for WebIndicatorProps definition ==="
rg -n "export (interface|type) WebIndicatorProps" -S src | head
echo
echo "=== Search for total in WebIndicatorProps ==="
rg -n "WebIndicatorProps|TaroIndicatorProps" -S src/types src | head -n 50
echo
echo "=== Search for TaroIndicatorProps definition ==="
rg -n "export (interface|type) TaroIndicatorProps" -S src | head
echo
echo "=== Search for runtime guard/clamp for total in indicator code ==="
rg -n "total\\s*(<=|>=|<|>|Math\\.|max\\(|min\\()" -S src/packages/indicator
echo
echo "=== Search for clamping total in entire repo ==="
rg -n "total\\s*(<=|>=|<|>|Math\\.|max\\(|min\\()" -S src | head -n 50Repository: jdf2e/nutui-react
Length of output: 1528
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== Search for BaseIndicator definition ==="
rg -n "BaseIndicator" src/types -S
echo
echo "=== Print files containing BaseIndicator (first matches) ==="
# Use rg to list likely file paths then show relevant sections
files=$(rg -l "BaseIndicator" src/types -S)
for f in $files; do
echo "--- $f ---"
sed -n '1,200p' "$f"
doneRepository: jdf2e/nutui-react
Length of output: 1437
total=1 时 slide 模式会导致 CSS calc 除零从而位移失效
indicator.tsx/indicator.taro.tsx 将 --nutui-indicator-total 直接设为 total,而 indicator.scss 中 transform: translateX/translateY(calc(var(--nutui-indicator-current) / (var(--nutui-indicator-total) - 1) * ...)) 的分母是 (total - 1):当 total={1} 时分母为 0,calc() 结果无效,可能出现视觉错误。BaseIndicator.total 仅为 number,代码/文档未见最小值约束。
建议在组件侧对 total 进行最小值保护(如 clamp 到 >= 2),或在 CSS 中用 max(var(--nutui-indicator-total) - 1, 1) 避免除零。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/packages/indicator/indicator.tsx` around lines 60 - 65, indicator passes
the raw total into the CSS variable --nutui-indicator-total, which makes the
calc in indicator.scss divide by (total - 1) and produce NaN when total === 1;
update the component (indicator.tsx / indicator.taro.tsx) to clamp/protect
BaseIndicator.total before assigning the CSS var (e.g. compute a safeTotal =
Math.max(total, 2) and set '--nutui-indicator-total' to safeTotal) so the CSS
denominator never becomes zero; alternatively also consider a defensive CSS
change (use max(var(--nutui-indicator-total) - 1, 1)) but the primary fix is to
ensure the component sets a minimum total >= 2.
|
辛苦关注下 ai 评审~ |

🤔 这个变动的性质是?
☑️ 请求合并前的自查清单
Summary by CodeRabbit
新功能
示例
文档
样式与主题
测试