This commit is contained in:
ditiqi 2025-02-23 18:59:32 +08:00
parent 6ace9b06a4
commit 1d6eb48bb6
1 changed files with 13 additions and 6 deletions

View File

@ -1,22 +1,29 @@
import React, { useState } from "react"; import React, { useEffect, useState } from "react";
import { Input, Button } from "antd"; import { Input, Button } from "antd";
import { DeleteOutlined } from "@ant-design/icons"; import { DeleteOutlined } from "@ant-design/icons";
interface InputListProps { interface InputListProps {
initialValue?: string[]; value?: string[];
onChange?: (value: string[]) => void; onChange?: (value: string[]) => void;
placeholder?: string; placeholder?: string;
} }
const InputList: React.FC<InputListProps> = ({ const InputList: React.FC<InputListProps> = ({
initialValue, value,
onChange, onChange,
placeholder = "请输入内容", placeholder = "请输入内容",
}) => { }) => {
// Internal state management with fallback to initial value or empty array // Internal state management with fallback to initial value or empty array
const [inputValues, setInputValues] = useState<string[]>( const [inputValues, setInputValues] = useState<string[]>([""]);
initialValue && initialValue.length > 0 ? initialValue : [""]
); // Update inputValues when value changes
useEffect(() => {
if (value && value.length > 0) {
setInputValues(value);
} else {
setInputValues([""]);
}
}, [value]);
// Handle individual input value change // Handle individual input value change
const handleInputChange = (index: number, newValue: string) => { const handleInputChange = (index: number, newValue: string) => {