UNPKG

@fluentui/react-northstar

Version:
118 lines (116 loc) 4.12 kB
import _invoke from "lodash/invoke"; import _get from "lodash/get"; import { textAreaBehavior } from '@fluentui/accessibility'; import * as React from 'react'; import * as PropTypes from 'prop-types'; import { commonPropTypes, createShorthandFactory } from '../../utils'; import { useAutoControlled, getElementType, useTelemetry, useUnhandledProps, useFluentContext, useAccessibility, useStyles } from '@fluentui/react-bindings'; export var textAreaClassName = 'ui-textarea'; /** * A TextArea is a multi-line plan-text editing control. * * @accessibility * For good screen reader experience set `aria-label` or `aria-labelledby` attribute for textarea. * When using maxlength attribute, provide the information about max length in label for screen reader. * @accessibilityIssues * [NVDA - No announcement of maxlength](https://github.com/nvaccess/nvda/issues/7910) * [JAWS - textarea - no announcement of maxlength](https://github.com/FreedomScientific/VFO-standards-support/issues/300) */ export var TextArea = /*#__PURE__*/function () { var TextArea = /*#__PURE__*/React.forwardRef(function (props, ref) { var context = useFluentContext(); var _useTelemetry = useTelemetry(TextArea.displayName, context.telemetry), setStart = _useTelemetry.setStart, setEnd = _useTelemetry.setEnd; setStart(); var disabled = props.disabled, accessibility = props.accessibility, inverted = props.inverted, resize = props.resize, fluid = props.fluid, className = props.className, design = props.design, styles = props.styles, variables = props.variables, error = props.error; var _useAutoControlled = useAutoControlled({ defaultValue: props.defaultValue, value: props.value, initialValue: '' }), value = _useAutoControlled[0], setValue = _useAutoControlled[1]; var unhandledProps = useUnhandledProps(TextArea.handledProps, props); var getA11yProps = useAccessibility(accessibility, { debugName: TextArea.displayName, mapPropsToBehavior: function mapPropsToBehavior() { return { disabled: disabled }; }, rtl: context.rtl }); var _useStyles = useStyles(TextArea.displayName, { className: textAreaClassName, mapPropsToStyles: function mapPropsToStyles() { return { inverted: inverted, resize: resize, fluid: fluid, disabled: disabled, error: error }; }, mapPropsToInlineStyles: function mapPropsToInlineStyles() { return { className: className, design: design, styles: styles, variables: variables }; }, rtl: context.rtl }), classes = _useStyles.classes; var ElementType = getElementType(props); var handleChange = function handleChange(e) { var newValue = _get(e, 'target.value'); _invoke(props, 'onChange', e, Object.assign({}, props, { value: newValue })); setValue(newValue); }; var element = /*#__PURE__*/React.createElement(ElementType, getA11yProps('root', Object.assign({ className: classes.root, value: value, disabled: disabled, ref: ref, onChange: handleChange }, unhandledProps))); setEnd(); return element; }); TextArea.displayName = 'TextArea'; TextArea.propTypes = Object.assign({}, commonPropTypes.createCommon({ content: false }), { defaultValue: PropTypes.string, onChange: PropTypes.func, value: PropTypes.string, disabled: PropTypes.bool, inverted: PropTypes.bool, fluid: PropTypes.bool, error: PropTypes.bool, resize: PropTypes.oneOf(['none', 'both', 'horizontal', 'vertical']) }); TextArea.defaultProps = { as: 'textarea', accessibility: textAreaBehavior }; TextArea.handledProps = Object.keys(TextArea.propTypes); TextArea.create = createShorthandFactory({ Component: TextArea }); return TextArea; }(); //# sourceMappingURL=TextArea.js.map