minimalcomps-openfl
minimalcomps-openfl copied to clipboard
Fix ComboBox bug
Current implementation create ComboBox that contains List of ListItems wich data is ListItem too. I think this is just a typo.
@freem-trg Hi, thanks for the pull request.
MinimalComps documentation does state that a List contains:
strings or objects with label property
Is that your use case? You are attempting to pass String or Dynamic object with label property instead of ListItem?
Yes. I want to use it with Array<String> or Array<EnumValue>. But signature of the class constructor and items setter want items:Array<ListItem>. And there is no way to pass Array<String> as in the documentation.
I've tried to create this array manually. But after that ComboBox shows something like this:
Select item: [+] [item ListItem] [item ListItem] ...
The problem is that ComboBox passed the _items to the List component. And List create its own ListItems (see List:111) and after it set passed _items as data (see List:128). After this ListItem casts his data to String.
That seems strange - have you compared your implementation to the MinimalComps Designer project?
_comboBox.defaultLabel = "Default label";
_comboBox.addItem({label: "Item 1"});
_comboBox.addItem({label: "Item 2"});
_comboBox.addItem({label: "Item 3"});
Hm, i missed this method. I'm sure it will work, because it is calls _list.addItem(item); directly. But if i want to pass my items via constructor args or items setter i will have problems because they take items:Array<ListItem>. My PR fix this case.
This makes sense from the constructor, but I'm not sure I like the private internal data structure set to dynamic. Let me think about this, and prototype these changes.
Yes, i'm usually avoid of using Dynamic too.
Another way is to remove items argument from constructor and don't keep this data in ComboBox: private var _items and use ComboBox.addItem instead of it. I think it can be good solution too.