Skip to content

Commit e94d023

Browse files
authored
Fix chips input flicker issue after adding new chip (#1706)
1 parent d080195 commit e94d023

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/incubator/ChipsInput/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ const ChipsInput = (props: ChipsInputProps, refToForward: React.Ref<any>) => {
4242
const reachedMaximum = maxChips && chips?.length >= maxChips;
4343
if (fieldValue.current && !reachedMaximum) {
4444
const newChip = {label: fieldValue.current};
45-
onChange?.([...chips, newChip], ChipsInputChangeReason.Added, newChip);
4645
setMarkedForRemoval(undefined);
4746
// @ts-expect-error
4847
fieldRef.current.clear();
4948
fieldValue.current = '';
49+
/* NOTE: Delay change event to give clear field time to complete and avoid a flickering */
50+
setTimeout(() => {
51+
onChange?.([...chips, newChip], ChipsInputChangeReason.Added, newChip);
52+
}, 0);
5053
}
5154
}, [onChange, chips, maxChips]);
5255

0 commit comments

Comments
 (0)