Skip to content

Commit

Permalink
feat(Select): add data for option group (#2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunory authored Dec 24, 2024
1 parent aa6251c commit 46c9d28
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/Select/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export type SelectOptionGroup<T = any> = {
/** Label is a string which displayed above the options group.
* If label is empty string, group item height will be 0 and only border will be displayed */
label: string;
data?: T;
options?: SelectOption<T>[];
children?:
| React.ReactElement<SelectOption, typeof Option>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Select/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
} from './types';

// "disable" property needs to deactivate group title item in List
export type GroupTitleItem = {label: string; disabled: true};
export type GroupTitleItem<T = any> = {label: string; disabled: true; data?: T};

export type FlattenOption = SelectOption | GroupTitleItem;

Expand All @@ -38,7 +38,7 @@ export const isSelectGroupTitle = (
export const getFlattenOptions = (options: SelectOptions): FlattenOptions => {
const flatten = options.reduce<FlattenOption[]>((acc, option) => {
if ('label' in option) {
acc.push({label: option.label, disabled: true});
acc.push({label: option.label, disabled: true, data: option.data});
acc.push(...(option.options || []));
} else {
acc.push(option);
Expand Down

0 comments on commit 46c9d28

Please sign in to comment.