Skip to content

Commit bb3fa58

Browse files
committed
Add aria-labels to XFA form elements. (bug 1723422)
1 parent 0b95d69 commit bb3fa58

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/core/xfa/template.js

+12
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ function setTabIndex(node) {
201201
}
202202
}
203203

204+
function ariaLabel(field) {
205+
return field.assist && field.assist.speak
206+
? field.assist.speak[$content]
207+
: null;
208+
}
209+
204210
function valueToHtml(value) {
205211
return HTMLResult.success({
206212
name: "div",
@@ -1231,6 +1237,7 @@ class CheckButton extends XFAObject {
12311237
type,
12321238
checked,
12331239
xfaOn: exportedValue.on,
1240+
"aria-label": ariaLabel(field),
12341241
},
12351242
};
12361243

@@ -1322,6 +1329,7 @@ class ChoiceList extends XFAObject {
13221329
fieldId: field[$uid],
13231330
dataId: (field[$data] && field[$data][$uid]) || field[$uid],
13241331
style,
1332+
"aria-label": ariaLabel(field),
13251333
};
13261334

13271335
if (this.open === "multiSelect") {
@@ -1560,6 +1568,7 @@ class DateTimeEdit extends XFAObject {
15601568
dataId: (field[$data] && field[$data][$uid]) || field[$uid],
15611569
class: ["xfaTextfield"],
15621570
style,
1571+
"aria-label": ariaLabel(field),
15631572
},
15641573
};
15651574

@@ -3684,6 +3693,7 @@ class NumericEdit extends XFAObject {
36843693
dataId: (field[$data] && field[$data][$uid]) || field[$uid],
36853694
class: ["xfaTextfield"],
36863695
style,
3696+
"aria-label": ariaLabel(field),
36873697
},
36883698
};
36893699

@@ -5649,6 +5659,7 @@ class TextEdit extends XFAObject {
56495659
fieldId: field[$uid],
56505660
class: ["xfaTextfield"],
56515661
style,
5662+
"aria-label": ariaLabel(field),
56525663
},
56535664
};
56545665
} else {
@@ -5660,6 +5671,7 @@ class TextEdit extends XFAObject {
56605671
fieldId: field[$uid],
56615672
class: ["xfaTextfield"],
56625673
style,
5674+
"aria-label": ariaLabel(field),
56635675
},
56645676
};
56655677
}

test/unit/xfa_tohtml_spec.js

+42
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,48 @@ describe("XFAFactory", function () {
179179
expect(field.attributes.maxLength).toEqual(123);
180180
});
181181

182+
it("should have an aria-label property", function () {
183+
const xml = `
184+
<?xml version="1.0"?>
185+
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/">
186+
<template xmlns="http://www.xfa.org/schema/xfa-template/3.3">
187+
<subform name="root" mergeMode="matchTemplate">
188+
<pageSet>
189+
<pageArea>
190+
<contentArea x="0pt" w="456pt" h="789pt"/>
191+
<medium stock="default" short="456pt" long="789pt"/>
192+
<field y="1pt" w="11pt" h="22pt" x="2pt">
193+
<assist><speak>Screen Reader</speak></assist>
194+
<ui>
195+
<textEdit multiLine="0"/>
196+
</ui>
197+
<value>
198+
<text maxChars="123"/>
199+
</value>
200+
</field>
201+
</pageArea>
202+
</pageSet>
203+
<subform name="first">
204+
<draw w="1pt" h="1pt"><value><text>foo</text></value></draw>
205+
</subform>
206+
</subform>
207+
</template>
208+
<xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
209+
<xfa:data>
210+
</xfa:data>
211+
</xfa:datasets>
212+
</xdp:xdp>
213+
`;
214+
const factory = new XFAFactory({ "xdp:xdp": xml });
215+
216+
expect(factory.numberPages).toEqual(1);
217+
218+
const pages = factory.getPages();
219+
const field = searchHtmlNode(pages, "name", "input");
220+
221+
expect(field.attributes["aria-label"]).toEqual("Screen Reader");
222+
});
223+
182224
it("should have an input or textarea", function () {
183225
const xml = `
184226
<?xml version="1.0"?>

0 commit comments

Comments
 (0)