diff --git a/package.json b/package.json index 33805c9..37c5adb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "n6-ui", - "version": "1.2.6", + "version": "1.2.7", "description": "N6 Network UI Framework", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -80,4 +80,4 @@ "tailwindcss": "^3.4.16", "zustand": "^5.0.2" } -} \ No newline at end of file +} diff --git a/src/NDropdown/NDropdown.tsx b/src/NDropdown/NDropdown.tsx index ad36742..af28311 100644 --- a/src/NDropdown/NDropdown.tsx +++ b/src/NDropdown/NDropdown.tsx @@ -7,14 +7,22 @@ interface NDropdownOption { interface NDropdownProps { options: NDropdownOption[]; - placeholder?: string; + defaultValue?: NDropdownOption; onSelect: (selected: NDropdownOption) => void; className?: string; // 支持传入自定义样式 } -const NDropdown: React.FC = ({ options, placeholder = 'Select an option', onSelect, className }) => { +const NDropdown: React.FC = ({ + options, + defaultValue = { + value: 'select', + label: 'Select an option', + }, + onSelect, + className, +}) => { const [isOpen, setIsOpen] = useState(false); - const [selectedOption, setSelectedOption] = useState(null); + const [selectedOption, setSelectedOption] = useState(defaultValue); const dropdownRef = useRef(null); const handleOptionClick = (option: NDropdownOption) => { @@ -42,7 +50,7 @@ const NDropdown: React.FC = ({ options, placeholder = 'Select an onClick={() => setIsOpen(!isOpen)} className="bg-white flex w-full justify-center px-4 py-2 text-left shadow-sm" > - {selectedOption?.label || placeholder} + {selectedOption?.label}