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

Readonly select items prop #4977

Closed
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
4 changes: 2 additions & 2 deletions packages/select/src/common/itemListRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export interface IItemListRendererProps<T> {
* map each item in this array through `renderItem`, with support for
* optional `noResults` and `initialContent` states.
*/
filteredItems: T[];
filteredItems: readonly T[];

/**
* Array of all items in the list.
* See `filteredItems` for a filtered array based on `query` and predicate props.
*/
items: T[];
items: readonly T[];

/**
* The current query string.
Expand Down
2 changes: 1 addition & 1 deletion packages/select/src/common/listItemsProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface IListItemsProps<T> extends Props {
activeItem?: T | ICreateNewItem | null;

/** Array of items in the list. */
items: T[];
items: readonly T[];

/**
* Specifies how to test if two items are equal. By default, simple strict
Expand Down
2 changes: 1 addition & 1 deletion packages/select/src/common/predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* A custom predicate for returning an entirely new `items` array based on the provided query.
* See usage sites in `IListItemsProps`.
*/
export type ItemListPredicate<T> = (query: string, items: T[]) => T[];
export type ItemListPredicate<T> = (query: string, items: readonly T[]) => T[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing the types of callback arguments may cause compile breaks for consumers, but should be easily fixed, since if they were mutating this argument here, it was probably causing problems


/**
* A custom predicate for filtering items based on the provided query.
Expand Down
4 changes: 2 additions & 2 deletions packages/select/src/components/query-list/queryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export interface IQueryListState<T> {
createNewItem: T | undefined;

/** The original `items` array filtered by `itemListPredicate` or `itemPredicate`. */
filteredItems: T[];
filteredItems: readonly T[];

/** The current query string. */
query: string;
Expand Down Expand Up @@ -645,7 +645,7 @@ function isItemDisabled<T>(item: T | null, index: number, itemDisabled?: IListIt
* @param startIndex which index to begin moving from
*/
export function getFirstEnabledItem<T>(
items: T[],
items: readonly T[],
itemDisabled?: keyof T | ((item: T, index: number) => boolean),
direction = 1,
startIndex = items.length - 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/select/src/components/select/multiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export interface IMultiSelectProps<T> extends IListItemsProps<T> {
popoverProps?: Partial<IPopoverProps> & object;

/** Controlled selected values. */
selectedItems?: T[];
selectedItems?: readonly T[];

/** Props to spread to `TagInput`. Use `query` and `onQueryChange` to control the input. */
// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down