Skip to content

Commit

Permalink
fix(form): form disabled affect components (#2405)
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed May 11, 2023
1 parent f829fce commit 98a84a6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/date-picker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import {
initYearMonthTime,
} from '../_common/js/date-picker/format';
import { subtractMonth, addMonth, extractTimeObj } from '../_common/js/date-picker/utils';
import useFormDisabled from '../hooks/useFormDisabled';

export default defineComponent({
name: 'TDateRangePicker',
props,
setup(props, { emit }) {
const COMPONENT_NAME = usePrefixClass('date-range-picker');
const { CalendarIcon } = useGlobalIcon({ CalendarIcon: TdCalendarIcon });
const { formDisabled } = useFormDisabled();

const {
inputValue,
Expand All @@ -51,6 +53,7 @@ export default defineComponent({
format: props.format,
valueType: props.valueType,
}));
const isDisabled = computed(() => formDisabled.value || props.disabled);

// 记录面板是否选中过
const isSelected = ref(false);
Expand Down Expand Up @@ -416,6 +419,7 @@ export default defineComponent({
popupVisible,
panelProps,
CalendarIcon,
isDisabled,
};
},
render() {
Expand All @@ -440,7 +444,7 @@ export default defineComponent({
return (
<div class={COMPONENT_NAME}>
<TRangeInputPopup
disabled={this.disabled}
disabled={this.isDisabled}
status={this.status}
tips={this.tips || this.$scopedSlots.tips}
inputValue={inputValue as string[]}
Expand Down
2 changes: 1 addition & 1 deletion src/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ export default defineComponent({
value: this.displayText,
valueDisplay: () => renderTNode('valueDisplay', { params: this.valueDisplayParams }),
clearable: this.clearable,
disabled: this.disabled,
disabled: this.isDisabled,
label: this.renderLabel,
suffixIcon: this.renderSuffixIcon,
placeholder: this.placeholderText,
Expand Down
6 changes: 5 additions & 1 deletion src/time-picker/time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { InputProps } from '../input';
import useVModel from '../hooks/useVModel';
import { useConfig, usePrefixClass } from '../hooks/useConfig';
import { useGlobalIcon } from '../hooks/useGlobalIcon';
import useFormDisabled from '../hooks/useFormDisabled';

import props from './props';

Expand All @@ -25,10 +26,12 @@ export default defineComponent({
const { classPrefix } = useConfig('classPrefix');
const componentName = usePrefixClass('time-picker');
const { TimeIcon } = useGlobalIcon({ TimeIcon: TdTimeIcon });
const { formDisabled } = useFormDisabled();

const currentValue = ref('');
const isShowPanel = ref(false);
const { global } = useConfig('timePicker');
const isDisabled = computed(() => formDisabled.value || props.disabled);

const { value } = toRefs(props);
const [innerValue, setInnerValue] = useVModel(value, props.defaultValue, props.onChange, 'change');
Expand Down Expand Up @@ -116,6 +119,7 @@ export default defineComponent({
global,
currentValue,
TimeIcon,
isDisabled,
};
},
render() {
Expand All @@ -129,7 +133,7 @@ export default defineComponent({
onClear: this.handleClear,
onBlur: this.handleInputBlur,
onInputChange: this.handleInputChange,
disabled: this.disabled,
disabled: this.isDisabled,
clearable: this.clearable,
allowInput: this.allowInput,
class: this.inputClasses,
Expand Down
7 changes: 6 additions & 1 deletion src/time-picker/time-range-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { TimeRangePickerPartial } from './type';
import useVModel from '../hooks/useVModel';
import { useConfig, usePrefixClass } from '../hooks/useConfig';
import { useGlobalIcon } from '../hooks/useGlobalIcon';
import useFormDisabled from '../hooks/useFormDisabled';

dayjs.extend(customParseFormat);

Expand All @@ -36,6 +37,7 @@ export default defineComponent({
const { global } = useConfig('timePicker');
const { classPrefix } = useConfig('classPrefix');
const { TimeIcon } = useGlobalIcon({ TimeIcon: TdTimeIcon });
const { formDisabled } = useFormDisabled();

const currentPanelIdx = ref(undefined);
const currentValue = ref<Array<string>>(TIME_PICKER_EMPTY);
Expand All @@ -47,6 +49,8 @@ export default defineComponent({
[`${classPrefix.value}-is-focused`]: isShowPanel.value,
},
]);
const isDisabled = computed(() => formDisabled.value || props.disabled);

const { value, format } = toRefs(props);
const [innerValue, setInnerValue] = useVModel(value, props.defaultValue, props.onChange, 'change');

Expand Down Expand Up @@ -150,6 +154,7 @@ export default defineComponent({
handleInputBlur,
handleTimeChange,
TimeIcon,
isDisabled,
};
},
render() {
Expand All @@ -161,7 +166,7 @@ export default defineComponent({
{...{
props: {
onInputChange: this.handleInputChange,
disabled: this.disabled,
disabled: this.isDisabled,
popupVisible: this.isShowPanel,
inputValue: this.isShowPanel ? this.currentValue : this.innerValue ?? TIME_PICKER_EMPTY,
popupProps: {
Expand Down

0 comments on commit 98a84a6

Please sign in to comment.