fix: close select dropdpwn when parent compoment is changed (#18950)

* fix: close select dropdpwn when parent compoment is changed

* code fixes

---------

Co-authored-by: Chirag Madlani <12962843+chirag-madlani@users.noreply.github.com>
This commit is contained in:
Kenil Shah 2024-12-09 11:12:22 +05:30 committed by GitHub
parent 6ec5d0cbdd
commit 81635db28a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -286,6 +286,13 @@ const AsyncSelectList: FC<AsyncSelectListProps & SelectProps> = ({
onChange?.(selectedValues);
};
const handleDropdownChange = (open: boolean) => {
if (!open) {
// Close the form when the dropdown closes
onCancel && onCancel();
}
};
useEffect(() => {
loadOptions('');
}, []);
@ -314,6 +321,7 @@ const AsyncSelectList: FC<AsyncSelectListProps & SelectProps> = ({
style={{ width: '100%' }}
tagRender={customTagRender}
onChange={handleChange}
onDropdownVisibleChange={handleDropdownChange}
onInputKeyDown={(event) => {
if (event.key === 'Backspace') {
return event.stopPropagation();

View File

@ -267,6 +267,13 @@ const TreeAsyncSelectList: FC<Omit<AsyncSelectListProps, 'fetchOptions'>> = ({
}
}, 300);
const handleDropdownChange = (open: boolean) => {
if (!open) {
// Close the form when the dropdown closes
onCancel && onCancel();
}
};
useEffect(() => {
if (glossaries.length) {
expandableKeys.current = glossaries.map((glossary) => glossary.id);
@ -327,6 +334,7 @@ const TreeAsyncSelectList: FC<Omit<AsyncSelectListProps, 'fetchOptions'>> = ({
treeData={treeData}
treeExpandedKeys={isEmpty(searchOptions) ? undefined : expandedRowKeys}
onChange={handleChange}
onDropdownVisibleChange={handleDropdownChange}
onSearch={onSearch}
onTreeExpand={setExpandedRowKeys}
{...props}