From e4db1e6b164e84ce8ae3e326d299baf755178c85 Mon Sep 17 00:00:00 2001 From: Allen Hansen Date: Tue, 2 Apr 2024 11:06:41 -0400 Subject: [PATCH 1/3] Update reference URL in getCollectionProps comments The reference URL in the getCollectionProps helper function documentation was outdated and incorrect. This commit updates the URL in the documentation comments to correctly point to the getCollectionProps section of the conform guide, enhancing code readability and understanding. --- packages/conform-react/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/conform-react/helpers.ts b/packages/conform-react/helpers.ts index 2dc9693c..984af123 100644 --- a/packages/conform-react/helpers.ts +++ b/packages/conform-react/helpers.ts @@ -340,7 +340,7 @@ export function getTextareaProps( * Derives the properties of a collection of checkboxes or radio buttons based on the field metadata, * including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby` and `required`. * - * @see https://conform.guide/api/react/getTextareaProps + * @see https://conform.guide/api/react/getCollectionProps * @example * ```tsx *
From 9a826d80eb451a9d7b790be770c0c39d4703f7ea Mon Sep 17 00:00:00 2001 From: Allen Hansen Date: Tue, 2 Apr 2024 11:40:44 -0400 Subject: [PATCH 2/3] Narrow the `type` prop returned from the `getCollectionProps` helper Update the type definitions for the `getCollectionProps` helper to fix widening issues with the `type` prop that is returned. --- packages/conform-react/helpers.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/conform-react/helpers.ts b/packages/conform-react/helpers.ts index 984af123..ca9c0478 100644 --- a/packages/conform-react/helpers.ts +++ b/packages/conform-react/helpers.ts @@ -363,9 +363,7 @@ export function getCollectionProps< | boolean | undefined | unknown, ->( - metadata: FieldMetadata, - options: Pretty< + Options extends Pretty< FormControlOptions & { /** * The input type. Use `checkbox` for multiple selection or `radio` for single selection. @@ -381,7 +379,12 @@ export function getCollectionProps< value?: boolean; } >, -): Array, 'type' | 'value'>> { +>( + metadata: FieldMetadata, + options: Options, +): Array< + InputProps & { type: Options['type'] } & Pick, 'value'> +> { return options.options.map((value) => simplify({ ...getFormControlProps(metadata, options), From 127164d943b75e38e477cb8e61ee610e7974bbcf Mon Sep 17 00:00:00 2001 From: Allen Hansen Date: Tue, 2 Apr 2024 12:27:49 -0400 Subject: [PATCH 3/3] Simplify `getCollectionProps` helper function return type definition using `Pick` --- packages/conform-react/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/conform-react/helpers.ts b/packages/conform-react/helpers.ts index ca9c0478..19187390 100644 --- a/packages/conform-react/helpers.ts +++ b/packages/conform-react/helpers.ts @@ -383,7 +383,7 @@ export function getCollectionProps< metadata: FieldMetadata, options: Options, ): Array< - InputProps & { type: Options['type'] } & Pick, 'value'> + InputProps & Pick & Pick, 'value'> > { return options.options.map((value) => simplify({