Skip to content

Commit

Permalink
fix(form): Digit support stringMode
Browse files Browse the repository at this point in the history
close #8553
  • Loading branch information
chenshuai2144 committed Jul 12, 2024
1 parent d797fa7 commit 5075113
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/field/src/components/Digit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ const FieldDigit: ProFieldFC<FieldDigitProps> = (
...fractionDigits,
...(fieldProps?.intlProps || {}),
}).format(Number(text) as number);
const dom = (

// 如果是 string 模式,什么都不要处理了
const dom = !fieldProps?.stringMode ? (
<span ref={ref}>{fieldProps?.formatter?.(digit) || digit}</span>
) : (
<span>{text}</span>
);

if (render) {
return render(text, { mode: type, ...fieldProps }, dom);
}
Expand Down
42 changes: 42 additions & 0 deletions packages/form/src/components/FieldSet/demos/components-other.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ProForm,
ProFormCascader,
ProFormCheckbox,
ProFormColorPicker,
ProFormDigit,
Expand Down Expand Up @@ -171,6 +172,47 @@ const Demo = () => {
},
]}
/>
<ProFormCascader
label="地址"
request={async () => [
{
value: 'zhejiang',
label: '浙江',
children: [
{
value: 'hangzhou',
label: '杭州',
children: [
{
value: 'xihu',
label: '西湖',
},
],
},
],
},
{
value: 'jiangsu',
label: 'Jiangsu',
children: [
{
value: 'nanjing',
label: 'Nanjing',
children: [
{
value: 'zhonghuamen',
label: 'Zhong Hua Men',
},
],
},
],
},
]}
fieldProps={{
changeOnSelect: true,
}}
name="area"
/>

<ProFormRadio.Group
name="radio"
Expand Down
94 changes: 94 additions & 0 deletions tests/form/__snapshots__/demo.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2605,6 +2605,100 @@ exports[`form demos > 📸 renders ./packages/form/src/components/FieldSet/demos
</div>
</div>
</div>
<div
class="ant-space-item"
>
<div
class="ant-form-item"
>
<div
class="ant-row ant-form-item-row"
>
<div
class="ant-col ant-form-item-label"
>
<label
class=""
for="validate_other_area"
title="地址"
>
地址
</label>
</div>
<div
class="ant-col ant-form-item-control"
>
<div
class="ant-form-item-control-input"
>
<div
class="ant-form-item-control-input-content"
>
<div
class="ant-select ant-cascader ant-select-outlined ant-select-in-form-item ant-pro-field-cascader ant-select-single ant-select-allow-clear ant-select-show-arrow"
>
<div
class="ant-select-selector"
>
<span
class="ant-select-selection-search"
>
<input
aria-autocomplete="list"
aria-controls="validate_other_area_list"
aria-expanded="false"
aria-haspopup="listbox"
aria-owns="validate_other_area_list"
autocomplete="off"
class="ant-select-selection-search-input"
id="validate_other_area"
readonly=""
role="combobox"
style="opacity: 0;"
type="search"
unselectable="on"
value=""
/>
</span>
<span
class="ant-select-selection-placeholder"
>
请选择
</span>
</div>
<span
aria-hidden="true"
class="ant-select-arrow"
style="user-select: none;"
unselectable="on"
>
<span
aria-label="down"
class="anticon anticon-down ant-select-suffix"
role="img"
>
<svg
aria-hidden="true"
data-icon="down"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"
/>
</svg>
</span>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div
class="ant-space-item"
>
Expand Down

0 comments on commit 5075113

Please sign in to comment.