Skip to content

Commit 4428423

Browse files
committed
fix: select dropdown custom input error #7020
1 parent 380fcd4 commit 4428423

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

components/vc-select/BaseSelect.tsx

+13-4
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ export default defineComponent({
510510
// ========================== Focus / Blur ==========================
511511
/** Record real focus status */
512512
const focusRef = shallowRef(false);
513-
514513
const onContainerFocus: FocusEventHandler = (...args) => {
515514
setMockFocused(true);
516515

@@ -527,14 +526,16 @@ export default defineComponent({
527526

528527
focusRef.value = true;
529528
};
530-
529+
const popupFocused = ref(false);
531530
const onContainerBlur: FocusEventHandler = (...args) => {
531+
if (popupFocused.value) {
532+
return;
533+
}
532534
blurRef.value = true;
533-
534535
setMockFocused(false, () => {
535536
focusRef.value = false;
536537
blurRef.value = false;
537-
//onToggleOpen(false);
538+
onToggleOpen(false);
538539
});
539540

540541
if (props.disabled) {
@@ -557,6 +558,12 @@ export default defineComponent({
557558
props.onBlur(...args);
558559
}
559560
};
561+
const onPopupFocusin = () => {
562+
popupFocused.value = true;
563+
};
564+
const onPopupFocusout = () => {
565+
popupFocused.value = false;
566+
};
560567
provide('VCSelectContainerEvent', {
561568
focus: onContainerFocus,
562569
blur: onContainerBlur,
@@ -818,6 +825,8 @@ export default defineComponent({
818825
getTriggerDOMNode={() => selectorDomRef.current}
819826
onPopupVisibleChange={onTriggerVisibleChange}
820827
onPopupMouseEnter={onPopupMouseEnter}
828+
onPopupFocusin={onPopupFocusin}
829+
onPopupFocusout={onPopupFocusout}
821830
v-slots={{
822831
default: () => {
823832
return customizeRawInputElement ? (

components/vc-select/SelectTrigger.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export interface SelectTriggerProps {
7171
onPopupVisibleChange?: (visible: boolean) => void;
7272

7373
onPopupMouseEnter: () => void;
74+
onPopupFocusin: () => void;
75+
onPopupFocusout: () => void;
7476
}
7577

7678
const SelectTrigger = defineComponent<SelectTriggerProps, { popupRef: any }>({
@@ -97,6 +99,8 @@ const SelectTrigger = defineComponent<SelectTriggerProps, { popupRef: any }>({
9799
getTriggerDOMNode: Function,
98100
onPopupVisibleChange: Function as PropType<(open: boolean) => void>,
99101
onPopupMouseEnter: Function,
102+
onPopupFocusin: Function,
103+
onPopupFocusout: Function,
100104
} as any,
101105
setup(props, { slots, attrs, expose }) {
102106
const builtInPlacements = computed(() => {
@@ -129,6 +133,8 @@ const SelectTrigger = defineComponent<SelectTriggerProps, { popupRef: any }>({
129133
getTriggerDOMNode,
130134
onPopupVisibleChange,
131135
onPopupMouseEnter,
136+
onPopupFocusin,
137+
onPopupFocusout,
132138
} = restProps as SelectTriggerProps;
133139
const dropdownPrefixCls = `${prefixCls}-dropdown`;
134140

@@ -167,7 +173,12 @@ const SelectTrigger = defineComponent<SelectTriggerProps, { popupRef: any }>({
167173
v-slots={{
168174
default: slots.default,
169175
popup: () => (
170-
<div ref={popupRef} onMouseenter={onPopupMouseEnter}>
176+
<div
177+
ref={popupRef}
178+
onMouseenter={onPopupMouseEnter}
179+
onFocusin={onPopupFocusin}
180+
onFocusout={onPopupFocusout}
181+
>
171182
{popupNode}
172183
</div>
173184
),

0 commit comments

Comments
 (0)