Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to override the type on the Combobox.Input #1476

Merged
merged 2 commits into from May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG.md
Expand Up @@ -7,11 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased - @headlessui/vue]

- Nothing yet!
### Fixed

- Allow to override the `type` on the `ComboboxInput` ([#1476](https://github.com/tailwindlabs/headlessui/pull/1476))

## [Unreleased - @headlessui/react]

- Nothing yet!
### Fixed

- Allow to override the `type` on the `Combobox.Input` ([#1476](https://github.com/tailwindlabs/headlessui/pull/1476))

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

Expand Down
Expand Up @@ -237,6 +237,31 @@ describe('Rendering', () => {
expect(getComboboxInput()).toHaveValue('B')
})
)

it(
'should be possible to override the `type` on the input',
suppressConsoleLogs(async () => {
function Example() {
let [value, setValue] = useState(undefined)

return (
<Combobox value={value} onChange={setValue}>
<Combobox.Input type="search" onChange={NOOP} />
<Combobox.Button>Trigger</Combobox.Button>
<Combobox.Options>
<Combobox.Option value="a">Option A</Combobox.Option>
<Combobox.Option value="b">Option B</Combobox.Option>
<Combobox.Option value="c">Option C</Combobox.Option>
</Combobox.Options>
</Combobox>
)
}

render(<Example />)

expect(getComboboxInput()).toHaveAttribute('type', 'search')
})
)
})

describe('Combobox.Label', () => {
Expand Down
Expand Up @@ -602,7 +602,6 @@ interface InputRenderPropArg {
type InputPropsWeControl =
| 'id'
| 'role'
| 'type'
| 'aria-labelledby'
| 'aria-expanded'
| 'aria-activedescendant'
Expand All @@ -622,7 +621,7 @@ let Input = forwardRefWithAs(function Input<
},
ref: Ref<HTMLInputElement>
) {
let { value, onChange, displayValue, ...theirProps } = props
let { value, onChange, displayValue, type = 'text', ...theirProps } = props
let [state] = useComboboxContext('Combobox.Input')
let data = useComboboxData()
let actions = useComboboxActions()
Expand Down Expand Up @@ -771,7 +770,7 @@ let Input = forwardRefWithAs(function Input<
ref: inputRef,
id,
role: 'combobox',
type: 'text',
type,
'aria-controls': state.optionsRef.current?.id,
'aria-expanded': state.disabled ? undefined : state.comboboxState === ComboboxStates.Open,
'aria-activedescendant':
Expand Down
24 changes: 24 additions & 0 deletions packages/@headlessui-vue/src/components/combobox/combobox.test.ts
Expand Up @@ -288,6 +288,30 @@ describe('Rendering', () => {
expect(getComboboxInput()).toHaveValue('B')
})
)

it(
'should be possible to override the `type` on the input',
suppressConsoleLogs(async () => {
let Example = defineComponent({
template: html`
<Combobox v-model="value">
<ComboboxInput type="search" />
<ComboboxButton>Trigger</ComboboxButton>
<ComboboxOptions>
<ComboboxOption value="a">Option A</ComboboxOption>
<ComboboxOption value="b">Option B</ComboboxOption>
<ComboboxOption value="c">Option C</ComboboxOption>
</ComboboxOptions>
</Combobox>
`,
setup: () => ({ value: ref(null) }),
})

renderTemplate(Example)

expect(getComboboxInput()).toHaveAttribute('type', 'search')
})
)
})

describe('ComboboxLabel', () => {
Expand Down
Expand Up @@ -746,7 +746,7 @@ export let ComboboxInput = defineComponent({
onChange: handleChange,
onInput: handleInput,
role: 'combobox',
type: 'text',
type: attrs.type ?? 'text',
tabIndex: 0,
ref: api.inputRef,
}
Expand Down