Skip to content

Commit 64694e8

Browse files
committed
Revert defaulting to adding clear_button by default
1 parent 6fd3bbb commit 64694e8

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

shiny/ui/_input_select.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"input_selectize",
1111
)
1212
import json
13-
from typing import Mapping, Optional, Union, cast
13+
from typing import Literal, Mapping, Optional, Union, cast
1414

1515
from htmltools import Tag, TagChild, TagList, css, div, tags
1616

@@ -58,7 +58,7 @@ def input_selectize(
5858
selected: Optional[str | list[str]] = None,
5959
multiple: bool = False,
6060
width: Optional[str] = None,
61-
remove_button: bool = True,
61+
remove_button: Optional[Literal[True, False, "both"]] = None,
6262
options: Optional[dict[str, Jsonifiable | JSEval]] = None,
6363
) -> Tag:
6464
"""
@@ -84,10 +84,16 @@ def input_selectize(
8484
width
8585
The CSS width, e.g. '400px', or '100%'
8686
remove_button
87-
Whether to add a remove button. When `True` (the default), both the
88-
'clear_button' and 'remove_button' plugins are included. If you want just one
89-
plugin, set this to `False` and specify the desired plugin in the `options`
90-
argument (i.e., `options = {"plugins": ["remove_button"]}`).
87+
Whether to add a remove button. The following values are supported:
88+
89+
- `None` (the default): The 'remove_button' selection plugin is included when
90+
`multiple=True`.
91+
- `True`: Same as `None` in the `multiple=True` case, but when `multiple=False`,
92+
the 'clear_button' plugin is included.
93+
- `False`: No plugins are included.
94+
- `"both"`: Both 'remove_button' and 'clear_button' plugins are included. This
95+
is useful for being able to clear each and all selected items when
96+
`multiple=True`.
9197
options
9298
A dictionary of options. See the documentation of selectize.js for possible options.
9399
If you want to pass a JavaScript function, wrap the string in `ui.JS`.
@@ -245,7 +251,7 @@ def _input_select_impl(
245251
selectize: bool = False,
246252
width: Optional[str] = None,
247253
size: Optional[str] = None,
248-
remove_button: bool = True,
254+
remove_button: Literal[True, False, "both", None] = None,
249255
options: Optional[dict[str, Jsonifiable | JSEval]] = None,
250256
) -> Tag:
251257
if options is not None and selectize is False:
@@ -262,15 +268,18 @@ def _input_select_impl(
262268
if options is None:
263269
options = {}
264270

265-
# Although 'remove_button' is primarily for multiple=True and 'clear_button' is for
266-
# multiple=False, we include both in either case since:
267-
# 1. When multiple=True, 'clear_button' can be used to clear _all_ selected items.
268-
# 2. When multiple=False, 'remove_button' is effectively a no-op.
269-
# 3. By including both, we can simplify the client-side logic needed to retain
270-
# these plugins across update_selectize(options=...) calls
271+
if remove_button is None:
272+
remove_button = multiple
273+
274+
# Translate remove_button into default selectize plugins
275+
# N.B. remove_button is primarily for multiple=True and clear_button is for
276+
# multiple=False, but both can also be useful in the multiple=True case (i.e., clear
277+
# _all_ selected items)
271278
default_plugins = None
272-
if remove_button or remove_button is None:
279+
if remove_button == "both":
273280
default_plugins = json.dumps(["remove_button", "clear_button"])
281+
elif remove_button:
282+
default_plugins = json.dumps(["remove_button" if multiple else "clear_button"])
274283

275284
choices_tags = _render_choices(choices_, selected)
276285

0 commit comments

Comments
 (0)