Skip to content

Fix Dropdown Option Removal Regression #2816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const Dropdown = props => {
const {
id,
clearable,
searchable,
multi,
options,
setProps,
Expand All @@ -48,6 +47,7 @@ const Dropdown = props => {
value,
} = props;
const [optionsCheck, setOptionsCheck] = useState(null);
const [searchValue, setSearchValue] = useState(null);
const persistentOptions = useRef(null);

if (!persistentOptions || !isEqual(options, persistentOptions.current)) {
Expand Down Expand Up @@ -115,14 +115,14 @@ const Dropdown = props => {
[multi]
);

const onInputChange = useCallback(
search_value => setProps({search_value}),
[]
);
const onInputChange = useCallback(search_value => {
setProps({search_value});
setSearchValue(search_value);
}, []);

useEffect(() => {
if (
!searchable &&
!searchValue &&
!isNil(sanitizedOptions) &&
optionsCheck !== sanitizedOptions &&
!isNil(value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

import pytest

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

Expand All @@ -11,7 +13,8 @@
]


def test_ddro001_remove_option_single(dash_dcc):
@pytest.mark.parametrize("searchable", (True, False))
def test_ddro001_remove_option_single(dash_dcc, searchable):
dropdown_options = sample_dropdown_options

app = Dash(__name__)
Expand All @@ -22,7 +25,7 @@ def test_ddro001_remove_option_single(dash_dcc):
dcc.Dropdown(
options=dropdown_options,
value=value,
searchable=False,
searchable=searchable,
id="dropdown",
),
html.Button("Remove option", id="remove"),
Expand All @@ -49,7 +52,8 @@ def on_change(val):
dash_dcc.wait_for_text_to_equal("#value-output", "None")


def test_ddro002_remove_option_multi(dash_dcc):
@pytest.mark.parametrize("searchable", (True, False))
def test_ddro002_remove_option_multi(dash_dcc, searchable):
dropdown_options = sample_dropdown_options

app = Dash(__name__)
Expand All @@ -62,7 +66,7 @@ def test_ddro002_remove_option_multi(dash_dcc):
value=value,
multi=True,
id="dropdown",
searchable=False,
searchable=searchable,
),
html.Button("Remove option", id="remove"),
html.Div(id="value-output"),
Expand Down