1
0
Fork 0
mirror of synced 2024-07-19 13:15:49 +12:00

Revert "Quick fix for all usages of compare function in select."

This reverts commit b4be6daea6.
This commit is contained in:
Mel O'Hagan 2024-01-26 10:00:35 +00:00
parent 0c09d5878b
commit 8cb5e2b569

View file

@ -33,20 +33,15 @@
$: fieldIcon = getFieldAttribute(getOptionIcon, value, options) $: fieldIcon = getFieldAttribute(getOptionIcon, value, options)
$: fieldColour = getFieldAttribute(getOptionColour, value, options) $: fieldColour = getFieldAttribute(getOptionColour, value, options)
function compareOptionAndValue(option, value) {
return typeof compare === "function"
? compare(option, value)
: option === value
}
const getFieldAttribute = (getAttribute, value, options) => { const getFieldAttribute = (getAttribute, value, options) => {
// Wait for options to load if there is a value but no options // Wait for options to load if there is a value but no options
if (!options?.length) { if (!options?.length) {
return "" return ""
} }
const index = options.findIndex((option, idx) => const index = options.findIndex((option, idx) => {
compare(getOptionValue(option, idx), value) const opt = getOptionValue(option, idx)
) return typeof compare === "function" ? compare(opt, value) : opt === value
})
return index !== -1 ? getAttribute(options[index], index) : null return index !== -1 ? getAttribute(options[index], index) : null
} }
@ -97,7 +92,7 @@
{tag} {tag}
isPlaceholder={value == null || value === ""} isPlaceholder={value == null || value === ""}
placeholderOption={placeholder === false ? null : placeholder} placeholderOption={placeholder === false ? null : placeholder}
isOptionSelected={option => compareOptionAndValue(option, value)} isOptionSelected={option => compare(option, value)}
onSelectOption={selectOption} onSelectOption={selectOption}
{loading} {loading}
/> />