Skip to content

Commit

Permalink
Fix sonarcloud linting; aria accessibility tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
NatSquared committed Mar 13, 2024
1 parent 3dfb1da commit bf6abb1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ const EngagementMetadata = forwardRef((_props, ref) => {
const taxonMeta = taxonMetadata.get(taxonId) ?? [];
let taxonValue = value ?? [];
// Normalize and clean the arrays
taxonValue = cleanArray(Array.isArray(taxonValue) ? taxonValue : [taxonValue]);
const normalizedTaxonMeta = cleanArray(taxonMeta);
if (JSON.stringify(taxonValue.sort()) === JSON.stringify(normalizedTaxonMeta.sort())) continue;
const comparator = (a: string, b: string) => a.localeCompare(b);
taxonValue = cleanArray(Array.isArray(taxonValue) ? taxonValue : [taxonValue]).sort(comparator);
const normalizedTaxonMeta = cleanArray(taxonMeta).sort(comparator);
if (JSON.stringify(taxonValue) === JSON.stringify(normalizedTaxonMeta)) continue;
// If we reach here, arrays are not equal, proceed with update
try {
const updatedMetadata = await bulkPatchEngagementMetadata(taxonId, Number(engagementId), taxonValue);
Expand Down
16 changes: 13 additions & 3 deletions met-web/src/components/metadataManagement/TaxonCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ export const TaxonCard: React.FC<TaxonCardProps> = ({ taxon, isExpanded, onExpan
direction="row"
justifyContent="space-between"
alignItems="center"
aria-expanded={isExpanded}
aria-label="A card representing a taxon in the engagement metadata."
role="group"
role="gridcell"
id={`taxon-${taxon.id}`}
>
<Grid item container xs alignItems="center" spacing={1}>
<Grid item>
Expand Down Expand Up @@ -157,13 +157,23 @@ export const TaxonCard: React.FC<TaxonCardProps> = ({ taxon, isExpanded, onExpan
size="small"
aria-label="expand"
onClick={handleExpand}
aria-expanded={isExpanded}
aria-controls={`taxon-${taxon.id}-content`}
>
<ExpandMore />
</IconButton>
</Grid>
</Grid>
<Grid item xs={12}>
<Collapse in={isExpanded} timeout="auto" unmountOnExit sx={{ pt: 1 }}>
<Collapse
in={isExpanded}
timeout="auto"
unmountOnExit
sx={{ pt: 1 }}
id={`taxon-${taxon.id}-content`}
aria-labelledby={`taxon-${taxon.id}`}
aria-hidden={!isExpanded}
>
<Grid container alignItems="center" spacing={1} flexWrap="wrap">
{/* Description */}
<DetailsRow name="Description" icon={<FormatQuote />}>
Expand Down

0 comments on commit bf6abb1

Please sign in to comment.