mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types: improve Checker parent typing (#8128)
This commit is contained in:
parent
afad4ca90a
commit
b5944524d9
@ -5,6 +5,15 @@ import Icon from '../icon';
|
||||
export type CheckerShape = 'square' | 'round';
|
||||
export type CheckerLabelPosition = 'left' | 'right';
|
||||
|
||||
type CheckerParent = {
|
||||
props: {
|
||||
disabled?: boolean;
|
||||
iconSize?: number | string;
|
||||
direction?: 'horizontal' | 'vertical';
|
||||
checkedColor?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export const checkerProps = {
|
||||
name: null as any,
|
||||
disabled: Boolean,
|
||||
@ -23,7 +32,7 @@ export default defineComponent({
|
||||
props: {
|
||||
...checkerProps,
|
||||
role: String,
|
||||
parent: Object as PropType<Record<string, any> | null>,
|
||||
parent: Object as PropType<CheckerParent | null>,
|
||||
checked: Boolean,
|
||||
bindGroup: {
|
||||
type: Boolean,
|
||||
@ -40,13 +49,13 @@ export default defineComponent({
|
||||
setup(props, { emit, slots }) {
|
||||
const iconRef = ref<HTMLElement>();
|
||||
|
||||
const getParentProp = (name: string) => {
|
||||
const getParentProp = <T extends keyof CheckerParent['props']>(name: T) => {
|
||||
if (props.parent && props.bindGroup) {
|
||||
return props.parent.props[name];
|
||||
}
|
||||
};
|
||||
|
||||
const disabled = computed<boolean>(
|
||||
const disabled = computed(
|
||||
() => getParentProp('disabled') || props.disabled
|
||||
);
|
||||
|
||||
|
@ -176,7 +176,7 @@ test('should toggle collapse after calling the toggle method in accordion mode',
|
||||
setup() {
|
||||
const itemA = ref();
|
||||
const itemB = ref();
|
||||
const active = ref([]);
|
||||
const active = ref('');
|
||||
return {
|
||||
itemA,
|
||||
itemB,
|
||||
@ -194,6 +194,7 @@ test('should toggle collapse after calling the toggle method in accordion mode',
|
||||
});
|
||||
|
||||
wrapper.vm.itemA.toggle();
|
||||
await later();
|
||||
expect(wrapper.vm.active).toEqual('a');
|
||||
|
||||
wrapper.vm.itemB.toggle();
|
||||
|
@ -100,7 +100,6 @@ export default createComponent({
|
||||
<p class={bem('valid')}>{validPeriod.value}</p>
|
||||
{!disabled && (
|
||||
<Checkbox
|
||||
size={18}
|
||||
class={bem('corner')}
|
||||
modelValue={chosen}
|
||||
checkedColor={RED}
|
||||
|
Loading…
x
Reference in New Issue
Block a user