packages/grafana-ui/src/components/Forms/InlineField.mdx
import { ArgTypes } from '@storybook/addon-docs/blocks'; import { InlineField } from './InlineField';
A basic component for rendering form elements, like Input, Checkbox, Combobox, etc, inline together with InlineLabel. If the child element has id specified, the label's htmlFor attribute, pointing to the id, will be added.
The width of the InlineLabel can be modified via labelWidth prop, which is a multiple of 8px. For example, an InlineField with labelWidth={20} will have a label 160px wide.
If tooltip prop is provided, an info icon with supplied tooltip content will be rendered inside the label.
<InlineField label="Inline field">
<Input placeholder="Inline input" />
</InlineField>
InlineField provides a FieldContext that any descendant can read using the useFieldContext hook. This is the recommended way to access field state from a child component.
| Property | Type | Description |
|---|---|---|
id | string | Resolved input id (htmlFor → child id → generated id) |
invalid | boolean | undefined | Mirrors the invalid prop |
disabled | boolean | undefined | Mirrors the disabled prop |
loading | boolean | undefined | Mirrors the loading prop |
aria-describedby | string | undefined | Always undefined in InlineField |
aria-labelledby | string | undefined | Set when the child is a RadioButtonGroup (fieldset mode) |
Example:
import { useFieldContext } from '@grafana/ui';
function MyCustomInput() {
const { id, invalid, 'aria-labelledby': labelledby } = useFieldContext();
return <input id={id} aria-invalid={invalid} aria-labelledby={labelledby} />;
}
// Usage:
<InlineField label="Threshold">
<MyCustomInput />
</InlineField>;