Files
grafana/public/app/features/datasources/settings/BasicSettings.tsx
Adam Simpson c57924e332 A11y: Fix remaining focus issues with Switch (#48376)
* refactor: replace uses of checked prop for <Switch> with value prop

* fix: remove spaces from ids

The ID format is stated as follows([source][1]):

> ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]),
hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

Since `QueryHeaderSwitch` is used in two places I created a new variable that replaces spaces with a dash in the label.

[1]: https://www.w3.org/TR/html401/types.html#type-name

* fix: allow Switch in AlertingSettings to be focused by keyboard

* fix: allow Switch in PromSettings to be focused by keyboard

Fixes #46472

Co-authored-by: Elfo404 <me@giordanoricci.com>
2022-05-02 13:50:44 +00:00

51 lines
1.6 KiB
TypeScript

import React, { FC } from 'react';
import { selectors } from '@grafana/e2e-selectors';
import { InlineField, InlineSwitch, Input } from '@grafana/ui';
export interface Props {
dataSourceName: string;
isDefault: boolean;
onNameChange: (name: string) => void;
onDefaultChange: (value: boolean) => void;
}
const BasicSettings: FC<Props> = ({ dataSourceName, isDefault, onDefaultChange, onNameChange }) => {
return (
<div className="gf-form-group" aria-label="Datasource settings page basic settings">
<div className="gf-form-inline">
<div className="gf-form max-width-30">
<InlineField
label="Name"
tooltip="The name is used when you select the data source in panels. The default data source is
'preselected in new panels."
grow
>
<Input
id="basic-settings-name"
type="text"
value={dataSourceName}
placeholder="Name"
onChange={(event) => onNameChange(event.currentTarget.value)}
required
aria-label={selectors.pages.DataSource.name}
/>
</InlineField>
</div>
<InlineField label="Default" labelWidth={8}>
<InlineSwitch
id="basic-settings-default"
value={isDefault}
onChange={(event: React.FormEvent<HTMLInputElement>) => {
onDefaultChange(event.currentTarget.checked);
}}
/>
</InlineField>
</div>
</div>
);
};
export default BasicSettings;