Skip to content

Commit

Permalink
Accessibility: Improve keyboard accessibility in Collapse (#59022)
Browse files Browse the repository at this point in the history
fix keyboard accessibility in Collapse
  • Loading branch information
ashharrison90 committed Nov 22, 2022
1 parent 189bf10 commit 19e97a1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/grafana-ui/src/components/Collapse/Collapse.tsx
Expand Up @@ -4,6 +4,7 @@ import React, { FunctionComponent, useState } from 'react';
import { GrafanaTheme2 } from '@grafana/data';

import { useStyles2 } from '../../themes/ThemeContext';
import { clearButtonStyles } from '../Button';
import { Icon } from '../Icon/Icon';

const getStyles = (theme: GrafanaTheme2) => ({
Expand Down Expand Up @@ -71,9 +72,7 @@ const getStyles = (theme: GrafanaTheme2) => ({
label: collapse__header;
padding: ${theme.spacing(1, 2, 1, 2)};
display: flex;
cursor: inherit;
transition: all 0.1s linear;
cursor: pointer;
`,
headerCollapsed: css`
label: collapse__header--collapsed;
Expand Down Expand Up @@ -132,6 +131,7 @@ export const Collapse = ({
className,
children,
}: React.PropsWithChildren<Props>) => {
const buttonStyles = useStyles2(clearButtonStyles);
const style = useStyles2(getStyles);
const onClickToggle = () => {
if (onToggle) {
Expand All @@ -145,10 +145,10 @@ export const Collapse = ({

return (
<div className={panelClass}>
<div className={headerClass} onClick={onClickToggle}>
<button type="button" className={cx(buttonStyles, headerClass)} onClick={onClickToggle}>
{collapsible && <Icon className={style.icon} name={isOpen ? 'angle-down' : 'angle-right'} />}
<div className={cx([style.headerLabel])}>{label}</div>
</div>
</button>
{isOpen && (
<div className={cx([style.collapseBody])}>
<div className={loaderClass} />
Expand Down

0 comments on commit 19e97a1

Please sign in to comment.