Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Popup): fix panel null bug #3061

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading