You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2021/02/12 18:41:07 UTC
[tapestry-5] branch 5.6.x updated: TAP5-2662: FormGroup now
generates aria-labelledby in field
This is an automated email from the ASF dual-hosted git repository.
thiagohp pushed a commit to branch 5.6.x
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
The following commit(s) were added to refs/heads/5.6.x by this push:
new 5aeae81 TAP5-2662: FormGroup now generates aria-labelledby in field
5aeae81 is described below
commit 5aeae81415be24d8cc9647c9409188ec9c72d33e
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Fri Feb 12 15:40:55 2021 -0300
TAP5-2662: FormGroup now generates aria-labelledby in field
---
.../org/apache/tapestry5/corelib/mixins/FormGroup.java | 18 +++++++++++++++++-
.../tapestry5/integration/app1/BeanEditorTests.java | 10 ++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/FormGroup.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/FormGroup.java
index 010fd37..4f4af3f 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/FormGroup.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/FormGroup.java
@@ -22,6 +22,7 @@ import org.apache.tapestry5.annotations.InjectContainer;
import org.apache.tapestry5.dom.Element;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.annotations.Symbol;
+import org.apache.tapestry5.services.javascript.JavaScriptSupport;
/**
* Applied to a {@link org.apache.tapestry5.Field}, this provides the outer layers of markup to correctly
@@ -83,6 +84,9 @@ public class FormGroup
@Environmental
private ValidationDecorator decorator;
+
+ @Inject
+ private JavaScriptSupport javaScriptSupport;
void beginRender(MarkupWriter writer)
{
@@ -116,9 +120,21 @@ public class FormGroup
void afterRender(MarkupWriter writer)
{
- if (fieldWrapper != null) {
+ if (fieldWrapper != null)
+ {
writer.end(); // field wrapper
}
+
+ // TAP5-2662
+ final Element inputElement = writer.getDocument().getElementById(field.getClientId());
+ if (inputElement != null)
+ {
+ final String clientId = field.getClientId();
+ final String labelId = javaScriptSupport.allocateClientId(clientId + "-label");
+ label.attribute("id", labelId);
+ inputElement.attribute("aria-labelledby", labelId);
+ }
+
writer.end(); // div.form-group
}
}
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/BeanEditorTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/BeanEditorTests.java
index ba8dd48..b1f8dfb 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/BeanEditorTests.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/BeanEditorTests.java
@@ -245,4 +245,14 @@ public class BeanEditorTests extends App1TestCase
}
+ /** TAP5-2662 */
+ public void bean_editor_accessibility()
+ {
+
+ openLinks("BeanEditor Demo");
+
+ assertEquals("lastName-label", getAttribute("//input[@id='lastName']/@aria-labelledby"));
+
+ }
+
}