fix(components): [time-picker] fix keyboard arrow controls (#21215)

This commit is contained in:
dhj-l
2025-07-23 17:36:38 +08:00
committed by GitHub
parent 6593d815e6
commit 6e419e9b9a
2 changed files with 39 additions and 16 deletions

View File

@@ -179,18 +179,26 @@ const getAmPmFlag = (hour: number) => {
const emitSelectRange = (type: TimeUnit) => {
let range = [0, 0]
if (!format || format === DEFAULT_FORMATS_TIME) {
switch (type) {
case 'hours':
range = [0, 2]
break
case 'minutes':
range = [3, 5]
break
case 'seconds':
range = [6, 8]
break
}
const actualFormat = format || DEFAULT_FORMATS_TIME
const hourIndex = actualFormat.indexOf('HH')
const minuteIndex = actualFormat.indexOf('mm')
const secondIndex = actualFormat.indexOf('ss')
switch (type) {
case 'hours':
if (hourIndex !== -1) {
range = [hourIndex, hourIndex + 2]
}
break
case 'minutes':
if (minuteIndex !== -1) {
range = [minuteIndex, minuteIndex + 2]
}
break
case 'seconds':
if (secondIndex !== -1) {
range = [secondIndex, secondIndex + 2]
}
break
}
const [left, right] = range

View File

@@ -116,10 +116,25 @@ const setSelectionRange = (start: number, end: number) => {
}
const changeSelectionRange = (step: number) => {
const list = [0, 3].concat(showSeconds.value ? [6] : [])
const mapping = ['hours', 'minutes'].concat(
showSeconds.value ? ['seconds'] : []
)
const actualFormat = props.format
const hourIndex = actualFormat.indexOf('HH')
const minuteIndex = actualFormat.indexOf('mm')
const secondIndex = actualFormat.indexOf('ss')
const list: number[] = []
const mapping: string[] = []
if (hourIndex !== -1) {
list.push(hourIndex)
mapping.push('hours')
}
if (minuteIndex !== -1) {
list.push(minuteIndex)
mapping.push('minutes')
}
if (secondIndex !== -1 && showSeconds.value) {
list.push(secondIndex)
mapping.push('seconds')
}
const index = list.indexOf(selectionRange.value[0])
const next = (index + step + list.length) % list.length
timePickerOptions['start_emitSelectRange'](mapping[next])