@meta-1/design 0.0.187 → 0.0.188

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": "@meta-1/design",
3
- "version": "0.0.187",
3
+ "version": "0.0.188",
4
4
  "keywords": [
5
5
  "easykit",
6
6
  "design",
@@ -1,4 +1,4 @@
1
- import { forwardRef, type MouseEvent, type ReactNode, useState } from "react";
1
+ import { forwardRef, type MouseEvent, type ReactNode, useRef, useState } from "react";
2
2
  import { XIcon } from "lucide-react";
3
3
 
4
4
  import { Empty } from "@meta-1/design/components/uix/empty";
@@ -46,22 +46,25 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>((props, _ref) =
46
46
  onOpenChange,
47
47
  ...rest
48
48
  } = props;
49
-
50
- const [innerValue, setInnerValue] = useState<string | undefined>(defaultValue);
51
- const isControlled = value !== undefined;
49
+ const initValue = useRef(value);
50
+ const [innerValue, setInnerValue] = useState<string | undefined>();
51
+ const isControlled = initValue.current !== undefined;
52
52
  const currentValue = isControlled ? value : innerValue;
53
53
 
54
54
  const handleChange = (val: string) => {
55
- if (onChange) {
56
- // 尝试找到原始选项,返回原始类型的 value
57
- const option = options.find((opt) => String(opt.value) === val);
58
- if (option) {
59
- onChange(option.value);
60
- }
61
- }
62
55
  if (!isControlled) {
63
56
  setInnerValue(val);
64
57
  }
58
+ if (onChange) {
59
+ if (val === "") {
60
+ onChange("");
61
+ } else {
62
+ const option = options.find((opt) => String(opt.value) === val);
63
+ if (option) {
64
+ onChange(option.value);
65
+ }
66
+ }
67
+ }
65
68
  };
66
69
 
67
70
  const clear = (e: MouseEvent<HTMLDivElement>) => {
@@ -76,7 +79,7 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>((props, _ref) =
76
79
  onOpenChange={onOpenChange}
77
80
  onValueChange={handleChange}
78
81
  open={open}
79
- value={currentValue !== undefined ? String(currentValue) : undefined}
82
+ value={currentValue as string | undefined}
80
83
  >
81
84
  <div className={cn("relative inline-block", allowClear && currentValue ? "group" : "", className)}>
82
85
  <SelectTrigger className={cn("flex w-full", triggerClassName)}>