mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(components): [time-picker] fix keyboard arrow controls (#21215)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user