Skip to content

Commit 9280d92

Browse files
authored
Allow to override the type on the Combobox.Input (#1476)
* allow to override the `type` on the `Combobox.Input` This still defaults to `text`. * update changelog
1 parent 5f42488 commit 9280d92

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased - @headlessui/vue]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Allow to override the `type` on the `ComboboxInput` ([#1476](https://github.com/tailwindlabs/headlessui/pull/1476))
1113

1214
## [Unreleased - @headlessui/react]
1315

14-
- Nothing yet!
16+
### Fixed
17+
18+
- Allow to override the `type` on the `Combobox.Input` ([#1476](https://github.com/tailwindlabs/headlessui/pull/1476))
1519

1620
## [@headlessui/vue@v1.6.2] - 2022-05-19
1721

packages/@headlessui-react/src/components/combobox/combobox.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,31 @@ describe('Rendering', () => {
237237
expect(getComboboxInput()).toHaveValue('B')
238238
})
239239
)
240+
241+
it(
242+
'should be possible to override the `type` on the input',
243+
suppressConsoleLogs(async () => {
244+
function Example() {
245+
let [value, setValue] = useState(undefined)
246+
247+
return (
248+
<Combobox value={value} onChange={setValue}>
249+
<Combobox.Input type="search" onChange={NOOP} />
250+
<Combobox.Button>Trigger</Combobox.Button>
251+
<Combobox.Options>
252+
<Combobox.Option value="a">Option A</Combobox.Option>
253+
<Combobox.Option value="b">Option B</Combobox.Option>
254+
<Combobox.Option value="c">Option C</Combobox.Option>
255+
</Combobox.Options>
256+
</Combobox>
257+
)
258+
}
259+
260+
render(<Example />)
261+
262+
expect(getComboboxInput()).toHaveAttribute('type', 'search')
263+
})
264+
)
240265
})
241266

242267
describe('Combobox.Label', () => {

packages/@headlessui-react/src/components/combobox/combobox.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ interface InputRenderPropArg {
602602
type InputPropsWeControl =
603603
| 'id'
604604
| 'role'
605-
| 'type'
606605
| 'aria-labelledby'
607606
| 'aria-expanded'
608607
| 'aria-activedescendant'
@@ -622,7 +621,7 @@ let Input = forwardRefWithAs(function Input<
622621
},
623622
ref: Ref<HTMLInputElement>
624623
) {
625-
let { value, onChange, displayValue, ...theirProps } = props
624+
let { value, onChange, displayValue, type = 'text', ...theirProps } = props
626625
let [state] = useComboboxContext('Combobox.Input')
627626
let data = useComboboxData()
628627
let actions = useComboboxActions()
@@ -771,7 +770,7 @@ let Input = forwardRefWithAs(function Input<
771770
ref: inputRef,
772771
id,
773772
role: 'combobox',
774-
type: 'text',
773+
type,
775774
'aria-controls': state.optionsRef.current?.id,
776775
'aria-expanded': state.disabled ? undefined : state.comboboxState === ComboboxStates.Open,
777776
'aria-activedescendant':

packages/@headlessui-vue/src/components/combobox/combobox.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,30 @@ describe('Rendering', () => {
288288
expect(getComboboxInput()).toHaveValue('B')
289289
})
290290
)
291+
292+
it(
293+
'should be possible to override the `type` on the input',
294+
suppressConsoleLogs(async () => {
295+
let Example = defineComponent({
296+
template: html`
297+
<Combobox v-model="value">
298+
<ComboboxInput type="search" />
299+
<ComboboxButton>Trigger</ComboboxButton>
300+
<ComboboxOptions>
301+
<ComboboxOption value="a">Option A</ComboboxOption>
302+
<ComboboxOption value="b">Option B</ComboboxOption>
303+
<ComboboxOption value="c">Option C</ComboboxOption>
304+
</ComboboxOptions>
305+
</Combobox>
306+
`,
307+
setup: () => ({ value: ref(null) }),
308+
})
309+
310+
renderTemplate(Example)
311+
312+
expect(getComboboxInput()).toHaveAttribute('type', 'search')
313+
})
314+
)
291315
})
292316

293317
describe('ComboboxLabel', () => {

packages/@headlessui-vue/src/components/combobox/combobox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ export let ComboboxInput = defineComponent({
746746
onChange: handleChange,
747747
onInput: handleInput,
748748
role: 'combobox',
749-
type: 'text',
749+
type: attrs.type ?? 'text',
750750
tabIndex: 0,
751751
ref: api.inputRef,
752752
}

0 commit comments

Comments
 (0)