From b4be6daea6a5fac4e16a7ce2436638ae903ba942 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 25 Jan 2024 08:46:59 +0000 Subject: [PATCH] Quick fix for all usages of compare function in select. --- packages/bbui/src/Form/Core/Select.svelte | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/bbui/src/Form/Core/Select.svelte b/packages/bbui/src/Form/Core/Select.svelte index aaca8b640d..3ee37be915 100644 --- a/packages/bbui/src/Form/Core/Select.svelte +++ b/packages/bbui/src/Form/Core/Select.svelte @@ -35,15 +35,20 @@ $: 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) => { - const opt = getOptionValue(option, idx) - return typeof compare === "function" ? compare(opt, value) : opt === value - }) + const index = options.findIndex((option, idx) => + compareOptionAndValue(getOptionValue(option, idx), value) + ) return index !== -1 ? getAttribute(options[index], index) : null } @@ -96,7 +101,7 @@ {customPopoverMaxHeight} isPlaceholder={value == null || value === ""} placeholderOption={placeholder === false ? null : placeholder} - isOptionSelected={option => compare(option, value)} + isOptionSelected={option => compareOptionAndValue(option, value)} onSelectOption={selectOption} {loading} />