Skip to content

Commit

Permalink
fix(Popup): fix panel null bug (#3061)
Browse files Browse the repository at this point in the history
* fix(Popup): fix panel null bug

* chore: fix

* fix(Popup): fix panel null bug
  • Loading branch information
uyarn authored Aug 23, 2024
1 parent f360958 commit 20eea7d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ const Popup = forwardRef<PopupRef, PopupProps>((originalProps, ref) => {
// 默认动画时长
const DEFAULT_TRANSITION_TIMEOUT = 180;

// 处理切换 panel 为 null 和正常内容动态切换的情况
useEffect(() => {
if (!content && hideEmptyPopup) {
requestAnimationFrame(() => setPopupElement(null));
}
}, [content, hideEmptyPopup]);

// 判断展示浮层
const showOverlay = useMemo(() => {
if (hideEmptyPopup && !content) return false;
Expand Down
1 change: 1 addition & 0 deletions src/select-input/useMultiple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default function useMultiple(props: TdSelectInputProps) {
onFocus={(val, context) => {
props.onFocus?.(props.value, { ...context, tagInputValue: val });
}}
onBlur={!props.panel ? props.onBlur : null}
{...props.tagInputProps}
inputProps={{
...props.inputProps,
Expand Down
6 changes: 6 additions & 0 deletions src/select-input/useSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export default function useSingle(props: TdSelectInputProps) {
}
};

const handleEmptyPanelBlur = (value: string, { e }: { e: React.FocusEvent<HTMLInputElement> }) => {
props.onBlur?.(value, { e, inputValue: value });
};

const renderSelectSingle = (popupVisible: boolean) => {
// 单选,值的呈现方式
const singleValueDisplay = !props.multiple ? props.valueDisplay : null;
Expand Down Expand Up @@ -93,6 +97,8 @@ export default function useSingle(props: TdSelectInputProps) {
onEnter={(val, context) => {
props.onEnter?.(value, { ...context, inputValue: val });
}}
// onBlur need to triggered by input when popup panel is null
onBlur={!props.panel ? handleEmptyPanelBlur : null}
{...props.inputProps}
inputClass={classNames(props.inputProps?.className, {
[`${classPrefix}-input--focused`]: popupVisible,
Expand Down

0 comments on commit 20eea7d

Please sign in to comment.