diff --git a/eslint-suppressions.json b/eslint-suppressions.json index f90a21cb7c5..9ecdfaed054 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -710,11 +710,6 @@ "count": 1 } }, - "packages/grafana-ui/src/components/QueryField/QueryField.story.tsx": { - "no-restricted-syntax": { - "count": 1 - } - }, "packages/grafana-ui/src/components/QueryField/QueryField.tsx": { "react-prefer-function-component/react-prefer-function-component": { "count": 1 @@ -4677,4 +4672,4 @@ "count": 1 } } -} +} \ No newline at end of file diff --git a/packages/grafana-ui/src/components/QueryField/QueryField.story.tsx b/packages/grafana-ui/src/components/QueryField/QueryField.story.tsx index f0f672fa120..24aaee5af3a 100644 --- a/packages/grafana-ui/src/components/QueryField/QueryField.story.tsx +++ b/packages/grafana-ui/src/components/QueryField/QueryField.story.tsx @@ -1,6 +1,9 @@ import { Meta, StoryFn } from '@storybook/react'; +import { useId } from 'react'; import { TypeaheadInput } from '../../types/completion'; +import { Field } from '../Forms/Field'; +import { Label } from '../Forms/Label'; import { QueryField, QueryFieldProps } from './QueryField'; @@ -24,8 +27,6 @@ const meta: Meta = { 'syntaxLoaded', ], }, - // TODO fix a11y issue in story and remove this - a11y: { test: 'off' }, }, argTypes: { query: { @@ -34,7 +35,16 @@ const meta: Meta = { }, }; -export const Basic: StoryFn = (args: Omit) => ; +export const Basic: StoryFn = (args: Omit) => { + const id = useId(); + // have to manually set an id on the label + // can't use htmlFor as QueryField is a contenteditable div, not an input + return ( + Query field}> + + + ); +}; Basic.args = { onTypeahead: async (_input: TypeaheadInput) => ({ diff --git a/packages/grafana-ui/src/components/QueryField/QueryField.tsx b/packages/grafana-ui/src/components/QueryField/QueryField.tsx index b9cd4fcd67c..a0583ee7121 100644 --- a/packages/grafana-ui/src/components/QueryField/QueryField.tsx +++ b/packages/grafana-ui/src/components/QueryField/QueryField.tsx @@ -25,6 +25,7 @@ import { makeValue, SCHEMA } from '../../utils/slate'; export interface QueryFieldProps extends Themeable2 { additionalPlugins?: Plugin[]; + ['aria-labelledby']?: string; cleanText?: (text: string) => string; disabled?: boolean; // We have both value and local state. This is usually an antipattern but we need to keep local state @@ -201,7 +202,7 @@ export class UnThemedQueryField extends PureComponent { this.editor = editor; }} + aria-labelledby={ariaLabelledby} schema={SCHEMA} autoCorrect={false} readOnly={this.props.disabled}