mirror of
https://github.com/morpheus65535/bazarr.git
synced 2025-01-01 04:22:07 +08:00
no log: Add value property to the chip component
This commit is contained in:
parent
ca8f3f9fd2
commit
0af9647a6a
2 changed files with 20 additions and 3 deletions
|
@ -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…
Reference in a new issue