-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
XYZPropsWeControl
and cleanup internal TypeScript types (#2329)
* cleanup `XYZPropsWeControl` The idea behind the `PropsWeControl` is that we can omit all the fields that we are controlling entirely. In this case, passing a prop like `role`, but if we already set the role ourselves then the prop won't do anything at all. This is why we want to alert the end user that it is an "error". It can also happen that we "control" the value by default, but keep incoming props into account. For example we generate a unique ID for most components, but you can provide your own to override it. In this case we _don't_ want to include the ID in the `XYZPropsWeControl`. Additionally, we introduced some functionality months ago where we call event callbacks (`onClick`, ...) from the incoming props before our own callbacks. This means that by definition all `onXYZ` callbacks can be provided. * improve defining types Whenever we explicitly provide custom types for certain props, then we make sure to omit those keys first from the original props (of let's say an `input`). This is important so that TypeScript doesn't try to "merge" those types together. * cleanup: move `useEffect` * add `defaultValue` explicitly * ensure tests are not using `any` because of `onChange={console.log}` The `console.log` is typed as `(...args: any[]) => void` which means that it will incorrectly mark its incoming data as `any` as well. Converting it to `x => console.log(x)` makes TypeScript happy. Or in this case, angry since it found a bug. This is required because it _can_ be that your value (e.g.: the value of a Combobox) is an object (e.g.: a `User`), but it is also nullable. Therefore we can provide the value `null`. This would mean that eventually this resolves to `keyof null` which is `never`, but we just want a string in this case. ```diff -export type ByComparator<T> = (keyof T & string) | ((a: T, b: T) => boolean) +export type ByComparator<T> = + | (T extends null ? string : keyof T & string) + | ((a: T, b: T) => boolean) ``` * improve the internal types of the `Combobox` component * improve the internal types of the `Disclosure` component * improve the internal types of the `Listbox` component * improve the internal types of the `Menu` component * improve the internal types of the `Popover` component * improve the internal types of the `Tabs` component * improve the internal types of the `Transition` component * use `Override` in `Hidden` as well * cleanup unused code * don't check the `useSyncExternalStoreShimClient` * don't check the `useSyncExternalStoreShimServer` * improve types in the render tests * fix `Ref<TTag>` to be `Ref<HTMLElement>` * improve internal types of the `Transition` component (Vue) + add `attrs.class` as well * use different type for `AnyComponent` * update changelog
- Loading branch information
1 parent
948ae73
commit 989cd6b
Showing
23 changed files
with
386 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 109 additions & 109 deletions
218
packages/@headlessui-react/src/components/combobox/combobox.test.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.