diff --git a/packages/grafana-ui/src/components/FormField/FormField.test.tsx b/packages/grafana-ui/src/components/FormField/FormField.test.tsx index 71fe532a64d..553d92e0e17 100644 --- a/packages/grafana-ui/src/components/FormField/FormField.test.tsx +++ b/packages/grafana-ui/src/components/FormField/FormField.test.tsx @@ -1,4 +1,5 @@ -import { render, screen } from '@testing-library/react'; +import { render, screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import React from 'react'; import { FormField, Props } from './FormField'; @@ -29,4 +30,20 @@ describe('FormField', () => { expect(screen.queryByRole('textbox')).not.toBeInTheDocument(); expect(screen.getByRole('checkbox')).toBeInTheDocument(); }); + + it('tooltips should be focusable via Tab key', async () => { + const tooltip = 'Test tooltip'; + setup(); + setup({ + tooltip, + }); + + //focus the first input + screen.getAllByRole('textbox')[0].focus(); + await userEvent.tab(); + + await waitFor(() => { + screen.getByText(tooltip); + }); + }); }); diff --git a/packages/grafana-ui/src/components/FormField/FormField.tsx b/packages/grafana-ui/src/components/FormField/FormField.tsx index b15b54c3e1a..b341cfaa206 100644 --- a/packages/grafana-ui/src/components/FormField/FormField.tsx +++ b/packages/grafana-ui/src/components/FormField/FormField.tsx @@ -11,6 +11,8 @@ export interface Props extends InputHTMLAttributes { // If null no width will be specified not even default one inputWidth?: number | null; inputEl?: React.ReactNode; + /** Make tooltip interactive */ + interactive?: boolean; } const defaultProps = { @@ -29,12 +31,13 @@ export const FormField: FunctionComponent = ({ inputWidth, inputEl, className, + interactive, ...inputProps }) => { const styles = getStyles(); return (
- + {label} {inputEl || ( diff --git a/packages/grafana-ui/src/components/FormLabel/FormLabel.tsx b/packages/grafana-ui/src/components/FormLabel/FormLabel.tsx index ae6c1c46466..c01047df2ff 100644 --- a/packages/grafana-ui/src/components/FormLabel/FormLabel.tsx +++ b/packages/grafana-ui/src/components/FormLabel/FormLabel.tsx @@ -12,6 +12,8 @@ interface Props { isInvalid?: boolean; tooltip?: PopoverContent; width?: number | 'auto'; + /** Make tooltip interactive */ + interactive?: boolean; } export const FormLabel: FunctionComponent = ({ @@ -22,6 +24,7 @@ export const FormLabel: FunctionComponent = ({ htmlFor, tooltip, width, + interactive, ...rest }) => { const classes = classNames(className, `gf-form-label width-${width ? width : '10'}`, { @@ -33,10 +36,8 @@ export const FormLabel: FunctionComponent = ({ diff --git a/packages/grafana-ui/src/components/SecretFormField/SecretFormField.tsx b/packages/grafana-ui/src/components/SecretFormField/SecretFormField.tsx index 27da639c5ff..6eb08850410 100644 --- a/packages/grafana-ui/src/components/SecretFormField/SecretFormField.tsx +++ b/packages/grafana-ui/src/components/SecretFormField/SecretFormField.tsx @@ -18,6 +18,7 @@ export interface Props extends Omit, 'onRe inputWidth?: number; // Placeholder of the input field when in non configured state. placeholder?: string; + interactive?: boolean; } const getSecretFormFieldStyles = () => { @@ -46,6 +47,7 @@ export const SecretFormField: FunctionComponent = ({ isConfigured, tooltip, placeholder = 'Password', + interactive, ...inputProps }: Props) => { const styles = getSecretFormFieldStyles(); @@ -53,6 +55,7 @@ export const SecretFormField: FunctionComponent = ({