mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-07 14:47:58 +08:00
feat(blocks-antd): Fix autocomplete bugs.
This commit is contained in:
parent
0f9b64bcb8
commit
71523cba43
@ -20,7 +20,6 @@ import { blockDefaultProps, renderHtml } from '@lowdefy/block-utils';
|
||||
import { type } from '@lowdefy/helpers';
|
||||
|
||||
import Label from '../Label/Label.js';
|
||||
import getUniqueValues from '../../getUniqueValues.js';
|
||||
|
||||
const Option = AutoComplete.Option;
|
||||
|
||||
@ -35,7 +34,6 @@ const AutoCompleteInput = ({
|
||||
validation,
|
||||
value,
|
||||
}) => {
|
||||
const uniqueValueOptions = getUniqueValues(properties.options || []);
|
||||
return (
|
||||
<Label
|
||||
blockId={blockId}
|
||||
@ -51,7 +49,7 @@ const AutoCompleteInput = ({
|
||||
autoFocus={properties.autoFocus}
|
||||
backfill={properties.backfill}
|
||||
bordered={properties.bordered}
|
||||
className={methods.makeCssClass(properties.inputStyle)}
|
||||
className={methods.makeCssClass([{ width: '100%' }, properties.inputStyle])}
|
||||
defaultOpen={properties.defaultOpen}
|
||||
disabled={properties.disabled || loading}
|
||||
placeholder={properties.placeholder || 'Type or select item'}
|
||||
@ -63,45 +61,24 @@ const AutoCompleteInput = ({
|
||||
.indexOf(input.toLowerCase()) >= 0
|
||||
}
|
||||
onChange={(newVal) => {
|
||||
let val = type.isPrimitive(uniqueValueOptions[newVal])
|
||||
? uniqueValueOptions[newVal]
|
||||
: uniqueValueOptions[newVal].value;
|
||||
if (type.isNone(val)) {
|
||||
val = newVal;
|
||||
}
|
||||
methods.setValue(val);
|
||||
methods.setValue(newVal);
|
||||
methods.triggerEvent({ name: 'onChange' });
|
||||
}}
|
||||
onSearch={(newVal) => {
|
||||
methods.triggerEvent({ name: 'onSearch', event: { value: newVal } });
|
||||
}}
|
||||
value={type.isNone(value) ? undefined : value}
|
||||
value={type.isNone(value) ? undefined : `${value}`}
|
||||
>
|
||||
{(properties.options || []).map((opt, i) =>
|
||||
type.isPrimitive(opt) ? (
|
||||
<Option
|
||||
className={methods.makeCssClass(properties.optionsStyle)}
|
||||
id={`${blockId}_${i}`}
|
||||
key={i}
|
||||
value={`${i}`}
|
||||
>
|
||||
{renderHtml({ html: `${opt}`, methods })}
|
||||
</Option>
|
||||
) : (
|
||||
<Option
|
||||
className={methods.makeCssClass([properties.optionsStyle, opt.style])}
|
||||
disabled={opt.disabled}
|
||||
filterstring={opt.filterString}
|
||||
id={`${blockId}_${i}`}
|
||||
key={i}
|
||||
value={`${i}`}
|
||||
>
|
||||
{type.isNone(opt.label)
|
||||
? renderHtml({ html: `${opt.value}`, methods })
|
||||
: renderHtml({ html: opt.label, methods })}
|
||||
</Option>
|
||||
)
|
||||
)}
|
||||
{(properties.options || []).map((opt, i) => (
|
||||
<Option
|
||||
className={methods.makeCssClass(properties.optionsStyle)}
|
||||
id={`${blockId}_${i}`}
|
||||
key={i}
|
||||
value={`${opt}`}
|
||||
>
|
||||
{renderHtml({ html: `${opt}`, methods })}
|
||||
</Option>
|
||||
))}
|
||||
</AutoComplete>
|
||||
),
|
||||
}}
|
||||
|
Loading…
Reference in New Issue
Block a user