@react-native-ama/forms 1.0.0
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/dist/core/src/components/AMAProvider.d.ts +26 -0
- package/dist/core/src/components/AMAProvider.js +147 -0
- package/dist/core/src/components/AutofocusContainer.d.ts +9 -0
- package/dist/core/src/components/AutofocusContainer.js +58 -0
- package/dist/core/src/components/HideChildrenFromAccessibilityTree.d.ts +6 -0
- package/dist/core/src/components/HideChildrenFromAccessibilityTree.js +40 -0
- package/dist/core/src/hooks/useButtonChecks.d.ts +6 -0
- package/dist/core/src/hooks/useButtonChecks.js +51 -0
- package/dist/core/src/hooks/useChecks.d.ts +15 -0
- package/dist/core/src/hooks/useChecks.js +152 -0
- package/dist/core/src/hooks/useFocus.d.ts +4 -0
- package/dist/core/src/hooks/useFocus.js +55 -0
- package/dist/core/src/hooks/useTimedAction.d.ts +3 -0
- package/dist/core/src/hooks/useTimedAction.js +63 -0
- package/dist/core/src/index.d.ts +7 -0
- package/dist/core/src/index.js +20 -0
- package/dist/forms/src/components/Form.d.ts +24 -0
- package/dist/forms/src/components/Form.js +122 -0
- package/dist/forms/src/components/FormField.d.ts +7 -0
- package/dist/forms/src/components/FormField.js +52 -0
- package/dist/forms/src/components/FormSubmit.d.ts +10 -0
- package/dist/forms/src/components/FormSubmit.js +25 -0
- package/dist/forms/src/components/FormSwitch.d.ts +4 -0
- package/dist/forms/src/components/FormSwitch.js +15 -0
- package/dist/forms/src/components/TextInput.d.ts +26 -0
- package/dist/forms/src/components/TextInput.js +123 -0
- package/dist/forms/src/hooks/useFormField.d.ts +26 -0
- package/dist/forms/src/hooks/useFormField.js +92 -0
- package/dist/forms/src/hooks/useTextInput.d.ts +350 -0
- package/dist/forms/src/hooks/useTextInput.js +102 -0
- package/dist/forms/src/index.d.ts +16 -0
- package/dist/forms/src/index.js +24 -0
- package/dist/internal/src/checks/checkAccessibilityRole.d.ts +3 -0
- package/dist/internal/src/checks/checkAccessibilityRole.js +32 -0
- package/dist/internal/src/checks/checkFocusTrap.d.ts +8 -0
- package/dist/internal/src/checks/checkFocusTrap.js +34 -0
- package/dist/internal/src/checks/checkForAccessibilityState.d.ts +7 -0
- package/dist/internal/src/checks/checkForAccessibilityState.js +48 -0
- package/dist/internal/src/checks/checkMinimumSize.d.ts +3 -0
- package/dist/internal/src/checks/checkMinimumSize.js +29 -0
- package/dist/internal/src/checks/contrastChecker.d.ts +8 -0
- package/dist/internal/src/checks/contrastChecker.js +77 -0
- package/dist/internal/src/checks/noUndefinedProperty.d.ts +8 -0
- package/dist/internal/src/checks/noUndefinedProperty.js +14 -0
- package/dist/internal/src/checks/uppercaseChecker.d.ts +8 -0
- package/dist/internal/src/checks/uppercaseChecker.js +18 -0
- package/dist/internal/src/checks/uppercaseStringChecker.d.ts +8 -0
- package/dist/internal/src/checks/uppercaseStringChecker.js +29 -0
- package/dist/internal/src/index.d.ts +20 -0
- package/dist/internal/src/index.js +56 -0
- package/dist/internal/src/types.d.ts +17 -0
- package/dist/internal/src/types.js +2 -0
- package/dist/internal/src/utils/applyStyle.d.ts +9 -0
- package/dist/internal/src/utils/applyStyle.js +33 -0
- package/dist/internal/src/utils/constants.d.ts +3 -0
- package/dist/internal/src/utils/constants.js +32 -0
- package/dist/internal/src/utils/error.style.d.ts +6 -0
- package/dist/internal/src/utils/error.style.js +11 -0
- package/dist/internal/src/utils/generateAccessibilityStateFromProp.d.ts +9 -0
- package/dist/internal/src/utils/generateAccessibilityStateFromProp.js +35 -0
- package/dist/internal/src/utils/getPropertyFromStyle.d.ts +2 -0
- package/dist/internal/src/utils/getPropertyFromStyle.js +10 -0
- package/dist/internal/src/utils/interpolateAnimationStates.d.ts +2 -0
- package/dist/internal/src/utils/interpolateAnimationStates.js +43 -0
- package/dist/internal/src/utils/isFocused.d.ts +2 -0
- package/dist/internal/src/utils/isFocused.js +7 -0
- package/dist/internal/src/utils/logger.d.ts +16 -0
- package/dist/internal/src/utils/logger.js +53 -0
- package/dist/internal/src/utils/logger.rules.d.ts +15 -0
- package/dist/internal/src/utils/logger.rules.js +74 -0
- package/dist/internal/src/utils/maybeGenerateStringFromElement.d.ts +2 -0
- package/dist/internal/src/utils/maybeGenerateStringFromElement.js +51 -0
- package/dist/internal/src/utils/minimumTouchableSize.d.ts +3 -0
- package/dist/internal/src/utils/minimumTouchableSize.js +9 -0
- package/dist/react-native/src/components/ExpandablePressable.d.ts +6 -0
- package/dist/react-native/src/components/ExpandablePressable.js +26 -0
- package/dist/react-native/src/components/Pressable.d.ts +5 -0
- package/dist/react-native/src/components/Pressable.js +49 -0
- package/dist/react-native/src/components/SwitchListItem.d.ts +12 -0
- package/dist/react-native/src/components/SwitchListItem.js +44 -0
- package/dist/react-native/src/components/SwitchWrapper.d.ts +11 -0
- package/dist/react-native/src/components/SwitchWrapper.js +36 -0
- package/dist/react-native/src/components/Text.d.ts +6 -0
- package/dist/react-native/src/components/Text.js +77 -0
- package/dist/react-native/src/components/TouchableOpacity.d.ts +6 -0
- package/dist/react-native/src/components/TouchableOpacity.js +48 -0
- package/dist/react-native/src/components/TouchableWithoutFeedback.d.ts +5 -0
- package/dist/react-native/src/components/TouchableWithoutFeedback.js +48 -0
- package/dist/react-native/src/hooks/useExpandable.d.ts +13 -0
- package/dist/react-native/src/hooks/useExpandable.js +31 -0
- package/dist/react-native/src/hooks/usePressable.d.ts +16 -0
- package/dist/react-native/src/hooks/usePressable.js +44 -0
- package/dist/react-native/src/hooks/useSwitch.d.ts +10 -0
- package/dist/react-native/src/hooks/useSwitch.js +25 -0
- package/dist/react-native/src/index.d.ts +10 -0
- package/dist/react-native/src/index.js +25 -0
- package/package.json +82 -0
- package/src/components/Form.test.tsx +262 -0
- package/src/components/Form.tsx +138 -0
- package/src/components/FormField.test.tsx +54 -0
- package/src/components/FormField.tsx +45 -0
- package/src/components/FormSubmit.test.tsx +71 -0
- package/src/components/FormSubmit.tsx +43 -0
- package/src/components/FormSwitch.tsx +17 -0
- package/src/components/TextInput.test.tsx +540 -0
- package/src/components/TextInput.tsx +168 -0
- package/src/hooks/useFormField.test.tsx +183 -0
- package/src/hooks/useFormField.ts +133 -0
- package/src/hooks/useTextInput.ts +128 -0
- package/src/index.ts +39 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
TouchableWithoutFeedback,
|
|
4
|
+
TouchableWithoutFeedbackProps,
|
|
5
|
+
View,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
|
|
8
|
+
import { UseFormField, useFormField } from '../hooks/useFormField';
|
|
9
|
+
|
|
10
|
+
export type FormFieldProps = React.PropsWithChildren<
|
|
11
|
+
TouchableWithoutFeedbackProps &
|
|
12
|
+
Omit<
|
|
13
|
+
UseFormField,
|
|
14
|
+
'hasFocusCallback' | 'nextFormFieldRef' | 'nextFieldId' | 'editable'
|
|
15
|
+
> & {
|
|
16
|
+
wrapInsideAccessibleView?: boolean;
|
|
17
|
+
}
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export const FormField = ({
|
|
21
|
+
children,
|
|
22
|
+
wrapInsideAccessibleView = true,
|
|
23
|
+
...props
|
|
24
|
+
}: FormFieldProps) => {
|
|
25
|
+
const viewRef = React.useRef<React.ElementRef<
|
|
26
|
+
typeof TouchableWithoutFeedback
|
|
27
|
+
> | null>(null);
|
|
28
|
+
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
const formProps = useFormField({
|
|
31
|
+
hasFocusCallback: false,
|
|
32
|
+
ref: viewRef,
|
|
33
|
+
...props,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return wrapInsideAccessibleView ? (
|
|
37
|
+
<TouchableWithoutFeedback {...props} ref={viewRef} {...formProps}>
|
|
38
|
+
<View accessible>{children}</View>
|
|
39
|
+
</TouchableWithoutFeedback>
|
|
40
|
+
) : (
|
|
41
|
+
<TouchableWithoutFeedback {...props} ref={viewRef} {...formProps}>
|
|
42
|
+
<>{children}</>
|
|
43
|
+
</TouchableWithoutFeedback>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { render } from '@testing-library/react-native';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Pressable, View } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import { FormSubmit } from './FormSubmit';
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
jest.clearAllMocks();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe('FormSubmit', () => {
|
|
12
|
+
it('wraps the children inside a Pressable component with the correct accessibility role and label', () => {
|
|
13
|
+
const { getByTestId, UNSAFE_getByType } = render(
|
|
14
|
+
<FormSubmit
|
|
15
|
+
accessibilityLabel="This is the label"
|
|
16
|
+
busy={false}
|
|
17
|
+
testID="test-me"
|
|
18
|
+
/>,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
expect(UNSAFE_getByType(Pressable)).toBeTruthy();
|
|
22
|
+
expect(getByTestId('test-me').props).toEqual(
|
|
23
|
+
expect.objectContaining({
|
|
24
|
+
accessibilityRole: 'button',
|
|
25
|
+
accessibilityLabel: 'This is the label',
|
|
26
|
+
accessibilityState: {
|
|
27
|
+
busy: false,
|
|
28
|
+
},
|
|
29
|
+
busy: false,
|
|
30
|
+
accessible: true,
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('hides the children from the accessiblity tree', () => {
|
|
36
|
+
const { getByTestId } = render(
|
|
37
|
+
<FormSubmit
|
|
38
|
+
accessibilityLabel="This is the label"
|
|
39
|
+
busy={false}
|
|
40
|
+
testID="test-me">
|
|
41
|
+
<View testID="child" />
|
|
42
|
+
</FormSubmit>,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(getByTestId('child').props).toEqual({
|
|
46
|
+
accessibilityElementsHidden: true,
|
|
47
|
+
children: null,
|
|
48
|
+
importantForAccessibility: 'no',
|
|
49
|
+
testID: 'child',
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
jest.mock('../hooks/useFormField', () => {
|
|
55
|
+
return {
|
|
56
|
+
useFormField: jest.fn().mockReturnValue({}),
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
jest.mock('@react-native-ama/core', () => {
|
|
61
|
+
const originalModule = jest.requireActual('@react-native-ama/core');
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
...originalModule,
|
|
65
|
+
useAMAContext: () => {
|
|
66
|
+
return {
|
|
67
|
+
isScreenReaderEnabled: true,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useAMAContext } from '@react-native-ama/core';
|
|
2
|
+
import { HideChildrenFromAccessibilityTree } from '@react-native-ama/core';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Pressable, PressableProps } from 'react-native';
|
|
5
|
+
|
|
6
|
+
import { useForm } from '../components/Form';
|
|
7
|
+
|
|
8
|
+
export type FormSubmitProps = React.PropsWithChildren<{
|
|
9
|
+
accessibilityLabel: string;
|
|
10
|
+
accessibilityHint?: string;
|
|
11
|
+
busy: boolean;
|
|
12
|
+
style?: PressableProps['style'];
|
|
13
|
+
testID?: string;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
export const FormSubmit = (props: FormSubmitProps) => {
|
|
17
|
+
const { submitForm } = useForm();
|
|
18
|
+
const { isScreenReaderEnabled } = useAMAContext();
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Pressable
|
|
22
|
+
accessibilityRole="button"
|
|
23
|
+
pointerEvents="box-only" // prevent event propagation to children eg Pressable
|
|
24
|
+
{...props}
|
|
25
|
+
onPress={submitForm}>
|
|
26
|
+
{isScreenReaderEnabled ? (
|
|
27
|
+
<FormSubmitForScreenReader children={props.children} />
|
|
28
|
+
) : (
|
|
29
|
+
props.children
|
|
30
|
+
)}
|
|
31
|
+
</Pressable>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const FormSubmitForScreenReader = ({
|
|
36
|
+
children,
|
|
37
|
+
}: React.PropsWithChildren<{}>) => {
|
|
38
|
+
return (
|
|
39
|
+
<HideChildrenFromAccessibilityTree>
|
|
40
|
+
{children}
|
|
41
|
+
</HideChildrenFromAccessibilityTree>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SwitchListItem,
|
|
3
|
+
SwitchListItemProps,
|
|
4
|
+
} from '@react-native-ama/react-native';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { FormField } from './FormField';
|
|
8
|
+
|
|
9
|
+
export type FormSwitchProps = SwitchListItemProps;
|
|
10
|
+
|
|
11
|
+
export const FormSwitch = (props: FormSwitchProps) => {
|
|
12
|
+
return (
|
|
13
|
+
<FormField hasValidation={false}>
|
|
14
|
+
<SwitchListItem {...props} />
|
|
15
|
+
</FormField>
|
|
16
|
+
);
|
|
17
|
+
};
|