Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: Some TypeaheadSelect and MultiTypeaheadSelect improvements #21482

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/lib/cockpit-components-multi-typeahead-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const MultiTypeaheadSelectBase: React.FunctionComponent<MultiTypeaheadSel
newSelectOptions = [
{
isAriaDisabled: true,
isDisabled: true,
content:
typeof noOptionsFoundMessage === 'string' ? noOptionsFoundMessage : noOptionsFoundMessage(inputValue),
value: NO_RESULTS
Expand Down
13 changes: 11 additions & 2 deletions pkg/lib/cockpit-components-typeahead-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ SOFTWARE.
done. And there is no visual nesting going on anyway. Keeping the
options a flat list is just all around easier.

- Support for a footer.

*/

/* eslint-disable */
Expand All @@ -88,6 +90,7 @@ import {
SelectList,
SelectOptionProps,
MenuToggle,
MenuFooter,
MenuToggleElement,
TextInputGroup,
TextInputGroupMain,
Expand Down Expand Up @@ -164,6 +167,8 @@ export interface TypeaheadSelectProps extends Omit<SelectProps, 'toggle' | 'onSe
noOptionsFoundMessage?: string | ((filter: string) => string);
/** Flag indicating the select should be disabled. */
isDisabled?: boolean;
/** Optional footer */
footer?: React.ReactNode;
/** Width of the toggle. */
toggleWidth?: string;
/** Additional props passed to the toggle. */
Expand Down Expand Up @@ -208,6 +213,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
isCreateOptionOnTop = false,
createOptionMessage = "",
isDisabled = false,
footer = null,
toggleWidth,
toggleProps,
...props
Expand Down Expand Up @@ -268,6 +274,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
newSelectOptions = [
{
isAriaDisabled: true,
isDisabled: true,
content:
typeof noOptionsFoundMessage === 'string' ? noOptionsFoundMessage : noOptionsFoundMessage(filterValue),
value: NO_RESULTS
Expand All @@ -281,6 +288,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
newSelectOptions = [
{
isAriaDisabled: true,
isDisabled: true,
content: noOptionsAvailableMessage,
value: NO_RESULTS
}
Expand Down Expand Up @@ -310,7 +318,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>

const setActiveAndFocusedItem = (itemIndex: number) => {
setFocusedItemIndex(itemIndex);
const focusedItem = selectOptions[itemIndex] as TypeaheadSelectMenuOption;
const focusedItem = filteredSelections[itemIndex] as TypeaheadSelectMenuOption;
setActiveItemId(String(focusedItem.value));
};

Expand Down Expand Up @@ -378,7 +386,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>

openMenu();

if (filteredSelections.every(o => !isMenu(o))) {
if (filteredSelections.every(o => !isEnabledMenu(o))) {
return;
}

Expand Down Expand Up @@ -535,6 +543,7 @@ export const TypeaheadSelectBase: React.FunctionComponent<TypeaheadSelectProps>
);
})}
</SelectList>
{ footer && <MenuFooter>{footer}</MenuFooter> }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

</Select>
);
};
Expand Down
Loading