From c2e3531eeb0744854f93fe90cbcf67d7f031c82b Mon Sep 17 00:00:00 2001 From: Knoobie Date: Fri, 23 Jun 2023 10:21:41 +0200 Subject: [PATCH] fix: add slot=label attribute as legit use-case for the deprecated Label (#17089) --- .../main/java/com/vaadin/flow/component/html/Label.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flow-html-components/src/main/java/com/vaadin/flow/component/html/Label.java b/flow-html-components/src/main/java/com/vaadin/flow/component/html/Label.java index 27a53d13ab4..2dd1c1694dc 100644 --- a/flow-html-components/src/main/java/com/vaadin/flow/component/html/Label.java +++ b/flow-html-components/src/main/java/com/vaadin/flow/component/html/Label.java @@ -15,6 +15,7 @@ */ package com.vaadin.flow.component.html; +import java.util.Objects; import java.util.Optional; import com.vaadin.flow.component.AttachEvent; @@ -150,8 +151,14 @@ protected void onAttach(AttachEvent attachEvent) { // Label was not associated with a for-attribute // AND // Label was not associated by adding a nested component + // AND + // Label has no attribute slot=label + // (used e.g. in flow-components/FormLayout) if (getFor().isEmpty() - && getChildren().findAny().isEmpty()) { + && getChildren().findAny().isEmpty() + && !Objects.equals( + getElement().getAttribute("slot"), + "label")) { LoggerFactory.getLogger(Label.class.getName()).warn( "The Label '{}' was not associated with a component. " + "Labels should not be used for loose text on the page. "