From 750ca4f863132f5da0962b1a75d5bfb31273bd9a Mon Sep 17 00:00:00 2001 From: Haider Alshamma Date: Thu, 9 May 2024 15:38:09 -0400 Subject: [PATCH] fix: remove all generics from NDSSelect react-windowed-select does not forward > downstream to the react-select resulting in mismatches between the expected types (defaulting to unknown) and the actual types inferred by react-select. This caused a problem for both the onChange and the custom components. --- src/Select/Select.tsx | 52 ++++++++++++++++++--------------- src/Select/SelectComponents.tsx | 26 +++++++++++------ src/Select/SelectOption.tsx | 8 ++--- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/Select/Select.tsx b/src/Select/Select.tsx index 6df598995..dd3122103 100644 --- a/src/Select/Select.tsx +++ b/src/Select/Select.tsx @@ -1,6 +1,6 @@ import React, { forwardRef, ReactNode, MutableRefObject } from "react"; import Select from "react-select/base"; -import WindowedSelect, { GroupBase } from "react-windowed-select"; +import WindowedSelect from "react-windowed-select"; import type { Props as SelectProps } from "react-select"; import { useTranslation } from "react-i18next"; import { useTheme } from "styled-components"; @@ -10,7 +10,6 @@ import { MaybeFieldLabel } from "../FieldLabel"; import { InlineValidation } from "../Validation"; import customStyles from "../Select/customReactSelectStyles"; import { getSubset } from "../utils/subset"; -import { SelectControl } from "../AsyncSelect/AsyncSelectComponents"; import { ComponentSize, useComponentSize } from "../NDSProvider/ComponentSizeContext"; import { SelectMultiValue, @@ -19,37 +18,39 @@ import { SelectInput, SelectDropdownIndicator, SelectMenu, + SelectControl, } from "./SelectComponents"; import { SelectOption } from "./SelectOption"; +import { checkOptionsAreValid, getReactSelectValue } from "./lib"; -interface WindowedSelectProps> - extends SelectProps { +interface WindowedSelectProps extends SelectProps { windowThreshold: number; } -type CustomProps> = { - autocomplete?: WindowedSelectProps["isSearchable"]; +type CustomProps = { + autocomplete?: WindowedSelectProps["isSearchable"]; labelText?: string; size?: ComponentSize; requirementText?: string; helpText?: ReactNode; - disabled?: WindowedSelectProps["isDisabled"]; + disabled?: WindowedSelectProps["isDisabled"]; errorMessage?: string; errorList?: string[]; - initialIsOpen?: WindowedSelectProps["defaultMenuIsOpen"]; - multiselect?: WindowedSelectProps["isMulti"]; + initialIsOpen?: WindowedSelectProps["defaultMenuIsOpen"]; + multiselect?: WindowedSelectProps["isMulti"]; maxHeight?: string; - defaultValue?: WindowedSelectProps["defaultInputValue"]; + defaultValue?: WindowedSelectProps["defaultInputValue"]; + value?: string; }; -export type NDSSelectProps> = Omit< - WindowedSelectProps, - "isSearchable" | "isDisabled" | "isMulti" | "defaultMenuIsOpen" | "defaultInputValue" +export type NDSSelectProps = Omit< + WindowedSelectProps, + "isSearchable" | "isDisabled" | "isMulti" | "defaultMenuIsOpen" | "defaultInputValue" | "value" > & - CustomProps; + CustomProps; const NDSSelect = forwardRef( - >( + ( { size, autocomplete, @@ -84,29 +85,33 @@ const NDSSelect = forwardRef( "aria-label": ariaLabel, windowThreshold = 100, ...props - }: NDSSelectProps, - ref: - | ((instance: Select | null) => void) - | MutableRefObject | null> - | null + }: NDSSelectProps, + ref: ((instance: Select | null) => void) | MutableRefObject