Skip to content

Commit 561a29f

Browse files
authored
feat(select): support search input autocomplete (#82)
Sync react-component/select#1250.
1 parent 38d7f13 commit 561a29f

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

packages/select/__tests__/select.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ describe('select react sync', () => {
1515
document.body.innerHTML = ''
1616
})
1717

18+
it('forwards autocomplete to the search input', () => {
19+
const wrapper = mount(Select, {
20+
props: {
21+
showSearch: true,
22+
autoComplete: 'organization-title',
23+
},
24+
})
25+
26+
expect(wrapper.find('input').attributes('autocomplete')).toBe('organization-title')
27+
expect(wrapper.attributes('autocomplete')).toBeUndefined()
28+
})
29+
1830
it('does not add has-value class when selected label is empty string', async () => {
1931
const wrapper = mount(Select, {
2032
attachTo: document.body,

packages/select/src/BaseSelect/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export interface BaseSelectProps extends BaseSelectPrivateProps {
138138
tagRender?: (props: CustomTagProps) => any
139139
direction?: 'ltr' | 'rtl'
140140
autoFocus?: boolean
141+
autoComplete?: string
141142
placeholder?: VueNode
142143
maxCount?: number
143144

packages/select/src/SelectInput/Input.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ const Input = defineComponent<InputProps>(
153153
const {
154154
prefixCls,
155155
autoFocus,
156+
autoComplete: contextAutoComplete,
156157
placeholder,
157158
} = selectInputContext.value ?? {}
158159
const { input: InputComponent = 'input' } = selectInputContext.value?.components ?? {}
@@ -170,7 +171,7 @@ const Input = defineComponent<InputProps>(
170171

171172
// ============================= Render =============================
172173
// Extract shared input props
173-
174+
174175
const sharedInputProps = {
175176
id,
176177
'type': 'text',
@@ -183,7 +184,7 @@ const Input = defineComponent<InputProps>(
183184
'--select-input-width': widthCssVar.value,
184185
},
185186
autoFocus,
186-
'autocomplete': autoComplete || 'new-password',
187+
'autocomplete': autoComplete ?? contextAutoComplete ?? 'new-password',
187188
'class': inputCls,
188189
disabled,
189190
'value': value || '',

packages/select/src/SelectInput/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface SelectInputProps {
4242
onSelectorRemove?: (value: DisplayValueType) => void
4343
maxLength?: number
4444
autoFocus?: boolean
45+
autoComplete?: string
4546
/** Check if `tokenSeparators` contains `\n` or `\r\n` */
4647
tokenWithEnter?: boolean
4748
// Add other props that need to be passed through
@@ -70,6 +71,7 @@ const DEFAULT_OMIT_PROPS = [
7071
'onPopupScroll',
7172
'tabIndex',
7273
'activeValue',
74+
'autoComplete',
7375
'onSelectorRemove',
7476
'focused',
7577
] as const

0 commit comments

Comments
 (0)