Skip to content

Commit

Permalink
fix(DatePicker): 修复日期选择器在表单禁用后还能点击的问题 (#1117)
Browse files Browse the repository at this point in the history
* fix(DatePicker): 修复日期选择器在表单禁用后还能点击

* fix: 修复IDE自动引入导致错误
  • Loading branch information
timi137137 authored Jun 30, 2022
1 parent 4ef2b3c commit eccc66b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/date-picker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineComponent, watchEffect, computed } from 'vue';
import dayjs from 'dayjs';
import { usePrefixClass } from '../hooks/useConfig';

import { useFormDisabled } from '../form/hooks';
import useSingle from './hooks/useSingle';
import useFormat from './hooks/useFormat';
import { subtractMonth, addMonth, extractTimeObj } from '../_common/js/date-picker/utils';
Expand Down Expand Up @@ -32,6 +33,8 @@ export default defineComponent({
onChange,
} = useSingle(props);

const disabled = useFormDisabled();

const formatRef = computed(() =>
useFormat({
mode: props.mode,
Expand Down Expand Up @@ -194,7 +197,7 @@ export default defineComponent({
return () => (
<div class={COMPONENT_NAME.value}>
<TSelectInput
disabled={props.disabled}
disabled={disabled.value}
value={inputValue.value}
popupProps={popupProps.value}
inputProps={inputProps.value}
Expand Down
5 changes: 4 additions & 1 deletion src/date-picker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineComponent, watchEffect, computed, ref } from 'vue';
import dayjs from 'dayjs';
import { useFormDisabled } from '../form/hooks';
import { usePrefixClass } from '../hooks/useConfig';

import props from './date-range-picker-props';
Expand Down Expand Up @@ -33,6 +34,8 @@ export default defineComponent({
onChange,
} = useRange(props);

const disabled = useFormDisabled();

const formatRef = computed(() =>
useFormat({
mode: props.mode,
Expand Down Expand Up @@ -298,7 +301,7 @@ export default defineComponent({
return () => (
<div class={COMPONENT_NAME.value}>
<TRangeInputPopup
disabled={props.disabled}
disabled={disabled.value}
inputValue={inputValue.value as string[]}
popupProps={popupProps.value}
rangeInputProps={rangeInputProps.value}
Expand Down
5 changes: 4 additions & 1 deletion src/date-picker/hooks/useSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ref, computed, watchEffect } from 'vue';
import { CalendarIcon } from 'tdesign-icons-vue-next';
import dayjs from 'dayjs';

import { useFormDisabled } from '../../form/hooks';
import { usePrefixClass, useConfig } from '../../hooks/useConfig';
import { TdDatePickerProps, DateValue } from '../type';
import useFormat from './useFormat';
Expand All @@ -10,6 +11,7 @@ import useSingleValue from './useSingleValue';
export default function useSingle(props: TdDatePickerProps) {
const COMPONENT_NAME = usePrefixClass('date-picker');
const { global } = useConfig('datePicker');
const disabled = useFormDisabled();

const inputRef = ref();

Expand Down Expand Up @@ -89,10 +91,11 @@ export default function useSingle(props: TdDatePickerProps) {
const popupProps = computed(() => ({
expandAnimation: true,
...props.popupProps,
disabled: props.disabled,
disabled: disabled.value,
overlayStyle: props.popupProps?.overlayStyle ?? { width: 'auto' },
overlayClassName: [props.popupProps?.overlayClassName, `${COMPONENT_NAME.value}__panel-container`],
onVisibleChange: (visible: boolean) => {
if (disabled) return;
popupVisible.value = visible;
if (!visible) {
isHoverCell.value = false;
Expand Down

0 comments on commit eccc66b

Please sign in to comment.