Skip to content

Commit

Permalink
Improvements to the TypeaheadSelect template (#11153)
Browse files Browse the repository at this point in the history
* Avoid "any" type in TypeaheadSelect template

* Don't show "Clear" button without onClearSelection function

If there is no such function, nothing will change when clicking that
button, and it is less confusing to not show it in that case.

* Fix TypeScript error in TypeaheadSelect

This one:

# pkg/lib/cockpit-components-typeahead-select.tsx:406:6 - error TS2375: Type '{ children: Element; className?: string; isExpanded: boolean; isDisabled: boolean | undefined; isFullHeight?: boolean; isFullWidth: boolean; splitButtonOptions?: SplitButtonOptions; ... 281 more ...; ref: Ref<...>; }' is not assignable to type 'MenuToggleProps' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
#   Types of property 'isDisabled' are incompatible.
#     Type 'boolean | undefined' is not assignable to type 'boolean'.
#       Type 'undefined' is not assignable to type 'boolean'.
  • Loading branch information
mvollmer authored Nov 14, 2024
1 parent 9207e1e commit 0bdb559
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface TypeaheadSelectOption extends Omit<SelectOptionProps, 'content'

export interface TypeaheadSelectProps extends Omit<SelectProps, 'toggle' | 'onSelect'> {
/** @hide Forwarded ref */
innerRef?: React.Ref<any>;
innerRef?: React.Ref<HTMLDivElement>;
/** Options of the select */
selectOptions: TypeaheadSelectOption[];
/** Callback triggered on selection. */
Expand Down Expand Up @@ -325,7 +325,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
aria-label="Typeahead menu toggle"
onClick={onToggleClick}
isExpanded={isOpen}
isDisabled={isDisabled}
isDisabled={isDisabled || false}
isFullWidth
style={
{
Expand All @@ -349,7 +349,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
aria-controls="select-typeahead-listbox"
/>
<TextInputGroupUtilities
{...(!(isFiltering && filterValue) && !selected ? { style: { display: 'none' } } : {})}
{...(!(isFiltering && filterValue) && !(selected && onClearSelection) ? { style: { display: 'none' } } : {})}
>
<Button variant="plain" onClick={onClearButtonClick} aria-label="Clear input value">
<TimesIcon aria-hidden />
Expand Down Expand Up @@ -386,7 +386,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
};
TypeaheadSelectBase.displayName = 'TypeaheadSelectBase';

export const TypeaheadSelect = React.forwardRef((props: TypeaheadSelectProps, ref: React.Ref<any>) => (
export const TypeaheadSelect = React.forwardRef((props: TypeaheadSelectProps, ref: React.Ref<HTMLDivElement>) => (
<TypeaheadSelectBase {...props} innerRef={ref} />
));

Expand Down

0 comments on commit 0bdb559

Please sign in to comment.