fix: broken properties selector

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-11-07 15:30:57 +01:00
parent ea029648a5
commit 0ddd1f6d06

View File

@@ -18,6 +18,14 @@ import {
type IValue = any; type IValue = any;
type IItem = Record<'value' | 'label', IValue>; type IItem = Record<'value' | 'label', IValue>;
const sanitize = (value: string) => {
return encodeURIComponent(value.replaceAll('"', '&quot;'));
};
const desanitize = (value: string) => {
return decodeURIComponent(value).replaceAll('&quot;', '"');
};
interface ComboboxAdvancedProps { interface ComboboxAdvancedProps {
value: IValue[]; value: IValue[];
onChange: (value: IValue[]) => void; onChange: (value: IValue[]) => void;
@@ -51,7 +59,7 @@ export function ComboboxAdvanced({
); );
const renderItem = (item: IItem) => { const renderItem = (item: IItem) => {
const checked = !!value.find((s) => s === item.value); const checked = !!value.find((s) => s === desanitize(item.value));
return ( return (
<CommandItem <CommandItem
onMouseDown={(e) => { onMouseDown={(e) => {
@@ -61,15 +69,16 @@ export function ComboboxAdvanced({
onSelect={() => { onSelect={() => {
setInputValue(''); setInputValue('');
onChange( onChange(
value.includes(item.value) value.includes(desanitize(item.value))
? value.filter((s) => s !== item.value) ? value.filter((s) => s !== desanitize(item.value))
: [...value, item.value], : [...value, desanitize(item.value)],
); );
}} }}
className={'flex cursor-pointer items-center gap-2'} className={'flex cursor-pointer items-center gap-2'}
value={item.value}
> >
<DumpCheckbox checked={checked} /> <DumpCheckbox checked={checked} />
{item?.label ?? item?.value} {desanitize(item?.label ?? item?.value)}
</CommandItem> </CommandItem>
); );
}; };
@@ -133,7 +142,11 @@ export function ComboboxAdvanced({
/> />
<VirtualList <VirtualList
height={Math.min(items.length * 32, 300)} height={Math.min(items.length * 32, 300)}
data={data} data={data.map((item) => ({
...item,
label: sanitize(item.label),
value: sanitize(item.value),
}))}
itemHeight={32} itemHeight={32}
itemKey="value" itemKey="value"
> >