From 46c9d28b972ad63dd9ce334b1d052b76fa5720ec Mon Sep 17 00:00:00 2001 From: Angelina Gadzhieva Date: Tue, 24 Dec 2024 14:47:11 +0300 Subject: [PATCH] feat(Select): add data for option group (#2011) --- src/components/Select/types.ts | 1 + src/components/Select/utils.tsx | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Select/types.ts b/src/components/Select/types.ts index 7f88949748..37253cd7cb 100644 --- a/src/components/Select/types.ts +++ b/src/components/Select/types.ts @@ -176,6 +176,7 @@ export type SelectOptionGroup = { /** 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[]; children?: | React.ReactElement diff --git a/src/components/Select/utils.tsx b/src/components/Select/utils.tsx index a0f7e8d9bb..5915485248 100644 --- a/src/components/Select/utils.tsx +++ b/src/components/Select/utils.tsx @@ -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 = {label: string; disabled: true; data?: T}; export type FlattenOption = SelectOption | GroupTitleItem; @@ -38,7 +38,7 @@ export const isSelectGroupTitle = ( export const getFlattenOptions = (options: SelectOptions): FlattenOptions => { const flatten = options.reduce((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);