Skip to content

Commit 93dda54

Browse files
harry-igniteclaude
andauthored
[@mantine/core] Add openOnFocus prop to Combobox based components (#5893, #8623)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent aae37c9 commit 93dda54

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

packages/@mantine/core/src/components/Autocomplete/Autocomplete.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ export interface AutocompleteProps
7171

7272
/** If set, the highlighted option is selected when the input loses focus @default `false` */
7373
autoSelectOnBlur?: boolean;
74+
75+
/** If set, the dropdown opens when the input receives focus @default `true` */
76+
openOnFocus?: boolean;
7477
}
7578

7679
export type AutocompleteFactory = Factory<{
@@ -119,6 +122,7 @@ export const Autocomplete = factory<AutocompleteFactory>((_props, ref) => {
119122
clearable,
120123
rightSection,
121124
autoSelectOnBlur,
125+
openOnFocus = true,
122126
attributes,
123127
...others
124128
} = props;
@@ -214,7 +218,7 @@ export const Autocomplete = factory<AutocompleteFactory>((_props, ref) => {
214218
selectFirstOptionOnChange && combobox.selectFirstOption();
215219
}}
216220
onFocus={(event) => {
217-
combobox.openDropdown();
221+
openOnFocus && combobox.openDropdown();
218222
onFocus?.(event);
219223
}}
220224
onBlur={(event) => {

packages/@mantine/core/src/components/MultiSelect/MultiSelect.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ export interface MultiSelectProps
111111

112112
/** Clear search value when item is selected */
113113
clearSearchOnChange?: boolean;
114+
115+
/** If set, the dropdown opens when the input receives focus @default `true` */
116+
openOnFocus?: boolean;
114117
}
115118

116119
export type MultiSelectFactory = Factory<{
@@ -125,6 +128,7 @@ const defaultProps = {
125128
checkIconPosition: 'left',
126129
hiddenInputValuesDivider: ',',
127130
clearSearchOnChange: true,
131+
openOnFocus: true,
128132
size: 'sm',
129133
} satisfies Partial<MultiSelectProps>;
130134

@@ -207,6 +211,7 @@ export const MultiSelect = factory<MultiSelectFactory>((_props, ref) => {
207211
chevronColor,
208212
attributes,
209213
clearSearchOnChange,
214+
openOnFocus,
210215
...others
211216
} = props;
212217

@@ -431,7 +436,7 @@ export const MultiSelect = factory<MultiSelectFactory>((_props, ref) => {
431436
unstyled={unstyled}
432437
onFocus={(event) => {
433438
onFocus?.(event);
434-
searchable && combobox.openDropdown();
439+
openOnFocus && searchable && combobox.openDropdown();
435440
}}
436441
onBlur={(event) => {
437442
onBlur?.(event);

packages/@mantine/core/src/components/Select/Select.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ export interface SelectProps
9797

9898
/** If set, the highlighted option is selected when the input loses focus @default `false` */
9999
autoSelectOnBlur?: boolean;
100+
101+
/** If set, the dropdown opens when the input receives focus @default `true` */
102+
openOnFocus?: boolean;
100103
}
101104

102105
export type SelectFactory = Factory<{
@@ -110,6 +113,7 @@ const defaultProps = {
110113
withCheckIcon: true,
111114
allowDeselect: true,
112115
checkIconPosition: 'left',
116+
openOnFocus: true,
113117
} satisfies Partial<SelectProps>;
114118

115119
export const Select = factory<SelectFactory>((_props, ref) => {
@@ -168,6 +172,7 @@ export const Select = factory<SelectFactory>((_props, ref) => {
168172
__clearable,
169173
chevronColor,
170174
autoSelectOnBlur,
175+
openOnFocus,
171176
attributes,
172177
...others
173178
} = props;
@@ -339,7 +344,7 @@ export const Select = factory<SelectFactory>((_props, ref) => {
339344
selectFirstOptionOnChange && combobox.selectFirstOption();
340345
}}
341346
onFocus={(event) => {
342-
!!searchable && combobox.openDropdown();
347+
openOnFocus && !!searchable && combobox.openDropdown();
343348
onFocus?.(event);
344349
}}
345350
onBlur={(event) => {

packages/@mantine/core/src/components/TagsInput/TagsInput.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ export interface TagsInputProps
106106

107107
/** Custom function to determine if a tag is duplicate. Accepts tag value and array of current values. By default, checks if the tag exists case-insensitively. */
108108
isDuplicate?: (value: string, currentValues: string[]) => boolean;
109+
110+
/** If set, the dropdown opens when the input receives focus @default `true` */
111+
openOnFocus?: boolean;
109112
}
110113

111114
export type TagsInputFactory = Factory<{
@@ -119,6 +122,7 @@ const defaultProps = {
119122
acceptValueOnBlur: true,
120123
splitChars: [','],
121124
hiddenInputValuesDivider: ',',
125+
openOnFocus: true,
122126
size: 'sm',
123127
} satisfies Partial<TagsInputProps>;
124128

@@ -197,6 +201,7 @@ export const TagsInput = factory<TagsInputFactory>((_props, ref) => {
197201
scrollAreaProps,
198202
acceptValueOnBlur,
199203
isDuplicate,
204+
openOnFocus,
200205
attributes,
201206
...others
202207
} = props;
@@ -457,7 +462,7 @@ export const TagsInput = factory<TagsInputFactory>((_props, ref) => {
457462
onKeyDown={handleInputKeydown}
458463
onFocus={(event) => {
459464
onFocus?.(event);
460-
combobox.openDropdown();
465+
openOnFocus && combobox.openDropdown();
461466
}}
462467
onBlur={(event) => {
463468
onBlur?.(event);

0 commit comments

Comments
 (0)