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

How to style every item differently in my dropdown? #246

Open
ainnotate opened this issue Feb 16, 2024 · 1 comment
Open

How to style every item differently in my dropdown? #246

ainnotate opened this issue Feb 16, 2024 · 1 comment

Comments

@ainnotate
Copy link

ainnotate commented Feb 16, 2024

I want to give a different background for every list item. I'm trying the following,

  const data = [
    { label: 'Item 1', value: '1' , itemContainerStyle: { backgroundColor: '#f6ede4'}, itemTextStyle: {color: '#fff'}},
    { label: 'Item 2', value: '2' , itemContainerStyle: { backgroundColor: '#a07e56'}, itemTextStyle: {color: '#fff'}},
    { label: 'Item 3', value: '3' , itemContainerStyle: { backgroundColor: '#3a312a'}, itemTextStyle: {color: '#fff'}},
  ];

<Dropdown 
  data={data}
  labelField="label"
  valueField="value"
  ...
  />

Please let me know if I'm doing something wrong. Thank you.

@mohammed0abbas
Copy link

const data = [
{ label: 'Item 1', value: '1' , backgroundColor: '#f6ede4', color: '#fff'},
{ label: 'Item 2', value: '2' , backgroundColor: '#a07e56', color: '#fff'},
{ label: 'Item 3', value: '3' , backgroundColor: '#3a312a', color: '#fff'},
];

return (<Dropdown
data={data}
labelField="label"
valueField="value"
renderItem={(item) => {
return (

                                        <Text style={{
                                            flex: 1,
                                            fontSize: 16,
                                             backgroundColor : item.backgroundColor,
                                             color : item.color
                                        }}>{item.label}</Text>

                                    </View>
                                );
                            }}

...
/>)

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