Skip to content

Commit

Permalink
Fix dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed May 9, 2024
1 parent ba5e2ab commit b7f550f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isNil, pluck, without, pick} from 'ramda';
import {isNil, pluck, without, pick, isEmpty} from 'ramda';
import React, {useState, useCallback, useEffect, useMemo, useRef} from 'react';
import ReactDropdown from 'react-virtualized-select';
import createFilterOptions from 'react-select-fast-filter-options';
Expand Down Expand Up @@ -125,7 +125,8 @@ const Dropdown = props => {
!search_value &&
!isNil(sanitizedOptions) &&
optionsCheck !== sanitizedOptions &&
!isNil(value)
!isNil(value) &&
!isEmpty(value)
) {
const values = sanitizedOptions.map(option => option.value);
if (multi && Array.isArray(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import pytest

from dash import Dash, html, dcc, Output, Input, State
from dash import Dash, html, dcc, Output, Input, State, Patch
from dash.exceptions import PreventUpdate

from selenium.webdriver.common.keys import Keys

sample_dropdown_options = [
{"label": "New York City", "value": "NYC"},
Expand Down Expand Up @@ -147,3 +148,44 @@ def print_value(n_clicks, options, value):
btn.click()
dash_dcc.wait_for_text_to_equal("#value-output", '["NYC"]')
dash_dcc.wait_for_text_to_equal("#options-output", '["MTL", "NYC"]')


def test_ddro004_empty_string_not_updated(dash_dcc):
# The value should stay as empty string and not null.
app = Dash()
app.layout = html.Div(
[
dcc.Dropdown(["a", "b", "c"], value="", id="drop"),
html.Div(id="output"),
dcc.Store(data={"count": 0}, id="count"),
html.Div(id="count-output"),
]
)

@app.callback(
Output("output", "children"),
Output("count", "data"),
Input("drop", "value"),
)
def on_value(value):
count = Patch()
count.count += 1
if value is None:
return "Value is none", count
return f"Value={value}", count

app.clientside_callback(
"data => data.count", Output("count-output", "children"), Input("count", "data")
)

dash_dcc.start_server(app)
dash_dcc.wait_for_text_to_equal("#output", "Value=")

dash_dcc.wait_for_text_to_equal("#count-output", "1")

select_input = dash_dcc.find_element("#drop input")
select_input.send_keys("a")
select_input.send_keys(Keys.ENTER)

dash_dcc.wait_for_text_to_equal("#output", "Value=a")
dash_dcc.wait_for_text_to_equal("#count-output", "2")

0 comments on commit b7f550f

Please sign in to comment.