fix: fix multi combobox value is not in list candidate set issue

fix: fix multi combobox value is not in list candidate set issue
Co-Authored-By: Minghan Zhang <112773885+zmh-program@users.noreply.github.com>
This commit is contained in:
Deng Junhai 2024-03-31 00:29:32 +08:00
parent 03512d0fc8
commit 079c55d752
4 changed files with 13 additions and 11 deletions

View File

@ -44,9 +44,7 @@ function Announcement() {
</DialogTrigger>
<DialogContent className={`announcement-dialog flex-dialog`}>
<DialogHeader notTextCentered>
<DialogTitle
className={"flex flex-row items-center select-none"}
>
<DialogTitle className={"flex flex-row items-center select-none"}>
<Bell className="inline-block w-4 h-4 mr-2" />
<p className={`translate-y-[-1px]`}>{t("announcement")}</p>
</DialogTitle>
@ -55,7 +53,9 @@ function Announcement() {
</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogCancel onClick={() => setOpen(false)}>{t("close")}</DialogCancel>
<DialogCancel onClick={() => setOpen(false)}>
{t("close")}
</DialogCancel>
<DialogAction onClick={() => setOpen(false)}>
<Check className="w-4 h-4 mr-1" />
{t("i-know")}

View File

@ -39,8 +39,8 @@ export function Combobox({
const { t } = useTranslation();
const [open, setOpen] = React.useState(defaultOpen ?? false);
const valueList = React.useMemo((): string[] => {
// list set
const set = new Set(list);
// list set (if some element in current value is not in list, it will be added)
const set = new Set([...list, value]);
return [...set];
}, [list]);

View File

@ -64,7 +64,7 @@ const DialogHeader = ({
className,
notTextCentered,
...props
}: React.HTMLAttributes<HTMLDivElement> & {notTextCentered?: boolean}) => (
}: React.HTMLAttributes<HTMLDivElement> & { notTextCentered?: boolean }) => (
<div
className={cn(
"flex flex-col space-y-1.5 sm:text-left",
@ -121,10 +121,11 @@ const DialogCancel = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, ...props }, ref) => (
<Button
ref={ref}
className={className}
variant={variant ?? "outline"}
{...props}
/>
)
),
);
DialogCancel.displayName = "DialogCancel";
@ -133,10 +134,11 @@ const DialogAction = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, ...props }, ref) => (
<Button
ref={ref}
className={cn("mb-2 md:mb-0", className)}
variant={variant ?? "default"}
{...props}
/>
)
),
);
DialogAction.displayName = "DialogAction";

View File

@ -49,8 +49,8 @@ export function MultiCombobox({
const { t } = useTranslation();
const [open, setOpen] = React.useState(defaultOpen ?? false);
const valueList = React.useMemo((): string[] => {
// list set
const set = new Set(list);
// list set (if some element in current value is not in list, it will be added)
const set = new Set([...list, ...value]);
return [...set];
}, [list]);