naive-ui icon indicating copy to clipboard operation
naive-ui copied to clipboard

Date Picker中的shortcuts有点小问题

Open flyzss opened this issue 6 months ago • 2 comments

Describe the bug

Image 如图,我点击"本月"按钮触发弹窗的消失动画,在动画过程中鼠标指针会划过"最近三年"按钮,导致选择的是本月,但显示的是最近三年.

Steps to reproduce

当快捷按钮有多列时,消失动画可能导致鼠标指针触碰其它按钮

Link to minimal reproduction

none

System Info

chrome

Used Package Manager

npm

Validations

flyzss avatar May 21 '25 10:05 flyzss

Provide a based on Playground or CodeSandbox or stackblitz `s MinimalReproducible Example

jahnli avatar Jun 08 '25 16:06 jahnli

遇到了同样的问题

目前我这边是通过覆盖原方法以解决此问题.

<NDatePicker ref={cmpRef} />

TS样例仅供参考:

    const cmpRef = ref<{ panelInstRef?: { $el?: HTMLElement } } | null>(null)
    const overrideFn = ref({
      handleRangeShortcutMouseenter: undefined as ((shortcut: Shortcuts[string]) => void) | undefined
    })
    const pendingShortcutEnterEventFlagRef = ref(false)
    watch(
      () => cmpRef.value?.panelInstRef,
      (newVal) => {
        if (newVal && cmpRef.value && cmpRef.value.panelInstRef && cmpRef.value.panelInstRef.$el) {
          pendingShortcutEnterEventFlagRef.value = true
          const panelInst: JSONStruct = cmpRef.value.panelInstRef
          overrideFn.value.handleRangeShortcutMouseenter = panelInst.handleRangeShortcutMouseenter
          panelInst.handleRangeShortcutMouseenter = (shortcut: Shortcuts[string]) => {
            if (!pendingShortcutEnterEventFlagRef.value) {
              return
            }
            overrideFn.value.handleRangeShortcutMouseenter?.(shortcut)
          }
          panelInst.handleRangeShortcutClick = (shortcut: typeof Function) => {
            pendingShortcutEnterEventFlagRef.value = false
            const shortcutValue = panelInst.getShortcutValue(shortcut)
            if (!Array.isArray(shortcutValue)) return
            panelInst.changeStartEndTime(shortcutValue[0], shortcutValue[1], 'shortcutPreview') // 此处同时解决了另外一个问题 ['done' -> 'shortcutPreview' #6901]
            panelInst.clearPendingValue()
            panelInst.handleConfirmClick()
          }
        }
      }
    )

'done' -> 'shortcutPreview' #6901

Jeremyz0613 avatar Jun 10 '25 09:06 Jeremyz0613

This issue does not have any recent activity. If you are still experiencing similar problems, open a new error, including a minimal copy of the problem

jahnli avatar Jun 24 '25 03:06 jahnli