From 004b8dcf3419ccd0e6a75c031f67e40560d802ee Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Mon, 15 Apr 2024 18:17:15 +0200 Subject: [PATCH] Omit `nullable` prop from `Combobox` component (#3100) * ensure we pluck out the `nullable` prop from the props This should help improve migrating to v2 because otherwise the `nullable` prop (that doesn't do anything) could end up on the `Fragment` and cause errors. * update changelog * add test to ensure `` doesn't crash --- packages/@headlessui-react/CHANGELOG.md | 1 + .../src/components/combobox/combobox.test.tsx | 27 ++++++++++++++++++- .../src/components/combobox/combobox.tsx | 3 +++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/@headlessui-react/CHANGELOG.md b/packages/@headlessui-react/CHANGELOG.md index d74d9a8547..7b77146cd5 100644 --- a/packages/@headlessui-react/CHANGELOG.md +++ b/packages/@headlessui-react/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix enter transitions for the `Transition` component ([#3074](https://github.com/tailwindlabs/headlessui/pull/3074)) - Render hidden form input fields for `Checkbox`, `Switch` and `RadioGroup` components ([#3095](https://github.com/tailwindlabs/headlessui/pull/3095)) - Ensure the `multiple` prop is typed correctly when passing explicit types to the `Combobox` component ([#3099](https://github.com/tailwindlabs/headlessui/pull/3099)) +- Omit `nullable` prop from `Combobox` component ([#3100](https://github.com/tailwindlabs/headlessui/pull/3100)) ### Changed diff --git a/packages/@headlessui-react/src/components/combobox/combobox.test.tsx b/packages/@headlessui-react/src/components/combobox/combobox.test.tsx index 76d4dfc0d0..6da3f5eeba 100644 --- a/packages/@headlessui-react/src/components/combobox/combobox.test.tsx +++ b/packages/@headlessui-react/src/components/combobox/combobox.test.tsx @@ -1,5 +1,5 @@ import { render } from '@testing-library/react' -import React, { createElement, useEffect, useState } from 'react' +import React, { Fragment, createElement, useEffect, useState } from 'react' import { ComboboxMode, ComboboxState, @@ -575,6 +575,31 @@ describe('Rendering', () => { assertComboboxList({ state: ComboboxState.InvisibleUnmounted }) }) ) + + it( + 'should not crash when the `Combobox` still contains a `nullable` prop', + suppressConsoleLogs(async () => { + let data = [ + { id: 1, name: 'alice', label: 'Alice' }, + { id: 2, name: 'bob', label: 'Bob' }, + { id: 3, name: 'charlie', label: 'Charlie' }, + ] + + render( + + + + + {data.map((person) => ( + + {person.label} + + ))} + + + ) + }) + ) }) describe('Combobox.Input', () => { diff --git a/packages/@headlessui-react/src/components/combobox/combobox.tsx b/packages/@headlessui-react/src/components/combobox/combobox.tsx index 7eb136277c..cacee2b0a2 100644 --- a/packages/@headlessui-react/src/components/combobox/combobox.tsx +++ b/packages/@headlessui-react/src/components/combobox/combobox.tsx @@ -608,6 +608,9 @@ function ComboboxFn(