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(Section): make collapsible keyboard accessible #7144

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
27 changes: 16 additions & 11 deletions packages/core/src/components/section/section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ChevronDown, ChevronUp, type IconName } from "@blueprintjs/icons";

import { Classes, Elevation, Utils } from "../../common";
import { DISPLAYNAME_PREFIX, type HTMLDivProps, type MaybeElement, type Props } from "../../common/props";
import { uniqueId } from "../../common/utils";
import { clickElementOnKeyPress, uniqueId } from "../../common/utils";
import { Card } from "../card/card";
import { Collapse, type CollapseProps } from "../collapse/collapse";
import { H6 } from "../html/html";
Expand Down Expand Up @@ -177,10 +177,6 @@ export const Section: React.FC<SectionProps> = React.forwardRef((props, ref) =>
>
{title && (
<div
role={collapsible ? "button" : undefined}
aria-pressed={collapsible ? isCollapsed : undefined}
aria-expanded={collapsible ? isCollapsed : undefined}
aria-controls={collapsible ? sectionId : undefined}
className={classNames(Classes.SECTION_HEADER, {
[Classes.INTERACTIVE]: collapsible,
})}
Expand All @@ -204,12 +200,21 @@ export const Section: React.FC<SectionProps> = React.forwardRef((props, ref) =>
{isHeaderRightContainerVisible && (
<div className={Classes.SECTION_HEADER_RIGHT}>
{rightElement}
{collapsible &&
(isCollapsed ? (
<ChevronDown className={Classes.TEXT_MUTED} />
) : (
<ChevronUp className={Classes.TEXT_MUTED} />
))}
{collapsible && (
<span
role="button"
tabIndex={0}
aria-pressed={isCollapsed}
aria-expanded={isCollapsed}
aria-controls={sectionId}
aria-label={isCollapsed ? "expand section" : "collapse section"}
onClick={toggleIsCollapsed}
onKeyDown={clickElementOnKeyPress(["Enter", " "])}
className={classNames(Classes.TEXT_MUTED, Classes.INTERACTIVE)}
>
{isCollapsed ? <ChevronDown /> : <ChevronUp />}
</span>
)}
</div>
)}
</div>
Expand Down