Core: Implement aria attributes for query rows, improve a11y (#55563)

* feat: add aria-expanded prop

* refactor: remove console.log()

* feat: add aria-controls

* refactor: add id to expendable section

* refactor: create unique id
This commit is contained in:
Laura Benz
2022-09-30 13:03:55 +02:00
committed by GitHub
parent 9ec7b202b6
commit fc6afc6b84
3 changed files with 10 additions and 3 deletions

View File

@@ -104,6 +104,7 @@ export const QueryOperationRow: React.FC<QueryOperationRowProps> = ({
<div ref={provided.innerRef} className={styles.wrapper} {...provided.draggableProps}> <div ref={provided.innerRef} className={styles.wrapper} {...provided.draggableProps}>
<div> <div>
<QueryOperationRowHeader <QueryOperationRowHeader
id={id}
actionsElement={actionsElement} actionsElement={actionsElement}
disabled={disabled} disabled={disabled}
draggable draggable
@@ -127,6 +128,7 @@ export const QueryOperationRow: React.FC<QueryOperationRowProps> = ({
return ( return (
<div className={styles.wrapper}> <div className={styles.wrapper}>
<QueryOperationRowHeader <QueryOperationRowHeader
id={id}
actionsElement={actionsElement} actionsElement={actionsElement}
disabled={disabled} disabled={disabled}
draggable={false} draggable={false}

View File

@@ -15,6 +15,7 @@ interface QueryOperationRowHeaderProps {
onRowToggle: () => void; onRowToggle: () => void;
reportDragMousePosition: MouseEventHandler<HTMLDivElement>; reportDragMousePosition: MouseEventHandler<HTMLDivElement>;
titleElement?: React.ReactNode; titleElement?: React.ReactNode;
id: string;
} }
export const QueryOperationRowHeader: React.FC<QueryOperationRowHeaderProps> = ({ export const QueryOperationRowHeader: React.FC<QueryOperationRowHeaderProps> = ({
@@ -27,6 +28,7 @@ export const QueryOperationRowHeader: React.FC<QueryOperationRowHeaderProps> = (
onRowToggle, onRowToggle,
reportDragMousePosition, reportDragMousePosition,
titleElement, titleElement,
id,
}: QueryOperationRowHeaderProps) => { }: QueryOperationRowHeaderProps) => {
const styles = useStyles2(getStyles); const styles = useStyles2(getStyles);
@@ -40,6 +42,8 @@ export const QueryOperationRowHeader: React.FC<QueryOperationRowHeaderProps> = (
className={styles.collapseIcon} className={styles.collapseIcon}
onClick={onRowToggle} onClick={onRowToggle}
type="button" type="button"
aria-expanded={isContentVisible}
aria-controls={id}
/> />
{titleElement && ( {titleElement && (
<div className={styles.titleWrapper} onClick={onRowToggle} aria-label="Query operation row title"> <div className={styles.titleWrapper} onClick={onRowToggle} aria-label="Query operation row title">

View File

@@ -1,6 +1,6 @@
// Libraries // Libraries
import classNames from 'classnames'; import classNames from 'classnames';
import { cloneDeep, filter, has, uniqBy } from 'lodash'; import { cloneDeep, filter, has, uniqBy, uniqueId } from 'lodash';
import pluralize from 'pluralize'; import pluralize from 'pluralize';
import React, { PureComponent, ReactNode } from 'react'; import React, { PureComponent, ReactNode } from 'react';
@@ -451,6 +451,7 @@ export class QueryEditorRow<TQuery extends DataQuery> extends PureComponent<Prop
const { query, id, index, visualization } = this.props; const { query, id, index, visualization } = this.props;
const { datasource, showingHelp, data } = this.state; const { datasource, showingHelp, data } = this.state;
const isDisabled = query.hide; const isDisabled = query.hide;
const generatedUniqueId = uniqueId(id + '_');
const rowClasses = classNames('query-editor-row', { const rowClasses = classNames('query-editor-row', {
'query-editor-row--disabled': isDisabled, 'query-editor-row--disabled': isDisabled,
@@ -467,14 +468,14 @@ export class QueryEditorRow<TQuery extends DataQuery> extends PureComponent<Prop
return ( return (
<div aria-label={selectors.components.QueryEditorRows.rows}> <div aria-label={selectors.components.QueryEditorRows.rows}>
<QueryOperationRow <QueryOperationRow
id={id} id={generatedUniqueId}
draggable={true} draggable={true}
index={index} index={index}
headerElement={this.renderHeader} headerElement={this.renderHeader}
actions={this.renderActions} actions={this.renderActions}
onOpen={this.onOpen} onOpen={this.onOpen}
> >
<div className={rowClasses}> <div className={rowClasses} id={generatedUniqueId}>
<ErrorBoundaryAlert> <ErrorBoundaryAlert>
{showingHelp && DatasourceCheatsheet && ( {showingHelp && DatasourceCheatsheet && (
<OperationRowHelp> <OperationRowHelp>