@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyphen/hyphen-components",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "@hyphen"
@@ -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' },
@@ -18,6 +18,7 @@ const options = [
18
18
  { value: 'chocolate', label: 'Chocolate' },
19
19
  { value: 'strawberry', label: 'Strawberry' },
20
20
  { value: 'vanilla', label: 'Vanilla' },
21
+ { value: 'mint', label: 'Mint', disabled: true },
21
22
  ];
22
23
 
23
24
  export const Default = () => {
@@ -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: { value: string | number; label: string | number }[];
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 = { value: '', label: placeholder };
64
- const optionsWithPlaceholder = [{ ...placeholderOption }, ...options];
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.value === ''}
123
+ disabled={option.disabled ?? false}
111
124
  hidden={option.value === ''}
112
125
  color={option.value === '' ? 'disabled' : 'base'}
113
126
  >