Skip to content

Commit 399df31

Browse files
authored
Merge pull request #167 from aimeos/aria_i18n
Allow ARIA texts to be translated
2 parents 81e61c2 + c3c689b commit 399df31

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

packages/he-tree-vue/src/components/BaseTree.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ const cpt = defineComponent({
157157
treeLine: { type: Boolean, default: false },
158158
treeLineOffset: { type: Number, default: 8 },
159159
ariaLabel: { type: String, default: "Tree" },
160+
i18n: {
161+
type: Object as PropType<{
162+
instructions?: string;
163+
movedToPosition?: (position: number, total: number) => string;
164+
outdentedToLevel?: (level: number, position: number, total: number) => string;
165+
indentedToLevel?: (level: number, position: number, total: number) => string;
166+
}>,
167+
default: () => ({}),
168+
},
160169
},
161170
emits: [
162171
"update:modelValue",

packages/he-tree-vue/src/components/DraggableTree.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ const cpt = defineComponent({
220220
: this.stats;
221221
const newIndex = newSiblings.indexOf(stat);
222222
this._announce(
223-
`Moved to position ${newIndex + 1} of ${newSiblings.length}`
223+
this.i18n?.movedToPosition
224+
? this.i18n.movedToPosition(newIndex + 1, newSiblings.length)
225+
: `Moved to position ${newIndex + 1} of ${newSiblings.length}`
224226
);
225227
this._focusNode(stat);
226228
}
@@ -236,7 +238,9 @@ const cpt = defineComponent({
236238
: this.stats;
237239
const newIndex = newSiblings.indexOf(stat);
238240
this._announce(
239-
`Moved to position ${newIndex + 1} of ${newSiblings.length}`
241+
this.i18n?.movedToPosition
242+
? this.i18n.movedToPosition(newIndex + 1, newSiblings.length)
243+
: `Moved to position ${newIndex + 1} of ${newSiblings.length}`
240244
);
241245
this._focusNode(stat);
242246
}
@@ -258,7 +262,9 @@ const cpt = defineComponent({
258262
: this.stats;
259263
const newIndex = newSiblings.indexOf(stat);
260264
this._announce(
261-
`Outdented to level ${stat.level}, position ${newIndex + 1} of ${newSiblings.length}`
265+
this.i18n?.outdentedToLevel
266+
? this.i18n.outdentedToLevel(stat.level, newIndex + 1, newSiblings.length)
267+
: `Outdented to level ${stat.level}, position ${newIndex + 1} of ${newSiblings.length}`
262268
);
263269
this._focusNode(stat);
264270
}
@@ -277,7 +283,9 @@ const cpt = defineComponent({
277283
this.move(stat, prevSibling, targetIndex);
278284
this.$emit("change");
279285
this._announce(
280-
`Indented to level ${stat.level}, position ${prevSibling.children.indexOf(stat) + 1} of ${prevSibling.children.length}`
286+
this.i18n?.indentedToLevel
287+
? this.i18n.indentedToLevel(stat.level, prevSibling.children.indexOf(stat) + 1, prevSibling.children.length)
288+
: `Indented to level ${stat.level}, position ${prevSibling.children.indexOf(stat) + 1} of ${prevSibling.children.length}`
281289
);
282290
this._focusNode(stat);
283291
}
@@ -485,6 +493,7 @@ const cpt = defineComponent({
485493
};
486494
// Accessibility: keyboard instructions
487495
this.ariaInstructions =
496+
this.i18n?.instructions ??
488497
"Use arrow keys to navigate. Alt plus arrow keys to reorder.";
489498

490499
this.treeDraggableInstance = extendedDND(rootEl, {

packages/he-tree-vue/src/components/TreeNode.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ const cpt = defineComponent({
176176
// Only include aria-checked if checkboxes are in use
177177
// We detect this by checking if checked is explicitly set
178178
}
179+
// Aria label from stat or stat.data
180+
const ariaLabel = stat.ariaLabel ?? stat.data?.ariaLabel;
181+
if (ariaLabel) {
182+
attrs["aria-label"] = ariaLabel;
183+
}
179184
// Disabled state (non-draggable in a draggable tree)
180185
if (stat.draggable === false) {
181186
attrs["aria-disabled"] = "true";

0 commit comments

Comments
 (0)