Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(select): 修复限制可选条目数下禁用态不能反选的问题 #1825

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/select/option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
reactive,
} from '@vue/composition-api';
import Vue, { PropType } from 'vue';

import { ScopedSlotReturnValue } from 'vue/types/vnode';
import { renderContent } from '../utils/render-tnode';
import Ripple from '../utils/ripple';
Expand All @@ -24,6 +23,7 @@ import { TScroll } from '../common';
import { getNewMultipleValue } from './util';
import { useConfig } from '../config-provider/useConfig';
import useCommonClassName from '../hooks/useCommonClassName';
import useFormDisabled from '../hooks/useFormDisabled';

const keepAnimationMixins = getKeepAnimationMixins();
export interface OptionInstance extends Vue {
Expand Down Expand Up @@ -78,11 +78,15 @@ export default defineComponent({
);

const isHover = ref(false);
const formDisabled = ref(undefined);
const isDisabled = computed(() => formDisabled.value || disabled.value || selectProvider.isReachMaxLimit.value);
const { formDisabled } = useFormDisabled();
const isSelected = computed(() => multiple.value
? (selectProvider.selectValue.value as SelectValue[])?.includes(props.value)
: selectProvider.selectValue.value === props.value);
const isDisabled = computed(
() => disabled.value
|| formDisabled.value
|| (multiple.value && !isSelected.value && selectProvider.isReachMaxLimit.value),
);
const mouseEvent = (v: boolean) => {
isHover.value = v;
};
Expand Down Expand Up @@ -148,6 +152,7 @@ export default defineComponent({
return {
isHover,
isSelected,
isDisabled,
mouseEvent,
classes,
selectProvider,
Expand All @@ -161,7 +166,7 @@ export default defineComponent({

render() {
const {
classes, multiple, labelText, isSelected, disabled, selectProvider, mouseEvent,
classes, multiple, labelText, isSelected, isDisabled, mouseEvent,
} = this;
const children: ScopedSlotReturnValue = renderContent(this, 'default', 'content');
const optionChild = children || <span>{labelText}</span>;
Expand Down Expand Up @@ -190,7 +195,7 @@ export default defineComponent({
v-ripple={(this.keepAnimation as any).ripple}
>
{multiple ? (
<t-checkbox checked={isSelected} disabled={disabled || (!isSelected && selectProvider.isReachMaxLimit.value)}>
<t-checkbox checked={isSelected} disabled={isDisabled}>
{optionChild}
</t-checkbox>
) : (
Expand Down