feat(CheckboxGroup): toggleAll support skipDisabled option (#7644)

This commit is contained in:
neverland
2020-11-26 19:34:51 +08:00
committed by GitHub
parent 9f2187f021
commit 488d90aab9
5 changed files with 78 additions and 16 deletions
+11 -8
View File
@@ -27,16 +27,19 @@ export default createComponent({
methods: {
// @exposed-api
toggleAll(checked) {
if (checked === false) {
this.$emit('input', []);
return;
toggleAll(options = {}) {
if (typeof options === 'boolean') {
options = { checked: options };
}
let { children } = this;
if (!checked) {
children = children.filter((item) => !item.checked);
}
const { checked, skipDisabled } = options;
const children = this.children.filter((item) => {
if (item.disabled && skipDisabled) {
return item.checked;
}
return checked ?? !item.checked;
});
const names = children.map((item) => item.name);
this.$emit('input', names);