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

feat(TimePicker): support readonly #4812

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
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
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
4 changes: 3 additions & 1 deletion src/time-picker/time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useDisabled } from '../hooks/useDisabled';
import { useCommonClassName, useConfig, usePrefixClass } from '../hooks/useConfig';
import { useGlobalIcon } from '../hooks/useGlobalIcon';
import { TdTimePickerProps } from './type';
import { useReadonly } from '../hooks/useReadonly';

dayjs.extend(customParseFormat);

Expand All @@ -34,6 +35,7 @@ export default defineComponent({

const currentValue = ref('');
const isShowPanel = ref(false);
const isReadonly = useReadonly();

const { value, modelValue } = toRefs(props);
const [innerValue, setInnerValue] = useVModel(value, modelValue, props.defaultValue, props.onChange);
Expand Down Expand Up @@ -110,7 +112,7 @@ export default defineComponent({
class={inputClasses.value}
label={props.label}
suffixIcon={() => <TimeIcon />}
popupVisible={isShowPanel.value}
popupVisible={!isReadonly && 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
Loading