Skip to content

Commit

Permalink
Ensure non-collapsable cards aren't focusable
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Mar 11, 2024
1 parent ecd3ae9 commit ad73779
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/common/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,16 @@ export class CollapsibleCard extends React.Component<
private cardRef = React.createRef<HTMLElement>();

render() {
const collapsable = !!this.props.onCollapseToggled;

return <CollapsibleCardContainer
className={this.props.className}
collapsed={this.props.collapsed}
expanded={this.props.expanded ?? false}
direction={this.props.direction}
headerAlignment={this.props.headerAlignment ?? 'right'}

tabIndex={0}
tabIndex={collapsable ? 0 : undefined}
ref={this.cardRef}
onKeyDown={this.onKeyDown}
aria-label={this.props.ariaLabel}
Expand All @@ -179,15 +181,15 @@ export class CollapsibleCard extends React.Component<
renderChildren() {
const { children, collapsed, headerAlignment } = this.props;

const showCollapseIcon = !!this.props.onCollapseToggled;
const collapsable = !!this.props.onCollapseToggled;

return React.Children.map(children as React.ReactElement<any>[], (child, i) => {
if (i !== 0) {
if (collapsed) return null; // When collapsed, we drop all but the first child
else return child;
}

if (!showCollapseIcon) return child;
if (!collapsable) return child;

// Otherwise: it's the first child and we want to inject a collapse icon.

Expand Down

0 comments on commit ad73779

Please sign in to comment.