Skip to content

Commit

Permalink
remove placeholder_no_results and change order of parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
fhiroki committed Jun 28, 2023
1 parent 8d120db commit 94cf4b1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const getProps = (elementProps: Partial<MultiSelectProto> = {}): Props => ({
default: [0],
options: ["a", "b", "c"],
placeholder: "Please select",
placeholderNoResults: "No results found",
...elementProps,
}),
width: 0,
Expand Down Expand Up @@ -301,7 +300,7 @@ describe("Multiselect widget", () => {

expect(wrapper.find(UISelect).props()).toHaveProperty(
"noResultsMsg",
"No results found"
"No results"
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Multiselect extends React.PureComponent<Props, State> {

private getNoResultsMsg(): string {
if (this.props.element.maxSelections === 0) {
return this.props.element.placeholderNoResults
return "No results"
}
const option =
this.props.element.maxSelections !== 1 ? "options" : "option"
Expand Down
24 changes: 9 additions & 15 deletions lib/streamlit/elements/multiselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,10 @@ def multiselect(
args: Optional[WidgetArgs] = None,
kwargs: Optional[WidgetKwargs] = None,
*, # keyword-only arguments:
disabled: bool = False,
label_visibility: LabelVisibility = "visible",
max_selections: Optional[int] = None,
placeholder: str = "Choose an option",
placeholder_no_results: str = "No results",
disabled: bool = False,
label_visibility: LabelVisibility = "visible",
) -> List[T]:
r"""Display a multiselect widget.
The multiselect widget starts as empty.
Expand Down Expand Up @@ -215,6 +214,11 @@ def multiselect(
An optional tuple of args to pass to the callback.
kwargs : dict
An optional dict of kwargs to pass to the callback.
max_selections : int
The max selections that can be selected at a time.
This argument can only be supplied by keyword.
placeholder : str
An optional string to display when option is not selected.
disabled : bool
An optional boolean, which disables the multiselect widget if set
to True. The default is False. This argument can only be supplied
Expand All @@ -224,13 +228,6 @@ def multiselect(
is still empty space for it above the widget (equivalent to label="").
If "collapsed", both the label and the space are removed. Default is
"visible". This argument can only be supplied by keyword.
max_selections : int
The max selections that can be selected at a time.
This argument can only be supplied by keyword.
placeholder : str
An optional string to display when no option is selected.
placeholder_no_results : str
An optional string to display when there are no results for the search.
Returns
-------
Expand Down Expand Up @@ -269,7 +266,6 @@ def multiselect(
ctx=ctx,
max_selections=max_selections,
placeholder=placeholder,
placeholder_no_results=placeholder_no_results,
)

def _multiselect(
Expand All @@ -284,12 +280,11 @@ def _multiselect(
args: Optional[WidgetArgs] = None,
kwargs: Optional[WidgetKwargs] = None,
*, # keyword-only arguments:
max_selections: Optional[int] = None,
placeholder: str = "Choose an option",
disabled: bool = False,
label_visibility: LabelVisibility = "visible",
ctx: Optional[ScriptRunContext] = None,
max_selections: Optional[int] = None,
placeholder: str = "Choose an option",
placeholder_no_results: str = "No results",
) -> List[T]:
key = to_key(key)
check_callback_rules(self.dg, on_change)
Expand All @@ -307,7 +302,6 @@ def _multiselect(
multiselect_proto.form_id = current_form_id(self.dg)
multiselect_proto.max_selections = max_selections or 0
multiselect_proto.placeholder = placeholder
multiselect_proto.placeholder_no_results = placeholder_no_results
if help is not None:
multiselect_proto.help = dedent(help)

Expand Down
9 changes: 2 additions & 7 deletions lib/tests/streamlit/elements/multiselect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def test_defaults(self, defaults, expected):
self.assertListEqual(c.default[:], expected)
self.assertEqual(c.options, ["Coffee", "Tea", "Water"])
self.assertEqual(c.placeholder, "Choose an option")
self.assertEqual(c.placeholder_no_results, "No results")

@parameterized.expand(
[
Expand Down Expand Up @@ -369,14 +368,10 @@ def test_get_over_max_options_message(
)

def test_placeholder(self):
"""Test that it can be called with placeholder and placeholder_no_results params."""
"""Test that it can be called with placeholder params."""
st.multiselect(
"the label",
["Coffee", "Tea", "Water"],
placeholder="Select your beverage",
placeholder_no_results="There is no drink you want.",
"the label", ["Coffee", "Tea", "Water"], placeholder="Select your beverage"
)

c = self.get_delta_from_queue().new_element.multiselect
self.assertEqual(c.placeholder, "Select your beverage")
self.assertEqual(c.placeholder_no_results, "There is no drink you want.")
9 changes: 4 additions & 5 deletions proto/streamlit/proto/MultiSelect.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ message MultiSelect {
string form_id = 6;
repeated int32 value = 7;
bool set_value = 8;
bool disabled = 9;
LabelVisibilityMessage label_visibility = 10;
int32 max_selections = 11;
string placeholder = 12;
string placeholder_no_results = 13;
int32 max_selections = 9;
string placeholder = 10;
bool disabled = 11;
LabelVisibilityMessage label_visibility = 12;
}

0 comments on commit 94cf4b1

Please sign in to comment.