TextAreaWithDiff

How to get TextAreaWithDiff

import { TextAreaWithDiff } from 'fds/components';

Type: Component

A special version of TextArea that has an extra "originalValue" prop. This prop is compared to the current "value" and a "Show changes" text link is rendered below the text area to toggle between an editable text area and a non-editable diff view. The diff is visualized by rendering red strikethrough and underlined text for deletions and green underlined text for additions.

Props

# Name Type Description
1. [isDisabled] Boolean

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

  Default value
false
2. [name] String

The name of this component to identify it (and its value) when used inside an intelligent container component which aggregates its children (and/or their values), like a Form.

  Default value
null
3. [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.

4. [originalValue] String

The original value to compare the current "value" against.

Important: Make sure to set BOTH the "value" and the "originalValue" props to start with an empty diff. Then only update the "value" prop when "onChange" is called.


  Default value
""
5. [placeholder] String

The placeholder text displayed in component when it is empty, i.e. has no values.

  Default value
""
6. [rows] Number | Object

The number of text lines that should be visible before overflowing and showing a vertical scrollbar.

When passing in a number, you specify a fixed amount of text lines.

When passing in an object with properties "minimum" and "maximum", the TextArea will auto-grow based on the amount of text lines present in the TextArea. Starting at the specified minimum and not exceeding the specified maximum. If the number of maximum rows is exceeded, a scrollbar will show.


  Default value
2
7. [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
8. [validate] Function

A callback that is called directly after the value(s) of a form component change(s).

Use this callback to check the selected value(s) against business rules and to set any feedback for the user based on this.


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

A single value or an array of values, depending on the component being validated.


  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.

  Returns

Type: Object

The result of validating form input.

Properties

Name Type Description
connotation String

Determines the text/border color of the feedback message.

Specifies the meaning and/or severity of the given feedback. The possible values are: (from least to most severe)

  • 'success'

  • 'info'

  • 'warning'

  • 'error'

message String

The textual content of the feedback message shown near the form component whose validate callback yielded this result.

  Default value
null
9. [value] String

The current value of the component. This value should be a valid string.

  Default value
""
Was this page helpful?