Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/components/tag-input/useTagList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Fragment, useState } from 'react';
import { isFunction } from 'lodash-es';
import log from '@tdesign/common-js/log/index';

import useConfig from '../hooks/useConfig';
import useControlled from '../hooks/useControlled';
Expand All @@ -23,7 +24,20 @@ export default function useTagList(props: TagInputProps) {
const readOnly = props.readOnly || props.readonly;

// handle controlled property and uncontrolled property
const [tagValue, setTagValue] = useControlled(props, 'value', props.onChange);
const [innerTagValue, setTagValue] = useControlled(props, 'value', props.onChange);
let tagValue: TagInputValue;
if (Array.isArray(innerTagValue)) {
tagValue = innerTagValue;
} else {
if (innerTagValue !== undefined && innerTagValue !== null) {
log.warnOnce(
'TagInput',
`\`value\` is expected to be an array, but got ${typeof innerTagValue}. It will be treated as an empty array.`,
);
}
tagValue = [];
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [oldInputValue, setOldInputValue] = useState<InputValue>();

Expand Down
Loading