Skip to content

Commit

Permalink
fix(pro:search): panel onkeydown should only be called when opened (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Feb 27, 2023
1 parent b961c4e commit 76a1bac
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/pro/search/src/searchItem/Segment.tsx
Expand Up @@ -167,7 +167,7 @@ export default defineComponent({
handleMouseDown,
handleKeyDown,
setPanelOnKeyDown,
} = useInputEvents(props, context, handleSegmentInput, setCurrentAsActive, handleConfirm)
} = useInputEvents(props, context, overlayOpened, handleSegmentInput, setCurrentAsActive, handleConfirm)

const overlayProps = useOverlayAttrs(props, mergedPrefixCls, commonOverlayProps, overlayOpened)

Expand Down Expand Up @@ -263,6 +263,7 @@ interface InputEventHandlers {
function useInputEvents(
props: SegmentProps,
context: ProSearchContext,
overlayOpened: ComputedRef<boolean>,
handleSegmentInput: (name: string, input: string) => void,
setCurrentAsActive: (overlayOpened: boolean) => void,
confirm: () => void,
Expand Down Expand Up @@ -302,15 +303,20 @@ function useInputEvents(
setCurrentAsActive(true)
}
const handleKeyDown = (evt: KeyboardEvent) => {
const paneKeyDownRes = panelOnKeyDown.value?.(evt) ?? true
if (!paneKeyDownRes) {
evt.stopPropagation()
if (overlayOpened.value && panelOnKeyDown.value && !panelOnKeyDown.value(evt)) {
return
}

switch (evt.key) {
case 'Enter':
evt.preventDefault()
confirm()
if (props.value) {
confirm()
} else {
setCurrentAsActive(true)
}

break
case 'Backspace':
if (!props.input) {
Expand Down

0 comments on commit 76a1bac

Please sign in to comment.