Skip to content

Commit

Permalink
feat(TimePicker): support readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
RSS1102 committed Dec 5, 2024
1 parent c76c638 commit 5ce46fa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/time-picker/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export default {
presets: {
type: Object as PropType<TdTimePickerProps['presets']>,
},
/** 只读状态 */
readonly: {
type: Boolean,
default: undefined,
},
/** 透传 SelectInput 筛选器输入框组件的全部属性 */
selectInputProps: {
type: Object as PropType<TdTimePickerProps['selectInputProps']>,
Expand Down
2 changes: 1 addition & 1 deletion src/time-picker/time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default defineComponent({
class={inputClasses.value}
label={props.label}
suffixIcon={() => <TimeIcon />}
popupVisible={isShowPanel.value}
popupVisible={!props.readonly && isShowPanel.value}
onInputChange={handleInputChange}
onBlur={handleInputBlur}
onPopupVisibleChange={handleShowPopup}
Expand Down
5 changes: 5 additions & 0 deletions src/time-picker/time-range-picker-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export default {
rangeInputProps: {
type: Object as PropType<TdTimeRangePickerProps['rangeInputProps']>,
},
/** 只读状态 */
readonly: {
type: Boolean,
default: undefined,
},
/** 尺寸 */
size: {
type: String as PropType<TdTimeRangePickerProps['size']>,
Expand Down
5 changes: 4 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 useVModel from '../hooks/useVModel';
import { useCommonClassName, useConfig, usePrefixClass } from '../hooks/useConfig';
import { useGlobalIcon } from '../hooks/useGlobalIcon';
import { useDisabled } from '../hooks/useDisabled';
import { useReadonly } from '../hooks/useReadonly';

dayjs.extend(customParseFormat);

Expand All @@ -37,6 +38,7 @@ export default defineComponent({
const currentPanelIdx = ref(undefined);
const currentValue = ref<Array<string>>(TIME_PICKER_EMPTY);
const isShowPanel = ref(false);
const isReadOnly = useReadonly();

const inputClasses = computed(() => [
`${COMPONENT_NAME.value}__group`,
Expand All @@ -48,6 +50,7 @@ export default defineComponent({
const [innerValue, setInnerValue] = useVModel(value, modelValue, props.defaultValue, props.onChange as any);

const handleShowPopup = (visible: boolean, context: any) => {
if (isReadOnly.value) return;
// 输入框点击不关闭面板
if (context.trigger === 'trigger-element-click') {
isShowPanel.value = true;
Expand Down Expand Up @@ -173,7 +176,7 @@ export default defineComponent({
onClick: handleClick,
onFocus: handleFocus,
onBlur: handleInputBlur,
readonly: !allowInput.value,
readonly: props.readonly || !allowInput.value,
activeIndex: currentPanelIdx.value,
...props.rangeInputProps,
}}
Expand Down

0 comments on commit 5ce46fa

Please sign in to comment.