From 8cb5e2b5695cf575d63a6a241802f6f28b1f8079 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Fri, 26 Jan 2024 10:00:35 +0000 Subject: [PATCH] Revert "Quick fix for all usages of compare function in select." This reverts commit b4be6daea6a5fac4e16a7ce2436638ae903ba942. --- packages/bbui/src/Form/Core/Select.svelte | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/bbui/src/Form/Core/Select.svelte b/packages/bbui/src/Form/Core/Select.svelte index 9215500c0e..45693c2167 100644 --- a/packages/bbui/src/Form/Core/Select.svelte +++ b/packages/bbui/src/Form/Core/Select.svelte @@ -33,20 +33,15 @@ $: fieldIcon = getFieldAttribute(getOptionIcon, 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) => { // Wait for options to load if there is a value but no options if (!options?.length) { return "" } - const index = options.findIndex((option, idx) => - compare(getOptionValue(option, idx), value) - ) + const index = options.findIndex((option, idx) => { + const opt = getOptionValue(option, idx) + return typeof compare === "function" ? compare(opt, value) : opt === value + }) return index !== -1 ? getAttribute(options[index], index) : null } @@ -97,7 +92,7 @@ {tag} isPlaceholder={value == null || value === ""} placeholderOption={placeholder === false ? null : placeholder} - isOptionSelected={option => compareOptionAndValue(option, value)} + isOptionSelected={option => compare(option, value)} onSelectOption={selectOption} {loading} />