Skip to content

Commit 46aa394

Browse files
committed
fix(a11y): use shared logic for aria-expanded
1 parent 78864eb commit 46aa394

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

app/components/Package/Versions.vue

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,14 @@ function getExpandedTagVersions(tag: string, primaryVersion: string): VersionDis
457457
return versions.filter(v => filteredVersionSet.value.has(v.version))
458458
}
459459
460+
// Check if a tag row's children are expanded (manually or via active filter)
461+
function isTagExpanded(tag: string, primaryVersion: string): boolean {
462+
return (
463+
expandedTags.value.has(tag) ||
464+
(isFilterActive.value && getExpandedTagVersions(tag, primaryVersion).length > 0)
465+
)
466+
}
467+
460468
function findClaimingTag(version: string): string | null {
461469
const versionChannel = getPrereleaseChannel(version)
462470
@@ -605,7 +613,7 @@ function majorGroupContainsCurrent(group: (typeof otherMajorGroups.value)[0]): b
605613
v-if="getTagVersions(row.tag).length > 1 || !hasLoadedAll"
606614
type="button"
607615
class="size-5 -me-1 flex items-center justify-center text-fg-subtle hover:text-fg transition-colors rounded-sm relative z-10"
608-
:aria-expanded="expandedTags.has(row.tag)"
616+
:aria-expanded="isTagExpanded(row.tag, row.primaryVersion.version)"
609617
:aria-label="
610618
expandedTags.has(row.tag)
611619
? $t('package.versions.collapse', { tag: row.tag })
@@ -624,7 +632,9 @@ function majorGroupContainsCurrent(group: (typeof otherMajorGroups.value)[0]): b
624632
v-else
625633
class="size-3 transition-transform duration-200 rtl-flip"
626634
:class="
627-
expandedTags.has(row.tag) ? 'i-lucide:chevron-down' : 'i-lucide:chevron-right'
635+
isTagExpanded(row.tag, row.primaryVersion.version)
636+
? 'i-lucide:chevron-down'
637+
: 'i-lucide:chevron-right'
628638
"
629639
aria-hidden="true"
630640
/>
@@ -693,10 +703,7 @@ function majorGroupContainsCurrent(group: (typeof otherMajorGroups.value)[0]): b
693703

694704
<!-- Expanded versions -->
695705
<div
696-
v-if="
697-
(expandedTags.has(row.tag) || isFilterActive) &&
698-
getExpandedTagVersions(row.tag, row.primaryVersion.version).length
699-
"
706+
v-if="isTagExpanded(row.tag, row.primaryVersion.version)"
700707
class="ms-4 ps-2 border-is border-border space-y-0.5 pe-2"
701708
>
702709
<div

0 commit comments

Comments
 (0)