Is there a way to write `Modifier`s targeting spec...
# kobweb
n
Is there a way to write `Modifier`s targeting specific
AttrsScope
subtypes, like
InputAttrsScope
? For example configuring
TextInput()
using `Modifier`s, like:
TextInput(value = xyz, Modifier.onInput {...}.toAttrs())
?
d
Sadly this is a limitation of modifiers, and almost certainly the reason the JB APIs went with attrs blocks. It is worth noting that you can to
Modifier.a(...).b(...).toAttrs { ... }
and the
toAttrs
block will be appropriately typed.
1
🙏 1
The plan with Silk is to add a bunch of widgets that wrap the web and set the appropriate attributes for you
In fact, Silk provides Input and TextInput widgets! So you can see how those work
👀 1
c
You will be able to do this when context receivers are added:
Copy code
context(TextInputScope)
fun Modifier.b(…): Modifier { … }
d
The problem is there is no scope
I mean I might be missing something, which would be awesome
but imagine the select web widget
c
This is why AndroidX composables always introduce
RowScope
,
ColumnScope
, etc
d
Select(Modifier.....)
Those scopes ARE present in Kobweb too, but for the contents of the widget
Copy code
Select(...) {
  // this is SelectScope
}
c
I may have misunderstood the original question then, because I believe that scope would satisfy the requirement for child modifiers
d
Unless you can tag
context
onto regular parameters and not just methods / lambdas, I don't think there's a way to accomplish type-specific modifiers.
c
Ah no the question was about
AttrsInputScope
subtypes, not sub-components. Sorry for the noise.
d
No worries!