@@ -145,7 +145,7 @@ selectBackend = make component
145145 { isOpen = true
146146 , isActive = true
147147 , focusedIndex = s.focusedIndex <|>
148- if (getOptions s # maybe 0 optionsLength) > 0 then
148+ if (getOptions props s # maybe 0 optionsLength) > 0 then
149149 Just 0
150150 else
151151 Nothing
@@ -169,13 +169,13 @@ selectBackend = make component
169169 }
170170
171171 Blur -> do
172- when state.isActive do
172+ when ( state.isActive) do
173173 self.setState _ { isActive = false }
174174
175175 FocusIndexUp -> do
176176 self.setState \s -> s
177177 { focusedIndex = do
178- options <- getOptions s
178+ options <- getOptions props s
179179 let iMax = optionsLength options - 1
180180 pure
181181 case fromMaybe 0 s.focusedIndex of
@@ -186,7 +186,7 @@ selectBackend = make component
186186 FocusIndexDown -> do
187187 self.setState \s -> s
188188 { focusedIndex = do
189- options <- getOptions s
189+ options <- getOptions props s
190190 let iMax = optionsLength options - 1
191191 pure
192192 case fromMaybe (-1 ) s.focusedIndex of
@@ -237,7 +237,7 @@ selectBackend = make component
237237 send self $ LoadOptions searchTerm
238238
239239 LoadOptions searchTerm -> do
240- when (isNothing $ getOptions { searchTerm, optionCache: state.optionCache }) do
240+ when (isNothing $ getOptions props { searchTerm, optionCache: state.optionCache }) do
241241 let
242242 tidyUp =
243243 map
@@ -272,7 +272,7 @@ selectBackend = make component
272272 , isOpen: self.state.isOpen
273273 , isActive: self.state.isActive
274274 , keydownEventHandler
275- , options: map _.external $ fromMaybe Loading $ getOptions self.state
275+ , options: map _.external $ fromMaybe Loading $ getOptions self.props self. state
276276 , removeAllSelectedOptions: send self RemoveAllSelectedOptions
277277 , removeSelectedOption: send self <<< RemoveSelectedOption
278278 , searchTerm: self.state.searchTerm
@@ -366,7 +366,7 @@ selectBackend = make component
366366 E .preventDefault e
367367 E .stopPropagation e
368368 traverse_ (send self <<< AddSelectedOption ) do
369- options <- getOptions state
369+ options <- getOptions props state
370370 focusedIndex <- state.focusedIndex
371371 option <- getOption focusedIndex options
372372 pure option.external
@@ -392,13 +392,24 @@ optionsLength = case _ of
392392 _ -> 0
393393
394394getOptions ::
395- forall a r .
395+ forall a p r .
396+ { value :: Array a
397+ , toSelectOption :: a -> SelectOption
398+ | p
399+ } ->
396400 { searchTerm :: String
397- , optionCache :: Map.Map String (SelectOptions a )
401+ , optionCache :: Map.Map String (SelectOptions ( SelectOptionInternal a ) )
398402 | r
399403 } ->
400- Maybe (SelectOptions a )
401- getOptions { searchTerm, optionCache } = Map .lookup searchTerm optionCache
404+ Maybe (SelectOptions (SelectOptionInternal a ))
405+ getOptions { toSelectOption, value } { searchTerm, optionCache } =
406+ Map .lookup searchTerm optionCache <#> case _ of
407+ Ready os -> Ready $ isNotSelected os
408+ so -> so
409+ where
410+ selected = map (_.value <<< toSelectOption) value
411+
412+ isNotSelected = Array .filter \v -> Array .notElem v.value selected
402413
403414getOption :: forall a . Int -> SelectOptions a -> Maybe a
404415getOption i = case _ of
0 commit comments