-
Notifications
You must be signed in to change notification settings - Fork 29
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
Allow Listbox component to handle nullables #758
Comments
It is a design choice. I am only on mobile currently and also need some time to craft an understandable answer. So please stay tuned 😉 |
So the headless idea is to provide a common base of functionality for typical UI elements. A select menu has as base the "select 1 from many" semantic. But thinking about variants, three behaviors can be derived by this:
In order to support all three semantics, we have to be strict at the headless level. Other ways we could not support use case one. That said, you are totally free to model the other two cases on top of our headless Does this answer your question? |
But wouldn't full support of nullable types achieve all three use-cases for the component? 1. is fulfilled when a non-nullable type is provided (like in the Star Wars example for the component). 2. is fulfilled when a nullable type is provided with a default of Anyway, an easy solution to achieve my desired behaviour with the built-in val someTypeList = listOf(someTypeA, someTypeB, null)
val someTypeStore = storeOf<SomeType?>(null)
listbox<SomeType?> {
value(someTypeStore)
listboxItems {
someTypeList.forEach {
listboxItem(it) {
// Render some content
}
}
}
} I did this: val someTypeList = listOf(someTypeA, someTypeB, null)
val someTypeStore = storeOf<SomeType?>(null)
data class SomeTypeWrapper(val someType: SomeType?)
val lens = lensOf<SomeType?, SomeTypeWrapper>("", { SomeTypeWrapper(it) }, { _, it -> it.someType})
listbox<SomeTypeWrapper> {
value(someTypeStore.map(lens))
listboxItems {
someTypeList.map { SomeTypeWrapper(it) }.forEach {
listboxItem(it) {
// Render some content
}
}
}
} |
Currently the
Listbox
component doesn't play well with nullable types, due to the way theListboxEntries
are handled (an entry with a value ofnull
is treated the same a disabled entry and therefore ignored when clicked). In my opinion a nullable selection (that contains a "None" option at the end of the list of entries for example) is a very common use case though and should work with the component out of the box.Or is this a deliberate design choice (and if so, why)?
The text was updated successfully, but these errors were encountered: