@bitrise/bitkit 10.22.0 → 10.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "10.22.0",
4
+ "version": "10.22.1",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -0,0 +1,35 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { useForm } from 'react-hook-form';
4
+ import Textarea from './Textarea';
5
+
6
+ describe('Textarea', () => {
7
+ it('forwards data-testid', async () => {
8
+ render(<Textarea data-testid="testid" />);
9
+ const elem = await screen.findByTestId('testid');
10
+ expect(elem.tagName).toBe('TEXTAREA');
11
+ expect(elem).toBeInTheDocument();
12
+ });
13
+ describe('react-hook-form support', () => {
14
+ it('sends data when submitted', async () => {
15
+ const handler = jest.fn();
16
+ const TestComponent = () => {
17
+ const { register, handleSubmit } = useForm();
18
+ return (
19
+ <form onSubmit={handleSubmit((data) => handler(data))}>
20
+ <Textarea {...register('textarea')} />
21
+ <button type="submit">Send</button>
22
+ </form>
23
+ );
24
+ };
25
+ render(<TestComponent />);
26
+ const submit = await screen.findByRole('button', { name: 'Send' });
27
+ const textarea = await screen.findByRole('textbox');
28
+ await userEvent.type(textarea, 'test');
29
+ await userEvent.click(submit);
30
+
31
+ expect(handler).toHaveBeenCalledWith({ textarea: 'test' });
32
+ expect(handler).toHaveBeenCalledTimes(1);
33
+ });
34
+ });
35
+ });
@@ -10,13 +10,15 @@ import {
10
10
  forwardRef,
11
11
  } from '@chakra-ui/react';
12
12
 
13
- export interface TextareaProps extends Omit<FormControlProps, 'label' | 'onChange'> {
14
- dataTestid?: string;
13
+ export interface TextareaProps extends Omit<FormControlProps, 'label' | 'onChange' | 'onBlur'> {
14
+ 'data-testid'?: string;
15
15
  errorText?: string;
16
16
  isLoading?: boolean;
17
17
  helpherText?: string;
18
18
  label?: ReactNode;
19
+ name?: string;
19
20
  onChange?: ChakraTextareaProps['onChange'];
21
+ onBlur?: ChakraTextareaProps['onBlur'];
20
22
  value?: ChakraTextareaProps['value'];
21
23
  }
22
24
 
@@ -25,7 +27,7 @@ export interface TextareaProps extends Omit<FormControlProps, 'label' | 'onChang
25
27
  */
26
28
  const Textarea = forwardRef<TextareaProps, 'div'>((props, ref) => {
27
29
  const {
28
- dataTestid,
30
+ 'data-testid': dataTestid,
29
31
  errorText,
30
32
  helpherText,
31
33
  isDisabled,
@@ -34,12 +36,16 @@ const Textarea = forwardRef<TextareaProps, 'div'>((props, ref) => {
34
36
  label,
35
37
  placeholder,
36
38
  onChange,
39
+ onBlur,
40
+ name,
37
41
  value,
38
42
  ...rest
39
43
  } = props;
40
44
  const textareaProps = {
41
- dataTestid,
45
+ 'data-testid': dataTestid,
42
46
  onChange,
47
+ onBlur,
48
+ name,
43
49
  placeholder,
44
50
  value,
45
51
  };