@hyphen/hyphen-components 7.1.0 → 7.2.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/components/SelectInputNative/SelectInputNative.d.ts +6 -4
- package/dist/hyphen-components.cjs.development.js +5 -3
- package/dist/hyphen-components.cjs.development.js.map +1 -1
- package/dist/hyphen-components.cjs.production.min.js +1 -1
- package/dist/hyphen-components.cjs.production.min.js.map +1 -1
- package/dist/hyphen-components.esm.js +5 -3
- package/dist/hyphen-components.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Formik/Formik.stories.tsx +1 -0
- package/src/components/SelectInputNative/SelectInputNative.stories.tsx +1 -0
- package/src/components/SelectInputNative/SelectInputNative.test.tsx +15 -1
- package/src/components/SelectInputNative/SelectInputNative.tsx +17 -4
package/package.json
CHANGED
|
@@ -42,6 +42,7 @@ export const FormikForm = () =>
|
|
|
42
42
|
{ value: 'chocolate', label: 'Chocolate' },
|
|
43
43
|
{ value: 'strawberry', label: 'Strawberry' },
|
|
44
44
|
{ value: 'vanilla', label: 'Vanilla' },
|
|
45
|
+
{ value: 'mint', label: 'Mint', disabled: true },
|
|
45
46
|
];
|
|
46
47
|
const colorOptions = [
|
|
47
48
|
{ value: 'red', label: 'red' },
|
|
@@ -5,9 +5,23 @@ import { SelectInputNative } from './SelectInputNative';
|
|
|
5
5
|
|
|
6
6
|
const selectOptions = [
|
|
7
7
|
{ value: 'chocolate', label: 'Chocolate' },
|
|
8
|
-
{ value: 'strawberry', label: 'Strawberry' },
|
|
8
|
+
{ value: 'strawberry', label: 'Strawberry', disabled: true },
|
|
9
9
|
{ value: 'vanilla', label: 'Vanilla' },
|
|
10
10
|
];
|
|
11
|
+
test('option with disabled property is rendered as disabled', () => {
|
|
12
|
+
const mockedHandleChange = jest.fn();
|
|
13
|
+
render(
|
|
14
|
+
<SelectInputNative
|
|
15
|
+
id="testId"
|
|
16
|
+
label="Disabled Option Test"
|
|
17
|
+
onChange={mockedHandleChange}
|
|
18
|
+
options={selectOptions}
|
|
19
|
+
value={null}
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
const option = screen.getByText('Strawberry');
|
|
23
|
+
expect(option).toBeDisabled();
|
|
24
|
+
});
|
|
11
25
|
|
|
12
26
|
function getByTextWithMarkup(text: string) {
|
|
13
27
|
// eslint-disable-next-line
|
|
@@ -7,11 +7,17 @@ import { FormControl, FormControlProps } from '../FormControl/FormControl';
|
|
|
7
7
|
import styles from './SelectInputNative.module.scss';
|
|
8
8
|
|
|
9
9
|
export type SelectInputNativeSize = 'sm' | 'md' | 'lg';
|
|
10
|
+
export interface SelectInputNativeOption {
|
|
11
|
+
value: string | number;
|
|
12
|
+
label: string | number;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
export interface SelectInputNativeProps extends BoxProps, FormControlProps {
|
|
11
17
|
/**
|
|
12
18
|
* List of options for the select input.
|
|
13
19
|
*/
|
|
14
|
-
options:
|
|
20
|
+
options: SelectInputNativeOption[];
|
|
15
21
|
/**
|
|
16
22
|
* onChange callback from select element.
|
|
17
23
|
*/
|
|
@@ -60,8 +66,15 @@ export const SelectInputNative: React.FC<SelectInputNativeProps> = ({
|
|
|
60
66
|
size = 'md',
|
|
61
67
|
...restProps
|
|
62
68
|
}) => {
|
|
63
|
-
const placeholderOption = {
|
|
64
|
-
|
|
69
|
+
const placeholderOption: SelectInputNativeOption = {
|
|
70
|
+
value: '',
|
|
71
|
+
label: placeholder,
|
|
72
|
+
disabled: true,
|
|
73
|
+
};
|
|
74
|
+
const optionsWithPlaceholder: SelectInputNativeOption[] = [
|
|
75
|
+
placeholderOption,
|
|
76
|
+
...options,
|
|
77
|
+
];
|
|
65
78
|
|
|
66
79
|
const responsiveClasses = generateResponsiveClasses('size', size);
|
|
67
80
|
|
|
@@ -107,7 +120,7 @@ export const SelectInputNative: React.FC<SelectInputNativeProps> = ({
|
|
|
107
120
|
as="option"
|
|
108
121
|
key={option.value}
|
|
109
122
|
value={option.value}
|
|
110
|
-
disabled={option.
|
|
123
|
+
disabled={option.disabled ?? false}
|
|
111
124
|
hidden={option.value === ''}
|
|
112
125
|
color={option.value === '' ? 'disabled' : 'base'}
|
|
113
126
|
>
|