Skip to content

Commit

Permalink
fix(select): single select emit blur
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Sep 25, 2024
1 parent e33a9e9 commit e397871
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/select-input/useSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export default function useSingle(

const onBlur: StrInputProps['onBlur'] = (val, context) => {
const overlayState = popupRef.value?.getOverlayState();
if (overlayState?.hover) return;
isSingleFocus.value = false;
if (overlayState?.hover) return;
props.onBlur?.(value.value, { ...context, inputValue: val });
};

Expand Down
1 change: 1 addition & 0 deletions src/select/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const selectInjectKey: InjectionKey<
onCheckAllChange: (checked: boolean) => void;
getSelectedOptions: (selectValue?: SelectValue[] | SelectValue) => TdOptionProps[];
displayOptions: TdSelectProps['options'];
emitBlur: (e: MouseEvent | KeyboardEvent) => void;
}>
> = Symbol('selectProvide');

Expand Down
1 change: 1 addition & 0 deletions src/select/option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default defineComponent({
e,
});
selectProvider.value.handlePopupVisibleChange(false, { e });
selectProvider.value.emitBlur(e);
};

const handleCheckboxClick = (val: boolean, context: { e: MouseEvent | KeyboardEvent }) => {
Expand Down
5 changes: 5 additions & 0 deletions src/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export default defineComponent({
onCheckAllChange,
getSelectedOptions,
displayOptions: displayOptions.value,
emitBlur: handleOptionEmitBlur,
}));

provide(selectInjectKey, SelectProvider);
Expand Down Expand Up @@ -272,6 +273,10 @@ export default defineComponent({
});
};

const handleOptionEmitBlur = (e: MouseEvent | KeyboardEvent) => {
props.onBlur?.({ e, value: innerValue.value });
};

const handlerPopupVisibleChange = (visible: boolean, context: PopupVisibleChangeContext) => {
setInnerPopupVisible(visible, context);
// 在通过点击选择器打开弹窗时 清空此前的输入内容 避免在关闭时就清空引起的闪烁问题
Expand Down

0 comments on commit e397871

Please sign in to comment.