Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FormTextArea): Add new FormTextArea component #16660

Merged
1 change: 1 addition & 0 deletions packages/fluentui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Features
- Added `disabledFocusable` prop for `Button` component. @jurokapsiar ([#16419](https://github.com/microsoft/fluentui/pull/16419))
- Added `FormTextArea` component @assuncaocharles ([#16660](https://github.com/microsoft/fluentui/pull/16660))

## Performance

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Form, Button, Input, FormField, FormLabel, FormMessage } from '@fluentui/react-northstar';
import { Form, Button, Input, FormField, FormLabel, FormMessage, FormTextArea } from '@fluentui/react-northstar';
import { PresenceAvailableIcon } from '@fluentui/react-icons-northstar';

const FormExampleErrorAndSatisfactory = () => (
Expand All @@ -24,6 +24,7 @@ const FormExampleErrorAndSatisfactory = () => (
errorMessage="You can not fix this error"
required
/>
<FormTextArea name="bio" id="bio" label="bio" errorMessage="You can not fix this error" />
assuncaocharles marked this conversation as resolved.
Show resolved Hide resolved
<FormField>
<FormLabel id="email-label" htmlFor="email-field">
E-mail*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
FormCheckbox,
FormDatepicker,
FormButton,
FormTextArea,
} from '@fluentui/react-northstar';

const items = [
Expand Down Expand Up @@ -35,6 +36,7 @@ const items = [
const FormExampleComponents = () => (
<Form>
<FormInput label="First name" name="firstName" required />
<FormTextArea label="Bio" name="bio" />
<FormDropdown label="City" items={['prague', 'new york']} />
<FormRadioGroup label="Pizza" vertical defaultCheckedValue="prosciutto" items={items} />
<FormSlider label="Bid the price" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { compose } from '@fluentui/react-bindings';
import { TextArea, TextAreaProps } from '../TextArea/TextArea';
import { _FormFieldBase, FormFieldBaseProps } from './utils/formFieldBase';
import { commonPropTypes } from '../../utils';

interface FormTextAreaOwnProps extends Omit<TextAreaProps, 'accessibility'> {}
type SelectedFormFieldCustomProps = Omit<
FormFieldBaseProps,
'control' | 'styles' | 'accessibility' | 'design' | 'variables'
>;
export interface FormTextAreaProps extends SelectedFormFieldCustomProps, FormTextAreaOwnProps {}
export type FormTextAreaStylesProps = never;

export const formTextAreaClassName = 'ui-form__textarea';

/**
* An FormTextArea renders a TextArea wrapped by FormField.
*/
export const FormTextArea = compose<
'textarea',
FormTextAreaProps,
FormTextAreaStylesProps,
SelectedFormFieldCustomProps,
{}
>(_FormFieldBase, {
className: formTextAreaClassName,
displayName: 'FormTextArea',
overrideStyles: true,
slots: {
control: TextArea,
},
slotProps: ({ errorMessage }) => ({
control: {
error: !!errorMessage,
},
message: {
error: !!errorMessage,
},
}),
});

FormTextArea.propTypes = commonPropTypes.createCommon({
children: false,
content: false,
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ export interface TextAreaProps extends UIComponentProps, ChildrenComponentProps

/** A textarea can take the width of its container. */
fluid?: boolean;

/** A text area can have error state. */
error?: boolean;
}

export type TextAreaStylesProps = Required<Pick<TextAreaProps, 'inverted' | 'resize' | 'fluid' | 'disabled'>>;
export type TextAreaStylesProps = Required<Pick<TextAreaProps, 'inverted' | 'resize' | 'fluid' | 'disabled' | 'error'>>;

export const textAreaClassName = 'ui-textarea';

Expand All @@ -67,7 +70,7 @@ export const TextArea: ComponentWithAs<'textarea', TextAreaProps> &

setStart();

const { disabled, accessibility, inverted, resize, fluid, className, design, styles, variables } = props;
const { disabled, accessibility, inverted, resize, fluid, className, design, styles, variables, error } = props;

const [value, setValue] = useAutoControlled({
defaultValue: props.defaultValue,
Expand All @@ -92,6 +95,7 @@ export const TextArea: ComponentWithAs<'textarea', TextAreaProps> &
resize,
fluid,
disabled,
error,
}),
mapPropsToInlineStyles: () => ({
className,
Expand Down Expand Up @@ -138,6 +142,7 @@ TextArea.propTypes = {
disabled: PropTypes.bool,
inverted: PropTypes.bool,
fluid: PropTypes.bool,
error: PropTypes.bool,
resize: PropTypes.oneOf(['none', 'both', 'horizontal', 'vertical']),
};

Expand Down
1 change: 1 addition & 0 deletions packages/fluentui/react-northstar/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export * from './components/Flex/FlexItem';
export * from './components/Form/Form';
export * from './components/Form/FormField';
export * from './components/Form/FormInput';
export * from './components/Form/FormTextArea';
export * from './components/Form/FormInput';
export * from './components/Form/FormLabel';
export * from './components/Form/FormMessage';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TextAreaVariables } from './textAreaVariables';
import { ComponentSlotStylesPrepared, ICSSInJSStyle } from '@fluentui/styles';
import { TextAreaStylesProps } from '../../../../components/TextArea/TextArea';
import { pxToRem } from '../../../../utils';

export const textAreaStyles: ComponentSlotStylesPrepared<TextAreaStylesProps, TextAreaVariables> = {
root: ({ props: p, variables: v }): ICSSInJSStyle => ({
Expand Down Expand Up @@ -34,6 +35,8 @@ export const textAreaStyles: ComponentSlotStylesPrepared<TextAreaStylesProps, Te
color: v.disabledColor,
}),

...(p.error && { border: `${pxToRem(1)} solid ${v.borderColorError}` }),

'::placeholder': {
color: v.placeholderColor,
opacity: 1, // undo Firefox default opacity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface TextAreaVariables {
margin: string;
padding: string;
height: string;
borderColorError: string;
}

export const textAreaVariables = (siteVars): TextAreaVariables => ({
Expand All @@ -38,4 +39,5 @@ export const textAreaVariables = (siteVars): TextAreaVariables => ({
borderColorFocus: `transparent transparent ${siteVars.colorScheme.brand.borderFocus1} transparent`,

height: 'auto',
borderColorError: siteVars.colorScheme.red.background,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { isConformant } from 'test/specs/commonTests';
import { FormTextArea } from 'src/components/Form/FormTextArea';

import { TextArea } from 'src/components/TextArea/TextArea';

describe('FormTextArea', () => {
isConformant(FormTextArea, {
testPath: __filename,
constructorName: 'FormTextArea',
forwardsRefTo: false,
targetComponent: TextArea,
});
});