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: drop down close issue of multiselect component #1265

Closed
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
24 changes: 18 additions & 6 deletions packages/fuselage/src/components/MultiSelect/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import type {
ElementType,
Ref,
ReactNode,
FocusEventHandler,
MouseEventHandler,
} from 'react';
import React, { useState, useRef, useEffect, forwardRef } from 'react';

Expand Down Expand Up @@ -142,19 +144,29 @@ export const MultiSelect = forwardRef(
};

const handleClick = useEffectEvent(() => {
if (visible === AnimatedVisibility.VISIBLE) {
return hide();
}
innerRef.current?.focus();
return show();
});

const handleBlur: FocusEventHandler = useEffectEvent(() => {
visible === AnimatedVisibility.VISIBLE && hide();
});

const handleOnMouseDown = useEffectEvent((e) => {
const isClickOnChip = e.target.closest('.rcx-chip');
if (!isClickOnChip) {
visible === AnimatedVisibility.VISIBLE ? hide() : show();
}
});

const handleAnchorClick: MouseEventHandler = useEffectEvent(() => {});

return (
<Box
is='div'
rcx-select
className={[error && 'invalid', disabled && 'disabled']}
ref={containerRef}
onMouseDown={handleOnMouseDown}
onClick={handleClick}
disabled={disabled}
{...props}
Expand All @@ -176,8 +188,8 @@ export const MultiSelect = forwardRef(
ref: anchorRef,
children: internalValue.length === 0 ? placeholder : null,
disabled: disabled ?? false,
onClick: show,
onBlur: hide,
onClick: handleAnchorClick,
onBlur: handleBlur,
onKeyDown: handleKeyDown,
onKeyUp: handleKeyUp,
})}
Expand Down
Loading