Merge branch 'v4' of https://github.com/primefaces/primevue into v4
commit
0313babbb3
|
@ -13,6 +13,10 @@ export default {
|
||||||
type: String,
|
type: String,
|
||||||
default: null
|
default: null
|
||||||
},
|
},
|
||||||
|
indeterminate: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
trueValue: {
|
trueValue: {
|
||||||
type: null,
|
type: null,
|
||||||
default: true
|
default: true
|
||||||
|
|
|
@ -111,6 +111,11 @@ export interface CheckboxProps {
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
binary?: boolean;
|
binary?: boolean;
|
||||||
|
/**
|
||||||
|
* When present, it specifies input state as indeterminate.
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
indeterminate?: boolean | undefined;
|
||||||
/**
|
/**
|
||||||
* When present, it specifies that the component should have invalid state style.
|
* When present, it specifies that the component should have invalid state style.
|
||||||
* @defaultValue false
|
* @defaultValue false
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="cx('root')" v-bind="getPTOptions('root')" :data-p-highlight="checked" :data-p-disabled="disabled">
|
<div :class="cx('root')" v-bind="getPTOptions('root')" :data-p-highlight="checked" :data-p-checked="checked" :data-p-indeterminate="d_indeterminate || undefined" :data-p-disabled="disabled">
|
||||||
<input
|
<input
|
||||||
:id="inputId"
|
:id="inputId"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
:aria-labelledby="ariaLabelledby"
|
:aria-labelledby="ariaLabelledby"
|
||||||
:aria-label="ariaLabel"
|
:aria-label="ariaLabel"
|
||||||
:aria-invalid="invalid || undefined"
|
:aria-invalid="invalid || undefined"
|
||||||
|
:aria-checked="d_indeterminate ? 'mixed' : undefined"
|
||||||
@focus="onFocus"
|
@focus="onFocus"
|
||||||
@blur="onBlur"
|
@blur="onBlur"
|
||||||
@change="onChange"
|
@change="onChange"
|
||||||
|
@ -23,6 +24,7 @@
|
||||||
<div :class="cx('box')" v-bind="getPTOptions('box')">
|
<div :class="cx('box')" v-bind="getPTOptions('box')">
|
||||||
<slot name="icon" :checked="checked" :class="cx('icon')">
|
<slot name="icon" :checked="checked" :class="cx('icon')">
|
||||||
<CheckIcon v-if="checked" :class="cx('icon')" v-bind="getPTOptions('icon')" />
|
<CheckIcon v-if="checked" :class="cx('icon')" v-bind="getPTOptions('icon')" />
|
||||||
|
<MinusIcon v-else-if="d_indeterminate" :class="cx('icon')" v-bind="getPTOptions('icon')" />
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -30,6 +32,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import CheckIcon from 'primevue/icons/check';
|
import CheckIcon from 'primevue/icons/check';
|
||||||
|
import MinusIcon from 'primevue/icons/minus';
|
||||||
import { ObjectUtils } from 'primevue/utils';
|
import { ObjectUtils } from 'primevue/utils';
|
||||||
import BaseCheckbox from './BaseCheckbox.vue';
|
import BaseCheckbox from './BaseCheckbox.vue';
|
||||||
|
|
||||||
|
@ -37,7 +40,17 @@ export default {
|
||||||
name: 'Checkbox',
|
name: 'Checkbox',
|
||||||
extends: BaseCheckbox,
|
extends: BaseCheckbox,
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
emits: ['update:modelValue', 'change', 'focus', 'blur'],
|
emits: ['update:modelValue', 'change', 'focus', 'blur', 'update:indeterminate'],
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
d_indeterminate: this.indeterminate
|
||||||
|
};
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
indeterminate(newValue) {
|
||||||
|
this.d_indeterminate = newValue;
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getPTOptions(key) {
|
getPTOptions(key) {
|
||||||
const _ptm = key === 'root' ? this.ptmi : this.ptm;
|
const _ptm = key === 'root' ? this.ptmi : this.ptm;
|
||||||
|
@ -54,12 +67,17 @@ export default {
|
||||||
let newModelValue;
|
let newModelValue;
|
||||||
|
|
||||||
if (this.binary) {
|
if (this.binary) {
|
||||||
newModelValue = this.checked ? this.falseValue : this.trueValue;
|
newModelValue = this.d_indeterminate ? this.trueValue : this.checked ? this.falseValue : this.trueValue;
|
||||||
} else {
|
} else {
|
||||||
if (this.checked) newModelValue = this.modelValue.filter((val) => !ObjectUtils.equals(val, this.value));
|
if (this.checked || this.d_indeterminate) newModelValue = this.modelValue.filter((val) => !ObjectUtils.equals(val, this.value));
|
||||||
else newModelValue = this.modelValue ? [...this.modelValue, this.value] : [this.value];
|
else newModelValue = this.modelValue ? [...this.modelValue, this.value] : [this.value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.d_indeterminate) {
|
||||||
|
this.d_indeterminate = false;
|
||||||
|
this.$emit('update:indeterminate', this.d_indeterminate);
|
||||||
|
}
|
||||||
|
|
||||||
this.$emit('update:modelValue', newModelValue);
|
this.$emit('update:modelValue', newModelValue);
|
||||||
this.$emit('change', event);
|
this.$emit('change', event);
|
||||||
}
|
}
|
||||||
|
@ -73,11 +91,12 @@ export default {
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
checked() {
|
checked() {
|
||||||
return this.binary ? this.modelValue === this.trueValue : ObjectUtils.contains(this.value, this.modelValue);
|
return this.d_indeterminate ? false : this.binary ? this.modelValue === this.trueValue : ObjectUtils.contains(this.value, this.modelValue);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
CheckIcon
|
CheckIcon,
|
||||||
|
MinusIcon
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -26,10 +26,9 @@
|
||||||
<component v-else :is="node.collapsedIcon ? 'span' : 'ChevronRightIcon'" :class="cx('togglerIcon')" v-bind="getPTOptions('togglerIcon')" />
|
<component v-else :is="node.collapsedIcon ? 'span' : 'ChevronRightIcon'" :class="cx('togglerIcon')" v-bind="getPTOptions('togglerIcon')" />
|
||||||
</template>
|
</template>
|
||||||
</button>
|
</button>
|
||||||
<Checkbox v-if="checkboxMode" :modelValue="checked" :binary="true" :class="cx('nodeCheckbox')" :tabindex="-1" :unstyled="unstyled" :pt="getPTOptions('nodeCheckbox')" :data-p-checked="checked" :data-p-partialchecked="partialChecked">
|
<Checkbox v-if="checkboxMode" :modelValue="checked" :binary="true" :indeterminate="partialChecked" :class="cx('nodeCheckbox')" :tabindex="-1" :unstyled="unstyled" :pt="getPTOptions('nodeCheckbox')" :data-p-partialchecked="partialChecked">
|
||||||
<template #icon="slotProps">
|
<template #icon="slotProps">
|
||||||
<component v-if="templates['checkboxicon']" :is="templates['checkboxicon']" :checked="slotProps.checked" :partialChecked="partialChecked" :class="slotProps.class" />
|
<component v-if="templates['checkboxicon']" :is="templates['checkboxicon']" :checked="slotProps.checked" :partialChecked="partialChecked" :class="slotProps.class" />
|
||||||
<component v-else :is="checked ? 'CheckIcon' : partialChecked ? 'MinusIcon' : null" :class="slotProps.class" v-bind="getPTOptions('nodeCheckbox.icon')" />
|
|
||||||
</template>
|
</template>
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
<component v-if="templates['nodeicon']" :is="templates['nodeicon']" :node="node" :class="[cx('nodeIcon')]"></component>
|
<component v-if="templates['nodeicon']" :is="templates['nodeicon']" :node="node" :class="[cx('nodeIcon')]"></component>
|
||||||
|
|
|
@ -18,15 +18,13 @@
|
||||||
:class="cx('rowCheckbox')"
|
:class="cx('rowCheckbox')"
|
||||||
@change="toggleCheckbox"
|
@change="toggleCheckbox"
|
||||||
:tabindex="-1"
|
:tabindex="-1"
|
||||||
|
:indeterminate="partialChecked"
|
||||||
:unstyled="unstyled"
|
:unstyled="unstyled"
|
||||||
:pt="getColumnCheckboxPT('rowCheckbox')"
|
:pt="getColumnCheckboxPT('rowCheckbox')"
|
||||||
:data-p-highlight="checked"
|
|
||||||
:data-p-checked="checked"
|
|
||||||
:data-p-partialchecked="partialChecked"
|
:data-p-partialchecked="partialChecked"
|
||||||
>
|
>
|
||||||
<template #icon="slotProps">
|
<template #icon="slotProps">
|
||||||
<component v-if="templates['checkboxicon']" :is="templates['checkboxicon']" :checked="slotProps.checked" :partialChecked="partialChecked" :class="slotProps.class" />
|
<component v-if="templates['checkboxicon']" :is="templates['checkboxicon']" :checked="slotProps.checked" :partialChecked="partialChecked" :class="slotProps.class" />
|
||||||
<component v-else :is="checked ? 'CheckIcon' : partialChecked ? 'MinusIcon' : null" :class="slotProps.class" v-bind="getColumnCheckboxPT('rowCheckbox.icon')" />
|
|
||||||
</template>
|
</template>
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
<component v-if="column.children && column.children.body" :is="column.children.body" :node="node" :column="column" />
|
<component v-if="column.children && column.children.body" :is="column.children.body" :node="node" :column="column" />
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
<template>
|
||||||
|
<DocSectionText v-bind="$attrs">
|
||||||
|
<p>When <i>indeterminate</i> is present, the checkbox state specified as indeterminate.</p>
|
||||||
|
</DocSectionText>
|
||||||
|
<div class="card flex justify-content-center">
|
||||||
|
<Checkbox v-model="checked" indeterminate binary />
|
||||||
|
</div>
|
||||||
|
<DocSectionCode :code="code" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
checked: false,
|
||||||
|
code: {
|
||||||
|
basic: `
|
||||||
|
<Checkbox v-model="checked" indeterminate binary />
|
||||||
|
`,
|
||||||
|
options: `
|
||||||
|
<template>
|
||||||
|
<div class="card flex justify-content-center">
|
||||||
|
<Checkbox v-model="checked" indeterminate binary />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
checked: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
<\/script>
|
||||||
|
`,
|
||||||
|
composition: `
|
||||||
|
<template>
|
||||||
|
<div class="card flex justify-content-center">
|
||||||
|
<Checkbox v-model="checked" indeterminate binary />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { ref } from "vue";
|
||||||
|
|
||||||
|
const checked = ref(false);
|
||||||
|
<\/script>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
|
@ -18,6 +18,7 @@ import DynamicDoc from '@/doc/checkbox/DynamicDoc.vue';
|
||||||
import FilledDoc from '@/doc/checkbox/FilledDoc.vue';
|
import FilledDoc from '@/doc/checkbox/FilledDoc.vue';
|
||||||
import GroupDoc from '@/doc/checkbox/GroupDoc.vue';
|
import GroupDoc from '@/doc/checkbox/GroupDoc.vue';
|
||||||
import ImportDoc from '@/doc/checkbox/ImportDoc.vue';
|
import ImportDoc from '@/doc/checkbox/ImportDoc.vue';
|
||||||
|
import IndeterminateDoc from '@/doc/checkbox/IndeterminateDoc.vue';
|
||||||
import InvalidDoc from '@/doc/checkbox/InvalidDoc.vue';
|
import InvalidDoc from '@/doc/checkbox/InvalidDoc.vue';
|
||||||
import PTComponent from '@/doc/checkbox/pt/index.vue';
|
import PTComponent from '@/doc/checkbox/pt/index.vue';
|
||||||
import ThemingDoc from '@/doc/checkbox/theming/index.vue';
|
import ThemingDoc from '@/doc/checkbox/theming/index.vue';
|
||||||
|
@ -36,6 +37,11 @@ export default {
|
||||||
label: 'Basic',
|
label: 'Basic',
|
||||||
component: BasicDoc
|
component: BasicDoc
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'indeterminate',
|
||||||
|
label: 'Indeterminate',
|
||||||
|
component: IndeterminateDoc
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'group',
|
id: 'group',
|
||||||
label: 'Group',
|
label: 'Group',
|
||||||
|
|
Loading…
Reference in New Issue