@agility/plenum-ui 2.1.18 → 2.1.19-rc2

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.
@@ -4,21 +4,13 @@ export interface ISimpleSelectOptions {
4
4
  value: string;
5
5
  }
6
6
  export interface ISelectProps {
7
- /** Label */
8
7
  label?: string;
9
- /** Select ID prop */
10
8
  id?: string;
11
- /** Select name prop */
12
9
  name?: string;
13
- /** List of options to display in the select menu */
14
10
  options: ISimpleSelectOptions[];
15
- /** Select name prop */
16
11
  onChange?(value: string): void;
17
- /** Select disabled state */
18
12
  isDisabled?: boolean;
19
- /** Select error state */
20
13
  isError?: boolean;
21
- /** Select required state */
22
14
  isRequired?: boolean;
23
15
  value?: string;
24
16
  className?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agility/plenum-ui",
3
- "version": "2.1.18",
3
+ "version": "2.1.19-rc2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -8,27 +8,20 @@ export interface ISimpleSelectOptions {
8
8
  value: string;
9
9
  }
10
10
  export interface ISelectProps {
11
- /** Label */
12
11
  label?: string;
13
- /** Select ID prop */
14
12
  id?: string;
15
- /** Select name prop */
16
13
  name?: string;
17
- /** List of options to display in the select menu */
18
14
  options: ISimpleSelectOptions[];
19
- /** Select name prop */
20
15
  onChange?(value: string): void;
21
- /** Select disabled state */
22
16
  isDisabled?: boolean;
23
- /** Select error state */
24
17
  isError?: boolean;
25
- /** Select required state */
26
18
  isRequired?: boolean;
27
19
  value?: string;
28
20
  className?: string;
29
21
  onFocus?: () => void;
30
22
  onBlur?: () => void;
31
23
  }
24
+
32
25
  const Select: React.FC<ISelectProps> = ({
33
26
  label,
34
27
  id,
@@ -43,22 +36,31 @@ const Select: React.FC<ISelectProps> = ({
43
36
  onFocus,
44
37
  onBlur
45
38
  }) => {
46
- const [selectedOption, setSelectedOption] = useState<string>(value || options[0].value);
39
+ const getValidVal = (val: string | undefined) => {
40
+ const validValue = val && val !== "" ? val : options[0]?.value ?? "select an option";
41
+ console.log("valid Val", validValue);
42
+ return validValue;
43
+ };
44
+ const [selectedOption, setSelectedOption] = useState<string>(getValidVal(value));
47
45
  const uniqueID = useId();
48
46
  if (!id) id = `select-${uniqueID}`;
49
47
  if (!name) name = id;
50
48
 
51
49
  useEffect(() => {
52
- if (value !== undefined && value !== null) {
50
+ // Explicitly handle falsy values
51
+ if (value !== undefined) {
53
52
  setSelectedOption(value);
54
53
  }
55
54
  }, [value]);
56
55
 
57
56
  const handleChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
58
57
  const targetValue = e.target.value;
59
- typeof onChange == "function" && onChange(targetValue);
58
+ if (typeof onChange === "function") {
59
+ onChange(targetValue);
60
+ }
60
61
  setSelectedOption(targetValue);
61
62
  };
63
+
62
64
  const wrapperStyle = cn("group", { "opacity-50": isDisabled });
63
65
  return (
64
66
  <div className={wrapperStyle}>
@@ -89,13 +91,11 @@ const Select: React.FC<ISelectProps> = ({
89
91
  onFocus={onFocus}
90
92
  onBlur={onBlur}
91
93
  >
92
- {options.map(({ value, label }) => {
93
- return (
94
- <option key={value} value={value}>
95
- {label}
96
- </option>
97
- );
98
- })}
94
+ {options.map(({ value, label }) => (
95
+ <option key={value} value={value}>
96
+ {label}
97
+ </option>
98
+ ))}
99
99
  </select>
100
100
  </div>
101
101
  );