A textarea component for user input.
The component can be imported via:
The PlumaTextArea component accepts the following functions, corresponding
to native events on the input element:
onChangeonInputonFocusonBlurNote: The onChange function is not the idiomatic React onChange
callback (which acts more like the native input event).
To keep the component API consistent between frameworks, we expose event
handlers that correspond to the browser native event. This means that
TextAreas onChange only fires after a blur, for example (rather than while
typing).
A PlumaTextArea component should always be associated with a label. The
component accepts a label string prop, which will render the text above the
input:
Alternatively, the ariaLabelledby prop can be used to associate the input with
a label element elsewhere in the DOM. It is also recommended to add a for
attribute on the custom label, along with an id attribute on the input, to
ensure the label is properly associated with the input.
Finally, the ariaLabel prop can be used if no other element is suitable for
a label.
Additionally, a hint text can be added below the input with the description
prop:
The PlumaTextArea component accepts an isInvalid prop, which will render the
input in an error state:
It is also highly recommended to provide an error message when the input is
invalid. This will render below the input:
By default, pressing Enter in a textarea creates a new line. However, with the shouldSubmitOnEnter prop set to true, pressing Enter will submit the form instead of creating a new line. Users can still add a new line by pressing Shift+Enter.
By default, PlumaTextArea disables password manager autofill to prevent unwanted interference. This behavior can be controlled with the shouldAllowAutofill prop.
When to use:
shouldAllowAutofill={false} (default) for general text areas where password managers often interfere inappropriatelyshouldAllowAutofill={true} only if you specifically want password managers to function in this textarea (rare for textareas)When shouldAllowAutofill is false, the component adds attributes to disable common password managers (1Password, LastPass, Bitwarden, Dashlane) and sets autocomplete="off".
The PlumaTextArea component supports auto-growing height based on content with the minRows and maxRows props.
minRows sets the minimum number of visible rows when emptymaxRows sets the maximum number of rows before scrollingBy default, PlumaTextArea renders at full width and can be resized vertically (but not horizontally).
Note: In the code snippet examples above, the component is placed in a 300px wide container.
Below is a full width example without the constraint:
When rendered at full width, it cannot be resized horizontally (it always stretches to fill the container).
To allow horizontal resizing, isFullWidth must be set to false. Additionally, resize should be set to horizontal or both:
If a string label is not sufficient, a component can be used to render the label.
In React, the label prop accepts any ReactNode.
If a string description is not sufficient, a component can be used to render the description.
In React, the description prop accepts any ReactNode.
If a string error is not sufficient, a component can be used to render the error.
In React, the error prop accepts any ReactNode.
PlumaTextArea extends BoxElement (or elements) that describe the form field. Also used for error messages, as aria-errormessage isn't supported in all assistive technologies: https://a11ysupport.io/tech/aria/aria-errormessage_attribute
String value that labels the form field.
Element (or elements) that label the form field.
Visible width of the textarea.
A description for the field, providing additional context or hints.
An error message associated with the form field.
Boolean: Ember-only. If the error named block is used,
this prop can be set to true to indicate an error is present,
which will make the error block render.
An optional id to be assigned to the input element. Also used to generate ids for labels and error messages. If one isn't provided, it will be generated.
Whether the form field is disabled.
Default:true
Whether the textarea should stretch to fill the width of its container.
Set this to false if the textarea needs to be resized horizontally (via resize both or horizontal).
Whether the form field is in an invalid state.
The label text to show with the form field.
Maximum number of rows when auto-growing.
Minimum number of rows when auto-growing.
The name of the textarea.
The blur event handler for the textarea element.
The change event handler for the textarea element.
The focus event handler for the textarea element.
The input event handler for the textarea element.
The keydown event handler for the textarea element.
Placeholder text to show inside the field.
Default:vertical
Whether the textarea is resizable.
Number of visible text lines.
Whether to allow browser autofill and password managers. When false (default), adds attributes to disable password managers (1Password, LastPass, Bitwarden, Dashlane). Set to true for fields where autofill is desired (e.g., email, password, address fields).
Whether the generated description id should be included in the input's aria-describedby attribute.
Disable this when a label`` tag surrounds the input as well as it's description text, for example in an OptionCard` component.
Whether the generated label id should be included in the input's aria-labelledby attribute.
Disable this when the label tag surrounds the input as well as it's label text,
for example in an OptionCard component.
Default:false
When true, pressing Enter key will submit the form instead of creating a new line.
By default, form elements will throw an error if no label or aria-label is provided. Disable this to suppress the error, for example when building a custom form element, and you want to handle labeling yourself.
Additional classes to be applied to the description element.
Additional classes to be applied to the error element.
Additional classes to be applied to the field node.
Ember-only: this is used internally to detect whether a label
named block is present, and to ignore empty label props if so.
Additional classes to be applied to the input node.
Sets the size attribute on the input element. This controls the visible width of the input in characters.
Whether the component should render with "legacy" styles.
Additional classes to be applied to the label node.
Additional class to apply on the textarea element wrapper.
The current value.
Whether to apply the center-baseline variant.