Skip to content

Commit 7f50bea

Browse files
marinaaisahqhhuang
andauthored
[rdar://105598877] feat: add refactor to ariaDescribedBy in NavigatorCardItem (#593)
Co-authored-by: Hanqing Huang <[email protected]>
1 parent ad64d71 commit 7f50bea

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

src/components/Navigator/NavigatorCardItem.vue

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,26 @@
6565
v-if="isParent"
6666
hidden
6767
:id="parentLabel"
68-
>, {{ $tc(
69-
'filter.containing-symbols',
68+
>{{ $tc(
69+
'filter.parent-label',
7070
item.childUIDs.length,
71-
{ number: item.childUIDs.length }
71+
{
72+
'number-siblings': item.index + 1,
73+
'total-siblings': item.siblingsCount,
74+
'parent-siblings': item.parent,
75+
'number-parent': item.childUIDs.length
76+
}
7277
) }}</span>
7378
<span
79+
v-if="!isParent"
7480
:id="siblingsLabel"
7581
hidden
7682
>
77-
{{ $t('filter.symbols-inside', { number: item.index + 1, total: item.siblingsCount }) }}
83+
{{ $t('filter.siblings-label', {
84+
'number-siblings': item.index + 1,
85+
'total-siblings': item.siblingsCount,
86+
'parent-siblings': item.parent
87+
}) }}
7888
</span>
7989
<component
8090
:is="refComponent"
@@ -181,13 +191,11 @@ export default {
181191
parentLabel: ({ item }) => `label-parent-${item.uid}`,
182192
siblingsLabel: ({ item }) => `label-${item.uid}`,
183193
usageLabel: ({ item }) => `usage-${item.uid}`,
184-
ariaDescribedBy({
185-
item, siblingsLabel, parentLabel, isParent,
186-
}) {
187-
const baseLabel = `${siblingsLabel} ${item.parent}`;
188-
if (!isParent) return `${baseLabel}`;
189-
return `${baseLabel} ${parentLabel}`;
190-
},
194+
ariaDescribedBy: ({
195+
isParent, parentLabel, siblingsLabel,
196+
}) => (
197+
isParent ? `${parentLabel}` : `${siblingsLabel}`
198+
),
191199
isBeta: ({ item: { beta } }) => !!beta,
192200
isDeprecated: ({ item: { deprecated } }) => !!deprecated,
193201
refComponent: ({ isGroupMarker }) => (isGroupMarker ? 'h3' : Reference),

src/lang/locales/ja-JP.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@
118118
"add-tag": "タグを追加",
119119
"tag-select-remove": "タグ。選択してリストから削除します。",
120120
"navigate": "シンボルを移動するには、上下左右の矢印キーを押します。",
121-
"containing-symbols": "1個のシンボルを含む | {number}個のシンボルを含む",
122-
"symbols-inside": "{total}個中{number}個のシンボルが中にあります",
121+
"siblings-label": "{number-siblings}個中{total-siblings} 個のシンボルが中にあります {parent-siblings}",
122+
"parent-label": "@:filter.siblings-label 1個のシンボルを含む | @:filter.siblings-label {number-parent} 個のシンボルを含む",
123123
"reset-filter": "フィルタをリセット"
124124
},
125125
"navigator": {

src/lang/locales/zh-CN.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@
118118
"add-tag": "添加标签",
119119
"tag-select-remove": "标签。选择以从列表中移除。",
120120
"navigate": "若要导航符号,请按下上箭头、下箭头、左箭头或右箭头。",
121-
"containing-symbols": "包含 1 个符号 | 包含 {number} 个符号",
122-
"symbols-inside": "内含 {number} 个符号(共 {total} 个)",
121+
"siblings-label": "内含 {number-siblings} 个符号(共 {total-siblings} 个){parent-siblings}",
122+
"parent-label": "@:filter.siblings-label 包含 1 个符号 | @:filter.siblings-label 包含 {number-parent} 个符号",
123123
"reset-filter": "还原过滤条件"
124124
},
125125
"navigator": {

tests/unit/components/Navigator/NavigatorCardItem.spec.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ describe('NavigatorCardItem', () => {
463463
expect(btn.attributes('tabindex')).toBe('-1');
464464
expect(btn.attributes('aria-labelledby')).toBe(`${defaultProps.item.uid}`);
465465
expect(btn.attributes('aria-describedby'))
466-
.toBe(`label-${defaultProps.item.uid} Foo label-parent-${defaultProps.item.uid}`);
466+
.toBe(`label-parent-${defaultProps.item.uid}`);
467467
});
468468

469469
it('renders aria-expanded true in button when component is expanded', () => {
@@ -475,22 +475,14 @@ describe('NavigatorCardItem', () => {
475475
expect(wrapper.find('.tree-toggle').attributes('aria-expanded')).toBe('true');
476476
});
477477

478-
it('renders a hidden span telling the user the position of a symbol', () => {
479-
const wrapper = createWrapper();
480-
const label = wrapper.find(`#label-${defaultProps.item.uid}`);
481-
expect(label.attributes('hidden')).toBe('hidden');
482-
expect(label.text())
483-
.toBe('filter.symbols-inside 2 5');
484-
});
485-
486-
it('renders a hidden span telling the containing number of symbols', () => {
478+
it('renders a aria-describedby with parent label if it is a parent', () => {
487479
const wrapper = createWrapper();
488480
const label = wrapper.find(`#label-parent-${defaultProps.item.uid}`);
489481
expect(label.attributes('hidden')).toBe('hidden');
490-
expect(label.text()).toBe(', filter.containing-symbols');
482+
expect(label.text()).toBe('filter.parent-label');
491483
});
492484

493-
it('renders a aria-describedby without parent label if it is not a parent', () => {
485+
it('renders a aria-describedby with sibling label if it is not a parent', () => {
494486
const wrapper = createWrapper({
495487
propsData: {
496488
item: {
@@ -499,8 +491,13 @@ describe('NavigatorCardItem', () => {
499491
},
500492
},
501493
});
494+
const label = wrapper.find(`#label-${defaultProps.item.uid}`);
495+
expect(label.attributes('hidden')).toBe('hidden');
496+
expect(label.text())
497+
.toBe('filter.siblings-label 2 5 Foo');
498+
502499
expect(wrapper.find('.leaf-link').attributes('aria-describedby'))
503-
.toBe(`label-${defaultProps.item.uid} Foo usage-${defaultProps.item.uid}`);
500+
.toBe(`label-${defaultProps.item.uid} usage-${defaultProps.item.uid}`);
504501
});
505502

506503
it('focuses its link, if `isFocused`, `isRendered` and `enableFocus` is `true`', async () => {

0 commit comments

Comments
 (0)