snehilvj / dash-mantine-components

Plotly Dash components based on Mantine React Components
https://www.dash-mantine-components.com
MIT License
577 stars 61 forks source link

SegmentedControl treats value 0 as falsey #58

Closed rick643charts closed 2 years ago

rick643charts commented 2 years ago

It appears that the SegmentedControl component is treating a value of 0 as falsey. For example:

dmc.SegmentedControl(id='test', data=[
    {'label': '0 Outs', 'value': 0},
    {'label': '1 Out', 'value': 1},
    {'label': '2 Outs', 'value': 2}
], size='sm', color='green', value=0),

Yields the following:

https://user-images.githubusercontent.com/76791595/157121104-ed451e81-9d65-4711-b73c-ef3f276aa7ba.mp4

snehilvj commented 2 years ago

Hi @rick643charts, this is because dmc.SegmentedControl expects value to be string. The reason you are not getting any type error is because dash does prop check only in debug mode. So if you develop apps with debug=True, you will see the error that value should be string.

rick643charts commented 2 years ago

Thanks for the reply @snehilvj. I suppose this is part of a larger discussion / feature request, as I've been restructuring some existing applications to leverage dash_mantine_components in place of dash_bootstrap_components and some core Dash components. Do you currently have plans to accommodate label-value object arrays that allow non-string-type values similar to the core Dash components? For example, it's often the case that Select component options (data prop) are populated directly from our relational database that relies heavily on integer-type object IDs.

Thus far my experience with the library has been great, you've done an incredible job accommodating numerous UI/UX use cases that were not adequately met by the existing libraries out there!

snehilvj commented 2 years ago

This change is somewhat dependent on the React library beneath dmc. I'll raise it in the Mantine's discord channel to see if Mantine will support this.