feat(Dialog): allow to disable confirm or cancel button (#10665)

This commit is contained in:
neverland 2022-06-04 20:19:19 +08:00 committed by GitHub
parent 0dc09cab8c
commit 4a602f7e46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 46 additions and 1 deletions

View File

@ -56,8 +56,10 @@ const dialogProps = extend({}, popupSharedProps, {
showCancelButton: Boolean, showCancelButton: Boolean,
cancelButtonText: String, cancelButtonText: String,
cancelButtonColor: String, cancelButtonColor: String,
cancelButtonDisabled: Boolean,
confirmButtonText: String, confirmButtonText: String,
confirmButtonColor: String, confirmButtonColor: String,
confirmButtonDisabled: Boolean,
showConfirmButton: truthProp, showConfirmButton: truthProp,
closeOnClickOverlay: Boolean, closeOnClickOverlay: Boolean,
}); });
@ -197,6 +199,7 @@ export default defineComponent({
class={bem('cancel')} class={bem('cancel')}
style={{ color: props.cancelButtonColor }} style={{ color: props.cancelButtonColor }}
loading={loading.cancel} loading={loading.cancel}
disabled={props.cancelButtonDisabled}
onClick={onCancel} onClick={onCancel}
/> />
)} )}
@ -207,6 +210,7 @@ export default defineComponent({
class={[bem('confirm'), { [BORDER_LEFT]: props.showCancelButton }]} class={[bem('confirm'), { [BORDER_LEFT]: props.showCancelButton }]}
style={{ color: props.confirmButtonColor }} style={{ color: props.confirmButtonColor }}
loading={loading.confirm} loading={loading.confirm}
disabled={props.confirmButtonDisabled}
onClick={onConfirm} onClick={onConfirm}
/> />
)} )}
@ -222,6 +226,7 @@ export default defineComponent({
class={bem('cancel')} class={bem('cancel')}
color={props.cancelButtonColor} color={props.cancelButtonColor}
loading={loading.cancel} loading={loading.cancel}
disabled={props.cancelButtonDisabled}
onClick={onCancel} onClick={onCancel}
/> />
)} )}
@ -232,6 +237,7 @@ export default defineComponent({
class={bem('confirm')} class={bem('confirm')}
color={props.confirmButtonColor} color={props.confirmButtonColor}
loading={loading.confirm} loading={loading.confirm}
disabled={props.confirmButtonDisabled}
onClick={onConfirm} onClick={onConfirm}
/> />
)} )}

View File

@ -154,8 +154,10 @@ export default {
| showCancelButton | Whether to show cancel button | _boolean_ | `false` | | showCancelButton | Whether to show cancel button | _boolean_ | `false` |
| cancelButtonText | Cancel button text | _string_ | `Cancel` | | cancelButtonText | Cancel button text | _string_ | `Cancel` |
| cancelButtonColor | Cancel button color | _string_ | `black` | | cancelButtonColor | Cancel button color | _string_ | `black` |
| confirmButtonDisabled `v3.5.0` | Whether to disable cancel button | _boolean_ | `false` |
| confirmButtonText | Confirm button text | _string_ | `Confirm` | | confirmButtonText | Confirm button text | _string_ | `Confirm` |
| confirmButtonColor | Confirm button color | _string_ | `#ee0a24` | | confirmButtonColor | Confirm button color | _string_ | `#ee0a24` |
| confirmButtonDisabled `v3.5.0` | Whether to disable confirm button | _boolean_ | `false` |
| overlay | Whether to show overlay | _boolean_ | `true` | | overlay | Whether to show overlay | _boolean_ | `true` |
| overlayClass | Custom overlay class | _string \| Array \| object_ | - | | overlayClass | Custom overlay class | _string \| Array \| object_ | - |
| overlayStyle | Custom overlay style | _object_ | - | | overlayStyle | Custom overlay style | _object_ | - |
@ -181,8 +183,10 @@ export default {
| show-cancel-button | Whether to show cancel button | _boolean_ | `false` | | show-cancel-button | Whether to show cancel button | _boolean_ | `false` |
| cancel-button-text | Cancel button text | _string_ | `Cancel` | | cancel-button-text | Cancel button text | _string_ | `Cancel` |
| cancel-button-color | Cancel button color | _string_ | `black` | | cancel-button-color | Cancel button color | _string_ | `black` |
| cancel-button-disabled `v3.5.0` | Whether to disable cancel button | _boolean_ | `false` |
| confirm-button-text | Confirm button text | _string_ | `Confirm` | | confirm-button-text | Confirm button text | _string_ | `Confirm` |
| confirm-button-color | Confirm button color | _string_ | `#ee0a24` | | confirm-button-color | Confirm button color | _string_ | `#ee0a24` |
| confirm-button-disabled `v3.5.0` | Whether to disable confirm button | _boolean_ | `false` |
| overlay | Whether to show overlay | _boolean_ | `true` | | overlay | Whether to show overlay | _boolean_ | `true` |
| overlay-class | Custom overlay class | _string_ | - | | overlay-class | Custom overlay class | _string_ | - |
| overlay-style | Custom overlay style | _object_ | - | | overlay-style | Custom overlay style | _object_ | - |

View File

@ -200,8 +200,10 @@ export default {
| showCancelButton | 是否展示取消按钮 | _boolean_ | `false` | | showCancelButton | 是否展示取消按钮 | _boolean_ | `false` |
| confirmButtonText | 确认按钮文案 | _string_ | `确认` | | confirmButtonText | 确认按钮文案 | _string_ | `确认` |
| confirmButtonColor | 确认按钮颜色 | _string_ | `#ee0a24` | | confirmButtonColor | 确认按钮颜色 | _string_ | `#ee0a24` |
| confirmButtonDisabled `v3.5.0` | 是否禁用确认按钮 | _boolean_ | `false` |
| cancelButtonText | 取消按钮文案 | _string_ | `取消` | | cancelButtonText | 取消按钮文案 | _string_ | `取消` |
| cancelButtonColor | 取消按钮颜色 | _string_ | `black` | | cancelButtonColor | 取消按钮颜色 | _string_ | `black` |
| cancelButtonDisabled `v3.5.0` | 是否禁用取消按钮 | _boolean_ | `false` |
| overlay | 是否展示遮罩层 | _boolean_ | `true` | | overlay | 是否展示遮罩层 | _boolean_ | `true` |
| overlayClass | 自定义遮罩层类名 | _string \| Array \| object_ | - | | overlayClass | 自定义遮罩层类名 | _string \| Array \| object_ | - |
| overlayStyle | 自定义遮罩层样式 | _object_ | - | | overlayStyle | 自定义遮罩层样式 | _object_ | - |
@ -229,8 +231,10 @@ export default {
| show-cancel-button | 是否展示取消按钮 | _boolean_ | `false` | | show-cancel-button | 是否展示取消按钮 | _boolean_ | `false` |
| confirm-button-text | 确认按钮文案 | _string_ | `确认` | | confirm-button-text | 确认按钮文案 | _string_ | `确认` |
| confirm-button-color | 确认按钮颜色 | _string_ | `#ee0a24` | | confirm-button-color | 确认按钮颜色 | _string_ | `#ee0a24` |
| confirm-button-disabled `v3.5.0` | 是否禁用确认按钮 | _boolean_ | `false` |
| cancel-button-text | 取消按钮文案 | _string_ | `取消` | | cancel-button-text | 取消按钮文案 | _string_ | `取消` |
| cancel-button-color | 取消按钮颜色 | _string_ | `black` | | cancel-button-color | 取消按钮颜色 | _string_ | `black` |
| cancel-button-disabled `v3.5.0` | 是否禁用取消按钮 | _boolean_ | `false` |
| overlay | 是否展示遮罩层 | _boolean_ | `true` | | overlay | 是否展示遮罩层 | _boolean_ | `true` |
| overlay-class | 自定义遮罩层类名 | _string_ | - | | overlay-class | 自定义遮罩层类名 | _string_ | - |
| overlay-style | 自定义遮罩层样式 | _object_ | - | | overlay-style | 自定义遮罩层样式 | _object_ | - |

View File

@ -56,8 +56,10 @@ Dialog.defaultOptions = {
messageAlign: '', messageAlign: '',
cancelButtonText: '', cancelButtonText: '',
cancelButtonColor: null, cancelButtonColor: null,
cancelButtonDisabled: false,
confirmButtonText: '', confirmButtonText: '',
confirmButtonColor: null, confirmButtonColor: null,
confirmButtonDisabled: false,
showConfirmButton: true, showConfirmButton: true,
showCancelButton: false, showCancelButton: false,
closeOnPopstate: true, closeOnPopstate: true,

View File

@ -142,3 +142,30 @@ test('should render footer slot correctly', () => {
}); });
expect(wrapper.find('.van-dialog').html()).toMatchSnapshot(); expect(wrapper.find('.van-dialog').html()).toMatchSnapshot();
}); });
test('should allow to disable confirm button', () => {
const wrapper = mount(Dialog, {
props: {
show: true,
message: 'message',
confirmButtonDisabled: true,
},
});
expect(wrapper.find('.van-dialog__confirm').classes()).toContain(
'van-button--disabled'
);
});
test('should allow to disable cancel button', () => {
const wrapper = mount(Dialog, {
props: {
show: true,
showCancelButton: true,
message: 'message',
cancelButtonDisabled: true,
},
});
expect(wrapper.find('.van-dialog__cancel').classes()).toContain(
'van-button--disabled'
);
});

View File

@ -23,12 +23,14 @@ export type DialogOptions = {
overlayClass?: string; overlayClass?: string;
overlayStyle?: CSSProperties; overlayStyle?: CSSProperties;
closeOnPopstate?: boolean; closeOnPopstate?: boolean;
cancelButtonText?: string;
showCancelButton?: boolean; showCancelButton?: boolean;
showConfirmButton?: boolean; showConfirmButton?: boolean;
cancelButtonText?: string;
cancelButtonColor?: string; cancelButtonColor?: string;
cancelButtonDisabled?: boolean;
confirmButtonText?: string; confirmButtonText?: string;
confirmButtonColor?: string; confirmButtonColor?: string;
confirmButtonDisabled?: boolean;
closeOnClickOverlay?: boolean; closeOnClickOverlay?: boolean;
}; };