M: Improve error handling
This commit is contained in:
parent
921310a349
commit
17f30f0b20
|
|
@ -1,7 +1,5 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import assert from 'assert';
|
|
||||||
|
|
||||||
import { useRef, useState } from 'react';
|
import { useRef, useState } from 'react';
|
||||||
import { ChevronDownIcon } from 'lucide-react';
|
import { ChevronDownIcon } from 'lucide-react';
|
||||||
|
|
||||||
|
|
@ -71,9 +69,10 @@ export function ComboMulti<Option>({
|
||||||
} else {
|
} else {
|
||||||
if ('onAdd' in restProps && typeof restProps.onAdd === 'function') {
|
if ('onAdd' in restProps && typeof restProps.onAdd === 'function') {
|
||||||
restProps.onAdd(newValue);
|
restProps.onAdd(newValue);
|
||||||
} else {
|
} else if ('onChange' in restProps && typeof restProps.onChange === 'function') {
|
||||||
assert('onChange' in restProps);
|
|
||||||
restProps.onChange([...value, newValue]);
|
restProps.onChange([...value, newValue]);
|
||||||
|
} else {
|
||||||
|
throw new Error('onChange is not defined');
|
||||||
}
|
}
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}
|
}
|
||||||
|
|
@ -82,9 +81,10 @@ export function ComboMulti<Option>({
|
||||||
function handleRemoveValue(delValue: Option) {
|
function handleRemoveValue(delValue: Option) {
|
||||||
if ('onRemove' in restProps && typeof restProps.onRemove === 'function') {
|
if ('onRemove' in restProps && typeof restProps.onRemove === 'function') {
|
||||||
restProps.onRemove(delValue);
|
restProps.onRemove(delValue);
|
||||||
} else {
|
} else if ('onChange' in restProps && typeof restProps.onChange === 'function') {
|
||||||
assert('onChange' in restProps);
|
|
||||||
restProps.onChange(value.filter(v => v !== delValue));
|
restProps.onChange(value.filter(v => v !== delValue));
|
||||||
|
} else {
|
||||||
|
throw new Error('onChange is not defined');
|
||||||
}
|
}
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}
|
}
|
||||||
|
|
@ -93,9 +93,10 @@ export function ComboMulti<Option>({
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
if ('onClear' in restProps && typeof restProps.onClear === 'function') {
|
if ('onClear' in restProps && typeof restProps.onClear === 'function') {
|
||||||
restProps.onClear();
|
restProps.onClear();
|
||||||
} else {
|
} else if ('onChange' in restProps && typeof restProps.onChange === 'function') {
|
||||||
assert('onChange' in restProps);
|
|
||||||
restProps.onChange([]);
|
restProps.onChange([]);
|
||||||
|
} else {
|
||||||
|
throw new Error('onChange is not defined');
|
||||||
}
|
}
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user