Add the option to add item at the top of the list (#5270)

Co-authored-by: Bassea <andre.basse@spiegel.de>
This commit is contained in:
Andre Basse 2022-09-29 07:32:05 +02:00 committed by GitHub
parent c912b6aa23
commit fda1950583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -882,6 +882,7 @@ combo 还有一个作用是增加层级,比如返回的数据是一个深层
| joinValues | `boolean` | `true` | 默认为 `true` 当扁平化开启的时候,是否用分隔符的形式发送给后端,否则采用 array 的方式。 |
| delimiter | `string` | `false` | 当扁平化开启并且 joinValues 为 true 时,用什么分隔符。 |
| addable | `boolean` | `false` | 是否可新增 |
| addattop | `boolean` | `false` | 在顶部添加 |
| removable | `boolean` | `false` | 是否可删除 |
| deleteApi | [API](../../../docs/types/api) | | 如果配置了,则删除前会发送一个 api请求成功才完成删除 |
| deleteConfirmText | `string` | `"确认要删除?"` | 当配置 `deleteApi` 才生效!删除时用来做用户确认 |

View File

@ -117,6 +117,11 @@ export interface ComboControlSchema extends FormBaseControlSchema {
*/
addable?: boolean;
/**
* Add at top
*/
addattop?: boolean;
/**
*
*/
@ -459,7 +464,7 @@ export default class ComboControl extends React.Component<ComboProps> {
}
addItemWith(condition: ComboCondition) {
const {flat, joinValues, delimiter, scaffold, disabled, submitOnChange} =
const {flat, joinValues, addattop, delimiter, scaffold, disabled, submitOnChange} =
this.props;
if (disabled) {
@ -481,6 +486,10 @@ export default class ComboControl extends React.Component<ComboProps> {
value = value.join(delimiter || ',');
}
if (addattop === true){
value.unshift(value.pop());
}
this.props.onChange(value, submitOnChange, true);
}
@ -488,6 +497,7 @@ export default class ComboControl extends React.Component<ComboProps> {
const {
flat,
joinValues,
addattop,
delimiter,
scaffold,
disabled,
@ -527,6 +537,10 @@ export default class ComboControl extends React.Component<ComboProps> {
value = value.join(delimiter || ',');
}
if (addattop === true){
value.unshift(value.pop());
}
this.props.onChange(value, submitOnChange, true);
}