Automatic Pass through properties on Custom Components

Let’s say you have a simple Custom Component called a “LabelTextBox”, unsurprisingly composed of two components of type TextBox and Label.

As far as I understand, if I want to create a custom property (let’s say placeholder text on the TextBox) I have to manually wire up the getters and setters.

In the property configuration UI, I’d like some sort of option to select preexisting properties from the child components, and just have them available on the higher level component.

As far as the implementation, perhaps a fourth column after the existing “Property, Type, Default Value” columns could be added called “Wire to existing child property”. This would be a dropdown of the existing component hierarchy, where you can drill down, and select the appropriate property to auto wire to.

6 Likes

This makes way too much sense…

3 Likes

You may already know this, but I checked to confirm that it doesn’t work to just rig up data bindings on the child component:
image
That works to set the child property initially, but then updating self.label_text_box_1.placeholder with code does not update the child component.
https://anvil.works/build#clone:DZDERQPIFXBFBCOR=XON45XLCR62DAEFK6Z7YLS75

1 Like

I didn’t know that, but thank you for pointing it out!

edit: This option is already available, so I’ve changed the text below to reflect that.

It’s worth noting that the underlying components of a custom component are exposed in code (as is typical in Python), though their not visible in the Design tab. So, for instance, code using a custom component named self.label_text_box_1 can directly access self.label_text_box_1.text_box_1.placeholder. (But it’s probably not good practice since this introduces a form of coupling.)

1 Like

I second that, and would add pass through events to pass through properties.

3 Likes

Ehh… any news on this? Would really save everybody a bunch of time.

1 Like