8000 feat(form:select,cascader,tree-select): default value when cleared (#… · ng-alain/delon@655806d · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Commit 655806d

Browse files
authored
feat(form:select,cascader,tree-select): default value when cleared (#1844)
1 parent 8f9e5c0 commit 655806d

File tree

13 files changed

+28
-7
lines changed

13 files changed

+28
-7
lines changed

packages/form/src/widgets/select/index.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Select.
2626
| `[placeholder]` | Placeholder | `string` | - |
2727
| `[autoClearSearchValue]` | Whether clear search box when an option is selected, only valid when `mode` is `multiple` or `tags`. | `boolean` | `true` |
2828
| `[allowClear]` | Allow clear | `boolean` | `false` |
29+
| `[clearValue]` | Default value when cleared | `any` | `undefined` |
2930
| `[borderless]` | Whether has border | `boolean` | `false` |
3031
| `[autoFocus]` | Focused by default | `boolean` | `false` |
3132
| `[dropdownClassName]` | className property of dropdown list | `string` | - |

packages/form/src/widgets/select/index.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ order: 6
2626
| `[placeholder]` | 在文字框中显示提示讯息 | `string` | - |
2727
| `[autoClearSearchValue]` | 是否在选中项后清空搜索框,只在 `mode``multiple``tags` 时有效。 | `boolean` | `true` |
2828
| `[allowClear]` | 支持清除 | `boolean` | `false` |
29+
| `[clearValue]` | 清空时默认值 | `any` | `undefined` |
2930
| `[borderless]` | 是否无边框 | `boolean` | `false` |
3031
| `[autoFocus]` | 默认获取焦点 | `boolean` | `false` |
3132
| `[dropdownClassName]` | 下拉菜单的 className 属性 | `string` | - |

packages/form/src/widgets/select/schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ export interface SFSelectWidgetSchema extends SFUISchemaItem {
132132
*/
133133
clearIcon?: TemplateRef<NzSafeAny>;
134134

135+
/**
136+
* 清空时默认值,默认:`undefined`
137+
*/
138+
clearValue?: NzSafeAny;
139+
135140
/**
136141
* 自定义当前选中的条目图标
137142
*/

packages/form/src/widgets/select/select.widget.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ describe('form: widget: select', () => {
140140
default: 1,
141141
ui: {
142142
widget,
143-
allowClear: true
144-
}
143+
allowClear: true,
144+
clearValue: 2
145+
} as SFSelectWidgetSchema
145146
}
146147
}
147148
};
@@ -151,7 +152,7 @@ describe('form: widget: select', () => {
151152
.time()
152153
.typeEvent('click', '.ant-select-close-icon')
153154
.time()
154-
.checkValue('/a', undefined)
155+
.checkValue('/a', 2)
155156
.asyncEnd();
156157
}));
157158

packages/form/src/widgets/select/select.widget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class SelectWidget extends ControlUIWidget<SFSelectWidgetSchema> implemen
161161
if (this.ui.change) {
162162
this.ui.change(values, this.getOrgData(values));
163163
}
164-
this.setValue(values == null ? undefined : values);
164+
this.setValue(values == null ? this.ui.clearValue : values);
165165
}
166166

167167
private getOrgData(values: SFValue): SFSchemaEnum | SFSchemaEnum[] {

packages/form/widgets/cascader/index.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Every select triggers a HTTP request, data source is from `asyncData`; includes
4242
| `[placeholder]` | Placeholder | `string` | - |
4343
| `[showSearch]` | Whether support search | `bool` | `false` |
4444
| `[allowClear]` | Whether show clear button | `bool` | `true` |
45+
| `[clearValue]` | Default value when cleared | `any` | `undefined` |
4546
| `[clearText]` | Title of clear button | `string` | `清除` |
4647
| `[showArrow]` | Whether show arrow | `bool` | `true` |
4748
| `[showInput]` | Whether show input | `bool` | `true` |

packages/form/widgets/cascader/index.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type: Non-built-in widgets
4242
| `[placeholder]` | 在文字框中显示提示讯息 | `string` | - |
4343
| `[showSearch]` | 是否支持搜索 | `bool` | `false` |
4444
| `[allowClear]` | 是否显示清除按钮 | `bool` | `true` |
45+
| `[clearValue]` | 清空时默认值 | `any` | `undefined` |
4546
| `[clearText]` | 清除按钮的标题 | `string` | `清除` |
4647
| `[showArrow]` | 是否显示箭头 | `bool` | `true` |
4748
| `[showInput]` | 是否显示输入框 | `bool` | `true` |

packages/form/widgets/cascader/schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export interface SFCascaderWidgetSchema extends SFUISchemaItem {
2424
*/
2525
allowClear?: boolean;
2626

27+
/**
28+
* 清空时默认值,默认:`undefined`
29+
*/
30+
clearValue?: NzSafeAny;
31+
2732
/**
2833
* 清除按钮的标题,默认:`清除`
2934
*/

packages/form/widgets/cascader/widget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class CascaderWidget extends ControlUIWidget<SFCascaderWidgetSchema> impl
8383
}
8484

8585
_change(value: NzSafeAny[] | null): void {
86-
this.setValue(value);
86+
this.setValue(value == null ? this.ui.clearValue : value);
8787
if (this.ui.change) {
8888
this.ui.change(value);
8989
}

packages/form/widgets/tree-select/index.en-US.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Non-built-in modules need to additionally register `withTreeSelectWidget` in [js
3232
| `[placeholder]` | Placeholder | `string` | - |
3333
| `[notFoundContent]` | Text to display when a column is empty | `string` | - |
3434
| `[allowClear]` | Whether show clear button | `boolean` | `false` |
35+
| `[clearValue]` | Default value when cleared | `any` | `undefined` |
3536
| `[dropdownMatchSelectWidth]` | Determine whether the dropdown menu and the select input are the same width | `boolean` | `true` |
3637
| `[dropdownStyle]` | Set the style of the dropdown menu | `object` | - |
3738
| `[dropdownClassName]` | Set className of the dropdown menu | `string` | - |

0 commit comments

Comments
 (0)
0