Skip to content

How do i get the title for list of options with multiple objects? #108

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

Open
Nulligma opened this issue May 4, 2025 · 1 comment
Open

Comments

@Nulligma
Copy link

Nulligma commented May 4, 2025

I have a long list of options like this

options={[
          {
            title:'Type',
            data: [
              {label: 'All', value: 'All'},
              {label: 'Daily', value: 'daily'},
              {label: 'Special', value: 'special'},
            ],
          },
          {
            title: 'Deity',
            data: Constants.public.Enums.Deity.map(deity => ({label: deity, value: deity})),
          },
          {
            title: 'Sampradaya',
            data: Constants.public.Enums.Sampradaya.map(sampradaya => ({label: sampradaya, value: sampradaya})),
          },
          {
            title: 'State',
            data: LOCAL.states.map(state => ({label: state, value: state})),
          },
]}

Is your feature request related to a problem? Please describe.
I have a long list of options divided into subsections and I would like to get title property of that option when that option is selected. Currently i only get the itemvalue like this

onValueChange={(itemValue: any) => setMenu(itemValue)}

Describe the solution you'd like
I would like to get option title as well so that I can sort my list better like this

onValueChange={(itemValue: any, itemTitle:string) => setMenu(itemTitle, itemValue)}

Additional context
Also is there a way to collapse all the sections inside the list? Since the option list becomes too long hence it difficult to scroll all the way to bottom

@azeezat
Copy link
Owner

azeezat commented May 5, 2025

Hello @Nulligma! You can write a utility function as shown below to extract the title from a given array

const getTitleByValue = (array, valueToFind)=> {
  for (const section of array) {
    if (section.data.some(item => item.value === valueToFind)) {
      return section.title;
    }
  }
  return null; // or throw an error if preferred
}

Let me know if this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants