UNPKG

@datalayer/primer-rjsf

Version:

React JSON Schema Form (RJSF) for Primer

13 lines (12 loc) 1.26 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { FormControl, Textarea } from "@primer/react"; import { ariaDescribedByIds, } from "@rjsf/utils"; export default function TextareaWidget({ id, placeholder, value, label, disabled, autofocus, readonly, onBlur, onFocus, onChange, options, schema, uiSchema, required, rawErrors = [], registry, }) { const { schemaUtils } = registry; const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema) && (!!label || !!schema.title); const _onChange = ({ target: { value } }) => onChange(value === "" ? options.emptyValue : value); const _onBlur = ({ target: { value } }) => onBlur(id, value); const _onFocus = ({ target: { value } }) => onFocus(id, value); return (_jsxs(_Fragment, { children: [_jsx(FormControl.Label, { visuallyHidden: !displayLabel, htmlFor: id, children: label || schema.title }), _jsx(Textarea, { id: id, name: id, value: value ?? "", placeholder: placeholder, autoFocus: autofocus, required: required, disabled: disabled || readonly, validationStatus: rawErrors.length > 0 ? "error" : undefined, onChange: _onChange, onBlur: _onBlur, onFocus: _onFocus, block: true, "aria-describedby": ariaDescribedByIds(id) })] })); }