Skip to content

Commit e953dce

Browse files
authored
chore(ui): fix Expandable aria attributes (#37885)
1 parent 630345d commit e953dce

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

packages/web/src/components/expandable.tsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,29 @@ export const Expandable: React.FunctionComponent<React.PropsWithChildren<{
2525
expandOnTitleClick?: boolean,
2626
}>> = ({ title, children, setExpanded, expanded, expandOnTitleClick }) => {
2727
const id = React.useId();
28+
29+
const onClick = React.useCallback(() => setExpanded(!expanded), [expanded, setExpanded]);
30+
31+
const chevron = <div
32+
className={clsx('codicon', expanded ? 'codicon-chevron-down' : 'codicon-chevron-right')}
33+
style={{ cursor: 'pointer', color: 'var(--vscode-foreground)', marginLeft: '5px' }}
34+
onClick={!expandOnTitleClick ? onClick : undefined} />;
35+
2836
return <div className={clsx('expandable', expanded && 'expanded')}>
29-
<div
30-
role='button'
31-
aria-expanded={expanded}
32-
aria-controls={id}
33-
className='expandable-title'
34-
onClick={() => expandOnTitleClick && setExpanded(!expanded)}>
37+
{expandOnTitleClick ?
3538
<div
36-
className={clsx('codicon', expanded ? 'codicon-chevron-down' : 'codicon-chevron-right')}
37-
style={{ cursor: 'pointer', color: 'var(--vscode-foreground)', marginLeft: '5px' }}
38-
onClick={() => !expandOnTitleClick && setExpanded(!expanded)} />
39-
{title}
40-
</div>
41-
{ expanded && <div id={id} role='region' style={{ marginLeft: 25 }}>{children}</div> }
39+
role='button'
40+
aria-expanded={expanded}
41+
aria-controls={id}
42+
className='expandable-title'
43+
onClick={onClick}>
44+
{chevron}
45+
{title}
46+
</div> :
47+
<div className='expandable-title'>
48+
{chevron}
49+
{title}
50+
</div>}
51+
{expanded && <div id={id} role='region' style={{ marginLeft: 25 }}>{children}</div>}
4252
</div>;
4353
};

0 commit comments

Comments
 (0)