How to implement Label for AbstractSinglePropertyField

I am extending AbstractSinglePropertyField to wrap a Web Component with Java API. How do you implement a Label (caption) for this component?

Code is available at [Github]

Hi Syam, Here is a link for the [tutorial]
( on how to use the AbstractSinglePropertyField

i hope this one will help you. comment more if you still have any doubt about it.

Hi Zhe Sun,
Thank you for your response (Sorry, I was away for the last couple of days).
I had read that article before but that doesn’t say anything about adding a ‘label’ to a component.
I could make my component Composite and add a ‘div’ element to create a label.

I can see that labels in components like TextField, ComboBox etc. are not interpreted properly in FormLayout (FormLayout requires FormItem to be added if labels have to be rendered).

I was thinking about a HasLabel interface (like HasValue).

public interface HasLabel {
	public void setLabel(String label);
	public String getLabel();

Layouts such as FormLayout can check if the component getting added has this interface implemented or not and renders the label accordingly.

Hi Syam,

There is one thing i am not really sure about the label for the webcomponent [iron-autogrow-textarea]
( itself. I have tried to add a label to the webcomponent via using dev-tool on chrome, but even i have put the label attribute in, it is still no label shown. Then i found an issue in the github repo, which is [Added aria label to element]

i am not sure if it is related to your issue or not.


Hi Zhe,
If we set the label attribute in iron-autogrow-textarea, it’s set as aria-label and is useful for assistive technology (e.g. screen reader) only. What I want is to use setLabel(...) to behave like setLabel in TextField.

Hi Syam,

if i understand your issue properly, the problem at the moment is after you have used setLabel(), the label is not shown in the UI, right?

So, in this case, what i mean/suppose is the webcomponent itself wont show the label, but it works only as an attribute. i have checked your code and the demo, as we can see there, the getter can properly get the label properly, which means the property has been set correctly.

there is one easy way to test: open the demo of iron-autogrow-textarea, pick up one component demo and try to add label to the dom structure. That is why i have mentioned the component in the last message. Maybe the issue one kinda confuse you.



Hi Zhe,

Yes, you are right, setting label doesn’t set the real label. I can see that it’s not there in the #shadow-root of that element. So, we need to wrap it with some container to have the label.