Skip to content

fix(Stepper): correct disabled state when min/max are strings - #6090

Merged
rex-zsd merged 1 commit into
youzan:devfrom
Mosquito1123:fix/stepper-min-max-string-disabled
Oct 10, 2026
Merged

rex-zsd merged 1 commit into
youzan:devfrom
Mosquito1123:fix/stepper-min-max-string-disabled

Conversation

@Mosquito1123

Copy link
Copy Markdown
Contributor

问题

当 min/max 以字符串传入时(如 min="2" max="10",这也是本组件 demo 的用法),+ / - 按钮的禁用样式与实际点击逻辑不一致。

<van-stepper min="2" max="10" value="{{ 8 }}" />
- 期望:8 < 10,+ 可用
- 实际:+ 显示为禁用(置灰),但点击又能继续加
fix #6070
根因
packages/stepper/index.ts 的 isDisabled() 用 +value 做数值比较,是正确的:
// plus
return disabled || disablePlus || +currentValue >= +max;
// minus
return disabled || disableMinus || +currentValue <= +min;
但禁用样式是在 packages/stepper/index.wxml 里用裸比较单独算的:
<!-- before -->
disabled: disabled || disablePlus || currentValue >= max
currentValue 恒为字符串;当 min/max 是字符串字面量时,WXML 会走字符串字典序比较:"8" >= "10" 为真(比较首字符 "8" > "1"),于是 8 处被误判为已达上限。传数字(min="{{ 2 }}")时才会走数值比较,所以仅在字符串用法下复现。
修改
- packages/stepper/index.wxml:+ / - 的禁用判断改为数值比较(* 1),与 isDisabled() 语义保持一致
- disabled: disabled || disablePlus || currentValue >= max
+ disabled: disabled || disablePlus || currentValue * 1 >= max * 1
- packages/stepper/demo/index.wxml:新增回归用例 min="2" max="10" value="{{ 8 }}"
- packages/stepper/test/__snapshots__/demo.spec.ts.snap:同步更新快照
验证
- 全量测试通过:55 passed, 56 tests passed
- 回归用例有效性:还原 index.wxml 后,新用例立即失败,快照中 8 处出现 van-stepper__plus--disabled;修复后为 van-stepper__plus(无 --disabled)
- 边界:0、0.5 及数字型 min/max 的行为不变

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation consistently matches existing click logic and includes focused regression coverage.

0 open findings

What changed in this PR

Aligns Stepper button styling with its numeric min/max click logic when bounds are strings.

Changes:

  • Coerces bounds and current values to numbers in disabled-state comparisons.
  • Adds a string-bound demo regression case and updates its snapshot.
File Description
packages/​stepper/​index.wxml Fixes numeric disabled-state comparisons.
packages/​stepper/​demo/​index.wxml Adds the regression example.
packages/​stepper/​test/​__snapshots__/​demo.spec.ts.snap Verifies correct button styling.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@rex-zsd
rex-zsd merged commit 4df64a4 into youzan:dev Oct 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants