no log: Add value property to the chip component

pull/1638/head
LASER-Yi 3 years ago
parent ca8f3f9fd2
commit 0af9647a6a
No known key found for this signature in database
GPG Key ID: BB28903D50A1D408

@ -176,11 +176,11 @@ export const Chips: FunctionComponent<ChipsProp> = (props) => {
const update = useSingleUpdate();
const defaultValue = useLatest<string[]>(settingKey, isArray, override);
const value = useLatest<string[]>(settingKey, isArray, override);
return (
<CChips
defaultValue={defaultValue ?? undefined}
value={value ?? undefined}
onChange={(v) => {
update(v, settingKey);
}}

@ -3,6 +3,7 @@ import React, {
FunctionComponent,
KeyboardEvent,
useCallback,
useEffect,
useMemo,
useRef,
useState,
@ -14,15 +15,31 @@ const SplitKeys = ["Tab", "Enter", " ", ",", ";"];
export interface ChipsProps {
disabled?: boolean;
defaultValue?: readonly string[];
value?: readonly string[];
onChange?: (v: string[]) => void;
}
export const Chips: FunctionComponent<ChipsProps> = ({
defaultValue,
value,
disabled,
onChange,
}) => {
const [chips, setChips] = useState(defaultValue ?? []);
const [chips, setChips] = useState(() => {
if (value) {
return value;
}
if (defaultValue) {
return defaultValue;
}
return [];
});
useEffect(() => {
if (value) {
setChips(value);
}
}, [value]);
const input = useRef<HTMLInputElement>(null);

Loading…
Cancel
Save