diff --git a/packages/wow-ui/src/components/Picker/TimePicker.tsx b/packages/wow-ui/src/components/Picker/TimePicker.tsx index 385a2bc9..f2d8dc86 100644 --- a/packages/wow-ui/src/components/Picker/TimePicker.tsx +++ b/packages/wow-ui/src/components/Picker/TimePicker.tsx @@ -44,8 +44,10 @@ const TimePicker = forwardRef( }; const setSelectedTime = context?.setSelectedTime || propSetSelectedTime!; - const { isAM, handleClickAMOrPM, handleChangeHour, handleChangeMinute } = - useTimeState({ selectedTime, setSelectedTime }); + const { isAM, handleClickAMOrPM, handleChangeTime } = useTimeState({ + selectedTime, + setSelectedTime, + }); const strTime = formatTimeToString(selectedTime); @@ -77,7 +79,7 @@ const TimePicker = forwardRef( {strTime.hour} } - onChange={handleChangeHour} + onChange={(value) => handleChangeTime("hour", value)} > {hours.map((hour) => ( ( {strTime.minute} } - onChange={handleChangeMinute} + onChange={(value) => handleChangeTime("minute", value)} > {minutes.map((minute) => ( { setIsAM((prev) => !prev); }; - const handleChangeHour = (value: { - selectedValue: string; - selectedText: React.ReactNode; - }) => { + const handleChangeTime = ( + type: "hour" | "minute", + value: { selectedValue: string; selectedText: React.ReactNode } + ) => { setSelectedTime({ isAM: isAM, - hour: +value.selectedValue, - minute: selectedTime.minute, - }); - }; - - const handleChangeMinute = (value: { - selectedValue: string; - selectedText: React.ReactNode; - }) => { - setSelectedTime({ - isAM: isAM, - hour: selectedTime.hour, - minute: +value.selectedValue, + hour: type === "hour" ? +value.selectedValue : selectedTime.hour, + minute: type === "minute" ? +value.selectedValue : selectedTime.minute, }); }; return { isAM, handleClickAMOrPM, - handleChangeHour, - handleChangeMinute, + handleChangeTime, }; };