You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2023/01/10 12:02:49 UTC
[myfaces-tobago] branch main updated: fix(badge): add missing data attribute support (#3626)
This is an automated email from the ASF dual-hosted git repository.
lofwyr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/main by this push:
new 17203f9317 fix(badge): add missing data attribute support (#3626)
17203f9317 is described below
commit 17203f9317920fc566bbeddb34ba4ed34cbe0f38
Author: Bernd Bohmann <bo...@apache.org>
AuthorDate: Tue Jan 10 13:02:42 2023 +0100
fix(badge): add missing data attribute support (#3626)
issue: TOBAGO-2185
---
.../internal/renderkit/renderer/BadgeRenderer.java | 3 ++-
.../renderkit/renderer/BadgeRendererUnitTest.java | 11 +++++++++++
.../renderer/badge/badge-data-attribute.html | 19 +++++++++++++++++++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeRenderer.java
index be27fdde26..82ba2571b2 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeRenderer.java
@@ -21,6 +21,7 @@ package org.apache.myfaces.tobago.internal.renderkit.renderer;
import org.apache.myfaces.tobago.context.Markup;
import org.apache.myfaces.tobago.internal.component.AbstractUIBadge;
+import org.apache.myfaces.tobago.internal.util.HtmlRendererUtils;
import org.apache.myfaces.tobago.renderkit.RendererBase;
import org.apache.myfaces.tobago.renderkit.css.BootstrapClass;
import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
@@ -48,7 +49,7 @@ public class BadgeRenderer<T extends AbstractUIBadge> extends RendererBase<T> {
markup.contains(Markup.PILL) ? BootstrapClass.ROUNDED_PILL : null,
isInside(facesContext, HtmlElements.TOBAGO_BUTTONS) ? BootstrapClass.BTN : null,
component.getCustomClass());
-
+ HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
if (tip != null) {
writer.writeAttribute(HtmlAttributes.TITLE, tip, true);
}
diff --git a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeRendererUnitTest.java b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeRendererUnitTest.java
index a77f71ce7c..e106e8153d 100644
--- a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeRendererUnitTest.java
+++ b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/BadgeRendererUnitTest.java
@@ -40,4 +40,15 @@ public class BadgeRendererUnitTest extends RendererTestBase {
Assertions.assertEquals(loadHtml("renderer/badge/badge.html"), formattedResult());
}
+ @Test
+ public void badgeWithDataAttribute() throws IOException {
+ final UIBadge c = (UIBadge) ComponentUtils.createComponent(
+ facesContext, Tags.badge.componentType(), RendererTypes.Badge, "id");
+ c.setValue("Text");
+ ComponentUtils.putDataAttribute(c, "color", "#00ff00");
+ c.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/badge/badge-data-attribute.html"), formattedResult());
+ }
+
}
diff --git a/tobago-core/src/test/resources/renderer/badge/badge-data-attribute.html b/tobago-core/src/test/resources/renderer/badge/badge-data-attribute.html
new file mode 100644
index 0000000000..e8b53ba32f
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/badge/badge-data-attribute.html
@@ -0,0 +1,19 @@
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<tobago-badge id='id' class='badge' data-color='#00ff00'>Text
+</tobago-badge>