Skip to content

Commit

Permalink
fix(MultiSelect): remove unnecessary timeout to open overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkyrylo committed Sep 17, 2024
1 parent 6070e69 commit c84d37d
Showing 1 changed file with 67 additions and 65 deletions.
132 changes: 67 additions & 65 deletions components/lib/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,93 +285,93 @@ export const MultiSelect = React.memo(
const metaKey = event.metaKey || event.ctrlKey;

switch (event.code) {
case 'ArrowUp':
if (props.inline) {
break;
}

onArrowUpKey(event);
case 'ArrowUp':
if (props.inline) {
break;
}

case 'ArrowDown':
if (props.inline) {
break;
}

onArrowDownKey(event);
onArrowUpKey(event);
break;

case 'ArrowDown':
if (props.inline) {
break;
}

case 'Space':
case 'NumpadEnter':
case 'Enter':
if (props.inline) {
break;
}

onEnterKey(event);
break;
onArrowDownKey(event);

case 'Home':
if (props.inline) {
break;
}
break;

onHomeKey(event);
event.preventDefault();
case 'Space':
case 'NumpadEnter':
case 'Enter':
if (props.inline) {
break;
}

case 'End':
if (props.inline) {
break;
}
onEnterKey(event);
break;

onEndKey(event);
event.preventDefault();
case 'Home':
if (props.inline) {
break;
}

case 'PageDown':
onPageDownKey(event);
break;
onHomeKey(event);
event.preventDefault();
break;

case 'PageUp':
onPageUpKey(event);
case 'End':
if (props.inline) {
break;
}

case 'Escape':
if (props.inline) {
break;
}
onEndKey(event);
event.preventDefault();
break;

hide();
break;
case 'PageDown':
onPageDownKey(event);
break;

case 'Tab':
onTabKey(event);
break;
case 'PageUp':
onPageUpKey(event);
break;

case 'ShiftLeft':
case 'ShiftRight':
onShiftKey(event);
case 'Escape':
if (props.inline) {
break;
}

default:
if (event.code === 'KeyA' && metaKey) {
const value = visibleOptions.filter((option) => isValidOption(option)).map((option) => getOptionValue(option));
hide();
break;

updateModel(event, value, value);
case 'Tab':
onTabKey(event);
break;

event.preventDefault();
break;
}
case 'ShiftLeft':
case 'ShiftRight':
onShiftKey(event);
break;

if (!metaKey && ObjectUtils.isPrintableCharacter(event.key)) {
!overlayVisibleState && show();
searchOptions(event);
event.preventDefault();
}
default:
if (event.code === 'KeyA' && metaKey) {
const value = visibleOptions.filter((option) => isValidOption(option)).map((option) => getOptionValue(option));

updateModel(event, value, value);

event.preventDefault();
break;
}

if (!metaKey && ObjectUtils.isPrintableCharacter(event.key)) {
!overlayVisibleState && show();
searchOptions(event);
event.preventDefault();
}

break;
}

setClicked(false);
Expand Down Expand Up @@ -961,9 +961,11 @@ export const MultiSelect = React.memo(
}, [inputRef, props.inputRef]);

React.useEffect(() => {
setTimeout(() => {
props.overlayVisible ? show() : hide();
}, 100);
if (props.overlayVisible) {
show();
} else {
hide();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.overlayVisible]);

Expand Down

0 comments on commit c84d37d

Please sign in to comment.