9.0.0 • Published 25 days ago

@leafygreen-ui/text-area v9.0.0

Weekly downloads
13
License
Apache-2.0
Repository
github
Last release
25 days ago

Text Area

npm (scoped)

View on MongoDB.design

Installation

Yarn

yarn add @leafygreen-ui/text-area

NPM

npm install @leafygreen-ui/text-area

Example

import TextArea from '@leafygreen-ui/text-area';

const [value, setValue] = useState('');

return (
  <TextArea
    label="Text Area Label"
    description="This is the description for the text area"
    onChange={event => {
      /* Something to handle the change event */
    }}
    value={value}
  />
);

Properties

PropTypeDescriptionDefault
idstringid to describe the <textarea> element
darkModebooleanDetermines whether or not the component will appear in dark mode.false
labelstringLabel for <textarea>
descriptionReact.ReactNodeDescription below label
state'none', 'valid', 'error'Determines the state of the <textarea>'none'
classNamestringclassName applied to the container element
disabledbooleanDetermines if the component is disabledfalse
onChangefunctionThe event handler function for the 'onchange' event. Accepts the change event object as its argument and returns nothing.
onBlurfunctionThe event handler function for the 'onblur' event. Accepts the focus event object as its argument and returns nothing.

Test Harnesses

getTestUtils()

getTestUtils() is a util that allows consumers to reliably interact with LG TextArea in a product test suite. If the TextArea component cannot be found, an error will be thrown.

Usage

import TextArea, { getTestUtils } from '@leafygreen-ui/text-area';

const utils = getTestUtils(lgId?: string); // lgId refers to the custom `data-lgid` attribute passed to `TextArea`. It defaults to 'lg-text_area' if left empty.

Single TextArea

import { render } from '@testing-library/react';
import TextArea, { getTestUtils } from '@leafygreen-ui/text-area';

...

test('text-area', () => {
  render(<TextArea label="label" value="text area" />);
  const { getInput, getInputValue } = getTestUtils();

  expect(getInput()).toBeInTheDocument();
  expect(getInputValue()).toBe('text area');
});

Multiple TextArea's

When testing multiple TextArea's it is recommended to add the custom data-lgid attribute to each TextArea.

import { render } from '@testing-library/react';
import TextArea, { getTestUtils } from '@leafygreen-ui/text-area';

...

test('text-area', () => {
  render(
    <>
      <TextArea data-lgid="text-area-1" label="label 1" />
      <TextArea data-lgid="text-area-2" label="label 2" value="text area" />
    </>,
  );
  const utilsOne = getTestUtils('text-area-1'); // data-lgid
  const utilsTwo = getTestUtils('text-area-2'); // data-lgid

  // First TextArea
  expect(utilsOne.getInput()).toBeInTheDocument();
  expect(utilsOne.getInputValue()).toBe('');

  // Second TextArea
  expect(utilsTwo.getInput()).toBeInTheDocument();
  expect(utilsTwo.getInputValue()).toBe('text area');
});

TextArea with other LG form elements

import { render } from '@testing-library/react';
import Toggle, { getTestUtils as getToggleTestUtils } from '@leafygreen-ui/toggle';
import TextInput, { getTestUtils as getTextInputTestUtils } from '@leafygreen-ui/text-input';
import TextArea, { getTestUtils as getTextAreaTestUtils } from '@leafygreen-ui/text-area';

...

test('Form', () => {
  render(
    <Form>
      <Toggle aria-label="Toggle label" />
      <TextInput label="TextInput label" />
      <TextArea label="TextArea label" />
    </Form>,
  );

  const toggleInputUtils = getToggleTestUtils();
  const textInputUtils = getTextInputTestUtils();
  const textAreaUtils = getTextAreaTestUtils();

  // LG Toggle
  expect(toggleInputUtils.getInput()).toBeInTheDocument();
  expect(toggleInputUtils.getInputValue()).toBe('false');

  // LG TextInput
  expect(textInputUtils.getInput()).toBeInTheDocument();
  expect(textInputUtils.getInputValue()).toBe('');

  // LG TextArea
  expect(textAreaUtils.getInput()).toBeInTheDocument();
  expect(textAreaUtils.getInputValue()).toBe('');
});

Test Utils

Elements

const {
  getInput,
  getLabel,
  getDescription,
  getErrorMessage,
  getInputValue,
  isDisabled,
  isError,
} = getTestUtils();
UtilDescriptionReturns
getInputReturns the input nodeHTMLButtonElement
getLabelReturns the label nodeHTMLButtonElement | null
getDescriptionReturns the description nodeHTMLButtonElement | null
getErrorMessageReturns the error message nodeHTMLButtonElement | null
getInputValueReturns the input valuestring
isDisabledReturns whether the input is disabledboolean
isErrorReturns whether the input state is errorboolean
9.0.0

25 days ago

8.2.1

1 month ago

8.2.0

1 month ago

8.1.3

1 month ago

8.1.2

2 months ago

8.1.1

2 months ago

8.1.0

3 months ago

8.0.21

4 months ago

9.0.0-alpha.1

10 months ago

9.0.0-alpha.0

10 months ago

8.0.14

9 months ago

8.0.13

10 months ago

8.0.16

9 months ago

8.0.15

9 months ago

8.0.18

8 months ago

8.0.17

9 months ago

8.0.19

8 months ago

8.0.20

7 months ago

8.0.9

12 months ago

8.0.10

12 months ago

8.0.12

11 months ago

8.0.11

11 months ago

8.0.11-next.1

12 months ago

8.0.11-next.0

12 months ago

8.0.11-next.7

12 months ago

8.0.11-next.6

12 months ago

8.0.11-next.5

12 months ago

8.0.11-next.4

12 months ago

8.0.11-next.3

12 months ago

8.0.11-next.2

12 months ago

8.0.8

1 year ago

8.0.7

1 year ago

8.0.6

1 year ago

8.0.5

1 year ago

8.0.4

1 year ago

8.0.1

1 year ago

8.0.0

1 year ago

8.0.3

1 year ago

8.0.2

1 year ago

6.2.1

2 years ago

6.2.0

2 years ago

7.0.0

2 years ago

7.0.1

2 years ago

6.1.2

2 years ago

6.1.1

2 years ago

6.2.0-test.0

2 years ago

6.2.0-next.2

2 years ago

6.2.0-next.1

2 years ago

6.2.0-next.0

2 years ago

6.1.0

2 years ago

6.0.1

2 years ago

6.0.2

2 years ago

5.1.1

2 years ago

5.1.0

2 years ago

6.0.0

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.1.1

2 years ago

4.1.0

2 years ago

4.0.3

3 years ago

4.0.2

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.0.4

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.0

3 years ago

1.0.1

3 years ago

1.0.0

4 years ago