Skip to content

feat(BootstrapInputCurrency):add Currency support component - #8443

Open
Tony-ST0754 wants to merge 6 commits into
mainfrom
test-InputNumber-Support-currency-format
Open

feat(BootstrapInputCurrency):add Currency support component#8443
Tony-ST0754 wants to merge 6 commits into
mainfrom
test-InputNumber-Support-currency-format

Conversation

@Tony-ST0754

@Tony-ST0754 Tony-ST0754 commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Link issues

fixes #8442 #8444

根本原因

目前InputNumber组件,虽提供了Formatter回调,但由于组件最终还是会在Web里面了生成相应的Html元素,因此,采用了Input元素,且使用了type="number"这个类型,因此,不管怎么格式化,最终由于Html标准的限制导致格式化的内容无法按期望(用户)设定的显示

解决方案

新增InputCurrency组件,专门用于输入数值后进行格式化显示的组件

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Introduce culture-aware currency and formatted numeric input support through a new BootstrapInputCurrency component.

New Features:

  • Add a generic BootstrapInputCurrency component for culture-aware numeric entry, formatting, parsing, custom formatters, and value bounds.
  • Add an InputCurrency documentation/demo page covering currencies, percentages, cultures, custom formatting, and ranges.

Enhancements:

  • Extend generic string-to-value conversion with culture-aware support for numeric, nullable, boolean, and other bindable types.

Documentation:

  • Add localization and documentation metadata for the InputCurrency component.

Tests:

  • Add comprehensive component tests for formatting, parsing, culture handling, validation, bounds, nullable values, input events, and callbacks.
  • Add conversion tests covering numeric boundaries, precision, nullable values, cultures, and non-numeric types.

refactor:支持数字格式化显示,例如:$123,252.12
feat:增加文化信息参数
feat:增加Parser,以便与Formatter成配套使用;即Formatter可以输出任意格式,Parser负责反向
@sourcery-ai

sourcery-ai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

该 PR 通过以 inputmode="decimal" 替代 type="number",解除浏览器原生数字输入对格式化文本的限制;同时引入 CultureInfo 和 Parser,使 InputNumber 支持区域化默认转换及 Formatter 输出的自定义逆向解析,并补充转换、组件交互和筛选器测试。

Sequence diagram for formatted InputNumber parsing

sequenceDiagram
    participant User
    participant InputNumber
    participant Parser
    participant Converter

    User->>InputNumber: Enter formatted value
    alt Parser is configured
        InputNumber->>Parser: Parser(value, CultureInfo)
        Parser-->>InputNumber: Success, parsed TValue
    else Default conversion
        InputNumber->>Converter: TryConvertTo(value, CultureInfo)
        Converter-->>InputNumber: Success, parsed TValue
    end
    InputNumber-->>User: Update numeric Value or show validation error
Loading

File-Level Changes

Change Details Files
支持按指定文化格式化和解析数字,并允许自定义格式化结果的逆向解析。
  • 新增 CultureInfo 参数并将其用于默认数值转换。
  • 新增 Parser 回调,在输入值转换时优先处理自定义格式;未配置时保留默认转换。
  • 扩展字符串到数值类型的文化感知转换,覆盖可空数值、边界值、货币和区域格式。
src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor.cs
src/BootstrapBlazor/Extensions/ObjectExtensions.cs
test/UnitTest/Components/InputNumberTest.cs
test/UnitTest/Extensions/ObjectExtensionsTest.cs
调整 InputNumber 的 HTML 输入行为,使格式化文本可正常显示并在移动端仍提供数字键盘。
  • 移除 input 的 type="number",改用 inputmode="decimal"。
  • 同步更新表格数字筛选测试的元素选择器。
src/BootstrapBlazor/Components/InputNumber/BootstrapInputNumber.razor
test/UnitTest/Components/TableNumberFilterTest.cs
更新示例以演示文化格式化和自定义解析功能。
  • 使用 en-US 货币格式和百分比格式示例。
  • 为对应格式化示例配置 Parser,并调整示例绑定类型。
  • 注释掉多个原有演示区块以突出新功能。
src/BootstrapBlazor.Server/Components/Samples/InputNumbers.razor
src/BootstrapBlazor.Server/Components/Samples/InputNumbers.razor.cs
放宽示例服务器配置中的数值精度设置。
  • 将 Float、Double 和 Decimal 的精度配置从固定小数位改为 any。
src/BootstrapBlazor.Server/appsettings.json

Assessment against linked issues

Issue Objective Addressed Explanation
#8442 增强 InputNumber 的数字格式化显示能力,使格式化后的文本能够在输入框中按用户指定格式显示,同时保持组件内部值为原始数值。
#8442 支持通过 CultureInfo 按不同文化解析和处理数字,例如 zh-CN、de-DE 和 en-US 的千位分隔符、小数点及货币格式。
#8442 支持 Parser 回调将 Formatter 输出的自定义文本逆向解析为组件内部数值,并通过 inputmode="decimal" 替代 type="number" 以允许格式化文本显示并保留移动端数字键盘体验。

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/BootstrapBlazor.Server/appsettings.json" line_range="53-55" />
<code_context>
-      "Float": "0.1",
-      "Double": "0.01",
-      "Decimal": "0.01"
+      "Float": "any",
+      "Double": "any",
+      "Decimal": "any"
     },
     "ConnectionHubOptions": {
</code_context>
<issue_to_address>
**issue (bug_risk):** The sample application's default Float, Double, and Decimal step values are changed to `any`, but `BootstrapInputNumber.GetStepString()` converts `any` to `1` for its increment/decrement logic. Decimal inputs using the configured defaults therefore increment by whole integers instead of their previous fractional steps.

**Triggers:** When a floating-point or decimal InputNumber uses the sample application's default StepSettings and ShowButton is enabled.

**Suggested fix:** Keep the fractional defaults, or handle `any` separately in the button calculation instead of converting it to `1`.
</issue_to_address>

### Comment 2
<location path="src/BootstrapBlazor.Server/Components/Samples/InputNumbers.razor" line_range="8-11" />
<code_context>
 <h4>@Localizer["InputNumbersDescription"]</h4>

-<DemoBlock Title="@Localizer["InputNumbersNormalTitle"]"
+@* <DemoBlock Title="@Localizer["InputNumbersNormalTitle"]"
            Introduction="@Localizer["InputNumbersNormalIntro"]"
            Name="Normal">
</code_context>
<issue_to_address>
**nitpick:** The PR comments out the normal, ShowButton, Step, and Disabled InputNumber demo blocks, so the public sample page no longer demonstrates those existing component behaviors and their associated localized descriptions.

**Triggers:** When users visit the InputNumber documentation/sample page.

**Suggested fix:** Keep the existing examples enabled and add separate formatting examples for the new Formatter, Parser, and CultureInfo behavior.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and this changes shared numeric parsing and formatting behavior, including culture-specific conversion and custom parsers, so an incorrect parse could submit a wrong numeric value to a consuming application. Reverting restores the old behavior, but values already accepted and stored downstream would need to be identified and repaired.

Blocking findings: src/BootstrapBlazor.Server/appsettings.json:55


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/BootstrapBlazor.Server/appsettings.json Outdated
Comment thread src/BootstrapBlazor.Server/Components/Samples/InputNumbers.razor Outdated
@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (95776d1) to head (1ec833f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #8443    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          772       776     +4     
  Lines        34798     35167   +369     
==========================================
+ Hits         34798     35167   +369     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ArgoZhang ArgoZhang self-assigned this Sep 5, 2026
@ArgoZhang ArgoZhang added the enhancement New feature or request label Sep 5, 2026
@ArgoZhang ArgoZhang added this to the v10.10.0 milestone Sep 5, 2026
feat:新增InputCurrency组件,输入数值后进行格式化显示的组件
doc:新增InputCurrency组件对应文档
test:补充组件单元测试
@Tony-ST0754 Tony-ST0754 changed the title feat(InputNumber):增强组件数字格式化显示功能 feat(BootstrapInputCurrency):add Currency support component Sep 6, 2026
refactor:重构数据清洗标准化逻辑

test:调整单元测试

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

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.

feat(InputNumber): 增强组件数字格式化显示功能

2 participants