Skip to content

Commit 14e0a33

Browse files
author
小豪
committed
feat: support overriding default component behavior for the onBlur event in tags mode
1 parent ca86130 commit 14e0a33

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Select.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ export interface SelectProps<ValueType = any, OptionType extends BaseOptionType
162162
defaultValue?: ValueType | null;
163163
maxCount?: number;
164164
onChange?: (value: ValueType, option: OptionType | OptionType[]) => void;
165+
166+
// >>> tags mode only
167+
onBlurRemoveSpace?: boolean;
168+
onBlurAddValue?: boolean;
165169
}
166170

167171
function isRawValue(value: DraftValueType): value is RawValueType {
@@ -211,6 +215,10 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
211215
onChange,
212216
maxCount,
213217

218+
// tags mode only
219+
onBlurRemoveSpace = true,
220+
onBlurAddValue = true,
221+
214222
...restProps
215223
} = props;
216224

@@ -575,15 +583,16 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
575583

576584
// [Submit] Tag mode should flush input
577585
if (info.source === 'submit') {
578-
const formatted = (searchText || '').trim();
586+
const formatted = onBlurRemoveSpace ? (searchText || '').trim() : searchText || '';
579587
// prevent empty tags from appearing when you click the Enter button
580-
if (formatted) {
588+
if (formatted && onBlurAddValue) {
581589
const newRawValues = Array.from(new Set<RawValueType>([...rawValues, formatted]));
582590
triggerChange(newRawValues);
583591
triggerSelect(formatted, true);
584-
setSearchValue('');
585592
}
586593

594+
setSearchValue('');
595+
587596
return;
588597
}
589598

0 commit comments

Comments
 (0)