Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing props passed to tag causing aria issue #1074

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions src/components/sections/contact-box/ContactSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"use client";

import { use, useState } from "react";
import { use } from "react";

import EmployeeCard from "src/components/employeeCard/EmployeeCard";
import { Tag } from "src/components/tag";
import useTabs from "src/utils/hooks/useTabs";

import styles from "./contact-box.module.css";
import { EmployeeAndMetadata } from "./types";
Expand All @@ -22,41 +23,40 @@ export default function ContactSelector({
background = "dark",
}: ContactSelectorProps) {
const contactPoints = use(contactPointsPromise);

const [selectedTag, setSelectedTag] = useState<string | null>(
contactPoints[0]?.tagSlug,
);
const { tabListRef, selectedTabIndex } = useTabs();

if (!contactPoints.length) {
return null;
}

return (
<div className={styles.contactSelector}>
<div className={styles.tagList} role="tablist">
{contactPoints.map((contactPoint) => (
<Tag
key={contactPoint.tagSlug}
type="button"
role="tab"
background={background}
aria-selected={selectedTag === contactPoint.tagSlug}
aria-controls={`panel-${contactPoint.tagSlug}`}
id={`tab-${contactPoint.tagSlug}`}
active={selectedTag === contactPoint.tagSlug}
onClick={() => setSelectedTag(contactPoint.tagSlug)}
text={contactPoint.tag}
/>
<ul className={styles.tagList} role="tablist" ref={tabListRef}>
{contactPoints.map((contactPoint, index) => (
<li key={contactPoint.tagSlug}>
<Tag
type="button"
role="tab"
background={background}
aria-selected={selectedTabIndex === index}
aria-controls={`panel-${contactPoint.tagSlug}`}
id={`tab-${contactPoint.tagSlug}`}
active={selectedTabIndex === index}
text={contactPoint.tag}
tabIndex={selectedTabIndex === index ? 0 : -1}
/>
</li>
))}
</div>
</ul>
<div className={styles.employeeCard}>
{contactPoints.map((contactPoint) => (
{contactPoints.map((contactPoint, index) => (
<div
key={contactPoint.tagSlug}
role="tabpanel"
id={`panel-${contactPoint.tagSlug}`}
aria-labelledby={`tab-${contactPoint.tagSlug}`}
hidden={selectedTag !== contactPoint.tagSlug}
hidden={selectedTabIndex !== index}
tabIndex={selectedTabIndex === index ? 0 : -1}
>
<EmployeeCard
employee={contactPoint.employee}
Expand Down
5 changes: 5 additions & 0 deletions src/components/sections/contact-box/contact-box.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@

align-items: flex-start;
min-width: 120px;
margin: 0;
padding: 0;
}
.tagList li {
list-style: none;
}

.employeeCard {
Expand Down
1 change: 1 addition & 0 deletions src/components/tag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const Tag = ({
className={className}
style={{ cursor: "pointer" }}
onClick={props.onClick}
{...props}
>
<Text type="labelRegular">{text}</Text>
</button>
Expand Down
Loading