OptionalInput

How to get OptionalInput

import { OptionalInput } from 'fds/components';

Type: Component

Wraps a form component to make it support optionally adding a value. OptionalInput renders a Checkbox next to the form component which allows toggling its disabled state.

Props

# Name Type Description
1. [isDisabled] Boolean

Whether or not the component should be rendered in a disabled state.

  Default value
false
2. [onChange] Function

A callback that is called whenever a component's value changes.

This callback is called just before the "validate" prop is called.

Use this callback to update local state which in turn should update the value prop of the component whose callback just fired.


  Arguments
# Name Type Description
1. value Value | Array<ItemWithLabelAndValueValue>

A single value or an array of values, depending on the component that is changing.


  Value

Type: *

The current value of the component. This value will be visualized in the component, often using a human readable label, sometimes using another visual indication (e.g. Checkbox).

Depending on the component, the data type in JavaScript might be restricted further: eg: a TimeSelect might expect a Date, a TextInput a string etc. These restrictions are implemented with React PropTypes console warnings.

  ItemWithLabelAndValueValue

Type: *

The value of an ItemWithLabelAndValue.

This value is used to compare items, eg. when determining the selected item(s).

Depending on the component, the data type in JavaScript might be restricted further: eg: a TimeSelect might expect a Date, a TextInput a string etc. These restrictions are implemented with React PropTypes console warnings.

3. renderFormField Function

A callback that is called at render time, which should return a form field instance.


  Arguments
# Name Type Description
1. parameters Object
  Members

Members

Name Type Description
isDisabled Boolean

Whether or not the component should be rendered in a disabled state.

onFocusableRef Function

A callback that is called whenever the form field's(or part of the form field) ref changes. Use this callback to get the ref (or the domNode) of the form field (or part of the form field) so it can be focused when the OptionalInput is focused.

4. [tooltipContent] String | ReactElement

The content of the tooltip that is displayed when hovering over the whole component.

  • string: the textual content of the tooltip

  • ReactElement: a React Element (instance of a React Component, usually created with JSX)

  Default value
null
5. [value] Boolean

The current value of the component. This value should be true or false.

  Default value
false